From 21a246ad028a73f423d4fdbd7481866672da8d1d Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Tue, 31 Mar 2020 12:44:34 +0100 Subject: [PATCH] Service => Service Auth --- grpc.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/grpc.go b/grpc.go index 0357abc..acc1e64 100644 --- a/grpc.go +++ b/grpc.go @@ -131,7 +131,15 @@ func (g *grpcClient) call(ctx context.Context, node *registry.Node, req client.R // set the content type for the request header["x-content-type"] = req.ContentType() - // set the authorization token if one is saved locally + // if the caller specifies using service privelages, and the client + // has auth set, override the authorization header + if opts.WithServicePrivileges && g.opts.Auth != nil && g.opts.Auth.Options().Token != nil { + t := g.opts.Auth.Options().Token + header["authorization"] = auth.BearerScheme + t.Token + } + + // fall back to using the authorization token set in config, + // this enables the CLI to provide a token if len(header["authorization"]) == 0 { if token, err := config.Get("token"); err == nil && len(token) > 0 { header["authorization"] = auth.BearerScheme + token