From 86272a306446bb103fc21a394cf3f9a07429ab79 Mon Sep 17 00:00:00 2001 From: ben-toogood Date: Tue, 24 Mar 2020 10:18:34 +0000 Subject: [PATCH] WithRoles variadic args (#1395) Co-authored-by: Ben Toogood --- auth/options.go | 2 +- auth/store/store.go | 4 ++-- auth/store/store_test.go | 6 +++--- auth/token/basic/basic_test.go | 2 +- auth/token/jwt/jwt_test.go | 2 +- auth/token/options.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/auth/options.go b/auth/options.go index 6a49af2e..f7408335 100644 --- a/auth/options.go +++ b/auth/options.go @@ -85,7 +85,7 @@ func WithMetadata(md map[string]string) GenerateOption { } // WithRoles for the generated account -func WithRoles(rs []string) GenerateOption { +func WithRoles(rs ...string) GenerateOption { return func(o *GenerateOptions) { o.Roles = rs } diff --git a/auth/store/store.go b/auth/store/store.go index dad0be00..fe3693c9 100644 --- a/auth/store/store.go +++ b/auth/store/store.go @@ -68,7 +68,7 @@ func (s *Store) Generate(id string, opts ...auth.GenerateOption) (*auth.Account, secretOpts := []token.GenerateOption{ token.WithExpiry(options.SecretExpiry), token.WithMetadata(options.Metadata), - token.WithRoles(options.Roles), + token.WithRoles(options.Roles...), } secret, err := s.secretProvider.Generate(id, secretOpts...) if err != nil { @@ -166,6 +166,6 @@ func (s *Store) Refresh(secret string, opts ...auth.RefreshOption) (*auth.Token, return s.tokenProvider.Generate(sec.Subject, token.WithExpiry(options.TokenExpiry), token.WithMetadata(sec.Metadata), - token.WithRoles(sec.Roles), + token.WithRoles(sec.Roles...), ) } diff --git a/auth/store/store_test.go b/auth/store/store_test.go index 9b1ca0e9..d7dfd0c0 100644 --- a/auth/store/store_test.go +++ b/auth/store/store_test.go @@ -17,7 +17,7 @@ func TestGenerate(t *testing.T) { metadata := map[string]string{"foo": "bar"} opts := []auth.GenerateOption{ - auth.WithRoles(roles), + auth.WithRoles(roles...), auth.WithMetadata(metadata), } @@ -100,7 +100,7 @@ func TestInspect(t *testing.T) { metadata := map[string]string{"foo": "bar"} opts := []auth.GenerateOption{ - auth.WithRoles(roles), + auth.WithRoles(roles...), auth.WithMetadata(metadata), } @@ -146,7 +146,7 @@ func TestRefresh(t *testing.T) { metadata := map[string]string{"foo": "bar"} opts := []auth.GenerateOption{ - auth.WithRoles(roles), + auth.WithRoles(roles...), auth.WithMetadata(metadata), } diff --git a/auth/token/basic/basic_test.go b/auth/token/basic/basic_test.go index 159387a1..4498db3c 100644 --- a/auth/token/basic/basic_test.go +++ b/auth/token/basic/basic_test.go @@ -37,7 +37,7 @@ func TestInspect(t *testing.T) { opts := []token.GenerateOption{ token.WithMetadata(md), - token.WithRoles(roles), + token.WithRoles(roles...), } tok, err := b.Generate(subject, opts...) diff --git a/auth/token/jwt/jwt_test.go b/auth/token/jwt/jwt_test.go index 3a2c6237..576a1e2e 100644 --- a/auth/token/jwt/jwt_test.go +++ b/auth/token/jwt/jwt_test.go @@ -46,7 +46,7 @@ func TestInspect(t *testing.T) { opts := []token.GenerateOption{ token.WithMetadata(md), - token.WithRoles(roles), + token.WithRoles(roles...), } tok, err := j.Generate(subject, opts...) diff --git a/auth/token/options.go b/auth/token/options.go index d2e490b8..29e166e1 100644 --- a/auth/token/options.go +++ b/auth/token/options.go @@ -76,7 +76,7 @@ func WithMetadata(md map[string]string) func(o *GenerateOptions) { } // WithRoles for the token -func WithRoles(rs []string) func(o *GenerateOptions) { +func WithRoles(rs ...string) func(o *GenerateOptions) { return func(o *GenerateOptions) { o.Roles = rs }