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