From f48dec1fb02418c16436ff96951a77b6814f85c1 Mon Sep 17 00:00:00 2001 From: Ben Toogood Date: Wed, 29 Apr 2020 15:27:18 +0100 Subject: [PATCH] Use Server ID in account name --- service.go | 2 +- util/wrapper/wrapper.go | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/service.go b/service.go index 6cdb6b69..f7941e30 100644 --- a/service.go +++ b/service.go @@ -41,7 +41,7 @@ func newService(opts ...Option) Service { // wrap client to inject From-Service header on any calls options.Client = wrapper.FromService(serviceName, options.Client) options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client) - options.Client = wrapper.AuthClient(serviceName, authFn, options.Client) + options.Client = wrapper.AuthClient(serviceName, options.Server.Options().Id, authFn, options.Client) // wrap the server to provide handler stats options.Server.Init( diff --git a/util/wrapper/wrapper.go b/util/wrapper/wrapper.go index c97c9e54..ee569ef2 100644 --- a/util/wrapper/wrapper.go +++ b/util/wrapper/wrapper.go @@ -2,6 +2,7 @@ package wrapper import ( "context" + "fmt" "strings" "time" @@ -134,6 +135,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper { type authWrapper struct { client.Client name string + id string auth func() auth.Auth } @@ -208,7 +210,8 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac } // generate a new auth account for the service - acc, err := aa.Generate(a.name, auth.WithNamespace(aaOpts.Namespace), auth.WithRoles(serviceType)) + name := fmt.Sprintf("%v-%v", a.name, a.id) + acc, err := aa.Generate(name, auth.WithNamespace(aaOpts.Namespace), auth.WithRoles(serviceType)) if err != nil { return err } @@ -223,8 +226,8 @@ func (a *authWrapper) Call(ctx context.Context, req client.Request, rsp interfac } // AuthClient wraps requests with the auth header -func AuthClient(name string, auth func() auth.Auth, c client.Client) client.Client { - return &authWrapper{c, name, auth} +func AuthClient(name string, id string, auth func() auth.Auth, c client.Client) client.Client { + return &authWrapper{c, name, id, auth} } // AuthHandler wraps a server handler to perform auth