Use Server ID in account name

This commit is contained in:
Ben Toogood 2020-04-29 15:27:18 +01:00
parent ef9f65c78b
commit f48dec1fb0
2 changed files with 7 additions and 4 deletions

View File

@ -41,7 +41,7 @@ func newService(opts ...Option) Service {
// wrap client to inject From-Service header on any calls // wrap client to inject From-Service header on any calls
options.Client = wrapper.FromService(serviceName, options.Client) options.Client = wrapper.FromService(serviceName, options.Client)
options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, 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 // wrap the server to provide handler stats
options.Server.Init( options.Server.Init(

View File

@ -2,6 +2,7 @@ package wrapper
import ( import (
"context" "context"
"fmt"
"strings" "strings"
"time" "time"
@ -134,6 +135,7 @@ func TraceHandler(t trace.Tracer) server.HandlerWrapper {
type authWrapper struct { type authWrapper struct {
client.Client client.Client
name string name string
id string
auth func() auth.Auth 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 // 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 { if err != nil {
return err 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 // AuthClient wraps requests with the auth header
func AuthClient(name string, auth func() auth.Auth, c client.Client) client.Client { func AuthClient(name string, id string, auth func() auth.Auth, c client.Client) client.Client {
return &authWrapper{c, name, auth} return &authWrapper{c, name, id, auth}
} }
// AuthHandler wraps a server handler to perform auth // AuthHandler wraps a server handler to perform auth