From ef9f65c78b170ac83242037f9757e1663df264aa Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 15:15:38 +0100 Subject: [PATCH] Improve Comments --- util/wrapper/wrapper.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index 677061ef..c97c9e54 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -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. // 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 { 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...) } - // callWithToken performs the client call with the authorization header - // set to the token. + // performs the call with the authorization token provided callWithToken := func(token string) error { ctx := metadata.Set(ctx, "Authorization", auth.BearerScheme+token) 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) } - // if we have credentials we can generate a new token for the exiting auth - // account. these credential would've been set by env vars. + // if we have credentials we can generate a new token for the account if len(aaOpts.ID) > 0 && len(aaOpts.Secret) > 0 { tok, err := aa.Token(auth.WithCredentials(aaOpts.ID, aaOpts.Secret)) if err != nil { @@ -192,8 +190,8 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac return callWithToken(tok.AccessToken) } - // before we generate a new auth account, check to see if a token was provided - // in config, this is normally used for setting the token when calling via the cli + // check to see if a token was provided in config, this is normally used for + // setting the token when calling via the cli if token, err := config.Get("micro", "auth", "token"); err == nil && len(token) > 0 { return callWithToken(token) }