Improve Comments
This commit is contained in:
parent
99f8be5b3d
commit
ef9f65c78b
@ -146,7 +146,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac
|
|||||||
|
|
||||||
// check to see if the authorization header has already been set.
|
// check to see if the authorization header has already been set.
|
||||||
// We dont't override the header unless the ServiceToken option has
|
// We dont't override the header unless the ServiceToken option has
|
||||||
// been specified.
|
// been specified or the header wasn't provided
|
||||||
if _, ok := metadata.Get(ctx, "Authorization"); ok && !options.ServiceToken {
|
if _, ok := metadata.Get(ctx, "Authorization"); ok && !options.ServiceToken {
|
||||||
return a.Client.Call(ctx, req, rsp, opts...)
|
return a.Client.Call(ctx, req, rsp, opts...)
|
||||||
}
|
}
|
||||||
@ -158,8 +158,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac
|
|||||||
return a.Client.Call(ctx, req, rsp, opts...)
|
return a.Client.Call(ctx, req, rsp, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// callWithToken performs the client call with the authorization header
|
// performs the call with the authorization token provided
|
||||||
// set to the token.
|
|
||||||
callWithToken := func(token string) error {
|
callWithToken := func(token string) error {
|
||||||
ctx := metadata.Set(ctx, "Authorization", auth.BearerScheme+token)
|
ctx := metadata.Set(ctx, "Authorization", auth.BearerScheme+token)
|
||||||
return a.Client.Call(ctx, req, rsp, opts...)
|
return a.Client.Call(ctx, req, rsp, opts...)
|
||||||
@ -181,8 +180,7 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac
|
|||||||
return callWithToken(tok.AccessToken)
|
return callWithToken(tok.AccessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we have credentials we can generate a new token for the exiting auth
|
// if we have credentials we can generate a new token for the account
|
||||||
// account. these credential would've been set by env vars.
|
|
||||||
if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 {
|
if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 {
|
||||||
tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret))
|
tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -192,8 +190,8 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac
|
|||||||
return callWithToken(tok.AccessToken)
|
return callWithToken(tok.AccessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
// before we generate a new auth account, check to see if a token was provided
|
// check to see if a token was provided in config, this is normally used for
|
||||||
// in config, this is normally used for setting the token when calling via the cli
|
// setting the token when calling via the cli
|
||||||
if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 {
|
if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 {
|
||||||
return callWithToken(token)
|
return callWithToken(token)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user