@@ -9,62 +9,65 @@ import (
9
9
"regexp"
10
10
"strings"
11
11
"time"
12
+ "encoding/json"
12
13
)
13
14
14
15
type Config struct {
15
- Ctx context.Context
16
- ReqURI string
17
- DisableKeepAlive bool
18
- ReqTarget int64
19
- Conns uint
20
- Duration time.Duration
21
- MTLSKey string
22
- MTLSCert string
23
- SkipVerify bool
24
- ReadTimeout time.Duration
25
- WriteTimeout time.Duration
26
- Method string
27
- Verbose bool
28
- VerboseTicker time.Duration
29
- JwtKID string
30
- JwtKey string
31
- JwtSub string
32
- JwtIss string
33
- JwtAud string
34
- JwtHeader string
35
- SendJWT bool
36
- Headers []string
37
- Body string
38
- BodyFile string
39
- Client string
16
+ Ctx context.Context
17
+ ReqURI string
18
+ DisableKeepAlive bool
19
+ ReqTarget int64
20
+ Conns uint
21
+ Duration time.Duration
22
+ MTLSKey string
23
+ MTLSCert string
24
+ SkipVerify bool
25
+ ReadTimeout time.Duration
26
+ WriteTimeout time.Duration
27
+ Method string
28
+ Verbose bool
29
+ VerboseTicker time.Duration
30
+ JwtKID string
31
+ JwtKey string
32
+ JwtSub string
33
+ JwtCustomClaimsJSON string
34
+ JwtIss string
35
+ JwtAud string
36
+ JwtHeader string
37
+ SendJWT bool
38
+ Headers []string
39
+ Body string
40
+ BodyFile string
41
+ Client string
40
42
}
41
43
42
- func NewConfig (ctx context.Context , reqURI , mTLScert , mTLSKey string , disableKeepAlive bool , reqs int64 , conns uint , totalTime time.Duration , skipVerify bool , readTimeout , writeTimeout time.Duration , method string , verbose bool , ticker time.Duration , jwtKID , jwtKey , jwtSub , jwtIss , jwtAud , jwtHeader string , headers []string , body , bodyFile string , client string ) * Config {
44
+ func NewConfig (ctx context.Context , reqURI , mTLScert , mTLSKey string , disableKeepAlive bool , reqs int64 , conns uint , totalTime time.Duration , skipVerify bool , readTimeout , writeTimeout time.Duration , method string , verbose bool , ticker time.Duration , jwtKID , jwtKey , jwtSub , jwtCustomClaimsJSON , jwtIss , jwtAud , jwtHeader string , headers []string , body , bodyFile string , client string ) * Config {
43
45
return & Config {
44
- Ctx : ctx ,
45
- ReqURI : reqURI ,
46
- MTLSKey : mTLSKey ,
47
- MTLSCert : mTLScert ,
48
- DisableKeepAlive : disableKeepAlive ,
49
- ReqTarget : reqs ,
50
- Conns : conns ,
51
- Duration : totalTime ,
52
- SkipVerify : skipVerify ,
53
- ReadTimeout : readTimeout ,
54
- WriteTimeout : writeTimeout ,
55
- Method : method ,
56
- Verbose : verbose ,
57
- VerboseTicker : ticker ,
58
- JwtKID : jwtKID ,
59
- JwtKey : jwtKey ,
60
- JwtSub : jwtSub ,
61
- JwtIss : jwtIss ,
62
- JwtAud : jwtAud ,
63
- JwtHeader : jwtHeader ,
64
- Headers : headers ,
65
- Body : body ,
66
- BodyFile : bodyFile ,
67
- Client : client ,
46
+ Ctx : ctx ,
47
+ ReqURI : reqURI ,
48
+ MTLSKey : mTLSKey ,
49
+ MTLSCert : mTLScert ,
50
+ DisableKeepAlive : disableKeepAlive ,
51
+ ReqTarget : reqs ,
52
+ Conns : conns ,
53
+ Duration : totalTime ,
54
+ SkipVerify : skipVerify ,
55
+ ReadTimeout : readTimeout ,
56
+ WriteTimeout : writeTimeout ,
57
+ Method : method ,
58
+ Verbose : verbose ,
59
+ VerboseTicker : ticker ,
60
+ JwtKID : jwtKID ,
61
+ JwtKey : jwtKey ,
62
+ JwtSub : jwtSub ,
63
+ JwtCustomClaimsJSON : jwtCustomClaimsJSON ,
64
+ JwtIss : jwtIss ,
65
+ JwtAud : jwtAud ,
66
+ JwtHeader : jwtHeader ,
67
+ Headers : headers ,
68
+ Body : body ,
69
+ BodyFile : bodyFile ,
70
+ Client : client ,
68
71
}
69
72
}
70
73
@@ -83,6 +86,22 @@ var allowedMethods = [4]string{
83
86
"DELETE" ,
84
87
}
85
88
89
+ // Converts jwtCustomClaimsJSON from string to map[string]interface{}
90
+ func JwtCustomClaimsJSONStringToMap (jwtCustomClaimsJSON string ) (map [string ]interface {}, error ) {
91
+ if jwtCustomClaimsJSON == "" {
92
+ return nil , nil
93
+ }
94
+
95
+ jwtCustomClaimsMap := map [string ]interface {}{}
96
+
97
+ err := json .Unmarshal ([]byte (jwtCustomClaimsJSON ), & jwtCustomClaimsMap )
98
+ if err != nil {
99
+ return nil , err
100
+ }
101
+
102
+ return jwtCustomClaimsMap , nil
103
+ }
104
+
86
105
func (c * Config ) Validate () error {
87
106
if _ , err := url .ParseRequestURI (c .ReqURI ); err != nil {
88
107
return fmt .Errorf ("config: invalid request uri, got error %v" , err )
@@ -180,6 +199,14 @@ func (c *Config) Validate() error {
180
199
if c .ReqTarget == 0 && c .Duration == 0 {
181
200
return errors .New ("config: ReqTarget 0 and Duration 0" )
182
201
}
202
+
203
+ if c .JwtCustomClaimsJSON != "" {
204
+ _ , err := JwtCustomClaimsJSONStringToMap (c .JwtCustomClaimsJSON )
205
+ if err != nil {
206
+ return fmt .Errorf ("config: failed to parse custom json in --jwt-claims, got error; %v" , err )
207
+ }
208
+ }
209
+
183
210
return nil
184
211
}
185
212
0 commit comments