verbosity
parent
850052c4a5
commit
f89dd39356
18
main.go
18
main.go
|
|
@ -24,7 +24,7 @@ type LagReader struct {
|
|||
|
||||
func main() {
|
||||
var bodyRepeat int
|
||||
var path, host, method, body, headers, brandID, issuer, basicAuth string
|
||||
var path, host, method, body, headers, brandID, issuer, basicAuth, claims string
|
||||
var ca, cert, key, secret string
|
||||
var needJWT, verbose, jsonPP bool
|
||||
var timeout, lag time.Duration
|
||||
|
|
@ -46,6 +46,7 @@ func main() {
|
|||
flag.StringVar(&cert, "cert", "", "cert for client")
|
||||
flag.StringVar(&key, "key", "", "key for client")
|
||||
flag.StringVar(&secret, "secret", "dnKgzTPNZyEd2Kfop", "secret for jwt")
|
||||
flag.StringVar(&claims, "claims", "", "extra claims as k=v,k=v")
|
||||
flag.Parse()
|
||||
|
||||
if !strings.HasPrefix(host, "http") {
|
||||
|
|
@ -76,7 +77,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
if needJWT {
|
||||
setJWT(req, brandID, issuer, secret)
|
||||
setJWT(req, brandID, issuer, secret, claims)
|
||||
}
|
||||
if basicAuth != "" {
|
||||
splits := strings.Split(basicAuth, ",")
|
||||
|
|
@ -91,6 +92,9 @@ func main() {
|
|||
fmt.Println("DO FAILED:", err)
|
||||
return
|
||||
}
|
||||
if verbose {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", resp.Header)
|
||||
}
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Println("READ BODY FAILED:", err)
|
||||
|
|
@ -139,7 +143,7 @@ func makeClient(timeout time.Duration, ca, cert, key string) *http.Client {
|
|||
}
|
||||
}
|
||||
|
||||
func setJWT(r *http.Request, brandID string, issuer string, secret string) {
|
||||
func setJWT(r *http.Request, brandID string, issuer, secret, claims string) {
|
||||
signer := &jwt.Signer{
|
||||
Key: []byte(secret),
|
||||
DefaultClaims: jwt.Claims{
|
||||
|
|
@ -149,10 +153,18 @@ func setJWT(r *http.Request, brandID string, issuer string, secret string) {
|
|||
BrandID: brandID,
|
||||
Custom: map[string]interface{}{
|
||||
"IsolationPartitionID": brandID,
|
||||
"userType": "UT_SERVERADMIN",
|
||||
},
|
||||
},
|
||||
IncludeBodyHash: true,
|
||||
}
|
||||
for _, claim := range strings.Split(claims, ",") {
|
||||
c := strings.Split(claim, "=")
|
||||
if len(c) < 2 {
|
||||
continue
|
||||
}
|
||||
signer.DefaultClaims.Custom[c[0]] = c[1]
|
||||
}
|
||||
|
||||
if err := signer.Sign(r, jwt.Claims{}); err != nil {
|
||||
panic(err)
|
||||
|
|
|
|||
Loading…
Reference in New Issue