Auth - Swap Refresh to Token and change secrets to be strings, not tokens (#1444)

* Refresh => Token

* Secret is no longer a token

Co-authored-by: Ben Toogood <ben@micro.mu>
This commit is contained in:
ben-toogood
2020-03-31 10:06:13 +01:00
committed by GitHub
parent c706ebe3fb
commit 76ade7efd9
7 changed files with 144 additions and 166 deletions

View File

@@ -71,8 +71,6 @@ type GenerateOptions struct {
Metadata map[string]string
// Roles/scopes associated with the account
Roles []string
// SecretExpiry is the time the secret should live for
SecretExpiry time.Duration
// Namespace the account belongs too
Namespace string
}
@@ -100,45 +98,32 @@ func WithNamespace(n string) GenerateOption {
}
}
// WithSecretExpiry for the generated account's secret expires
func WithSecretExpiry(ex time.Duration) GenerateOption {
return func(o *GenerateOptions) {
o.SecretExpiry = ex
}
}
// NewGenerateOptions from a slice of options
func NewGenerateOptions(opts ...GenerateOption) GenerateOptions {
var options GenerateOptions
for _, o := range opts {
o(&options)
}
// set defualt expiry of secret
if options.SecretExpiry == 0 {
options.SecretExpiry = time.Hour * 24 * 7
}
return options
}
type RefreshOptions struct {
type TokenOptions struct {
// TokenExpiry is the time the token should live for
TokenExpiry time.Duration
}
type RefreshOption func(o *RefreshOptions)
type TokenOption func(o *TokenOptions)
// WithTokenExpiry for the token
func WithTokenExpiry(ex time.Duration) RefreshOption {
return func(o *RefreshOptions) {
func WithTokenExpiry(ex time.Duration) TokenOption {
return func(o *TokenOptions) {
o.TokenExpiry = ex
}
}
// NewRefreshOptions from a slice of options
func NewRefreshOptions(opts ...RefreshOption) RefreshOptions {
var options RefreshOptions
// NewTokenOptions from a slice of options
func NewTokenOptions(opts ...TokenOption) TokenOptions {
var options TokenOptions
for _, o := range opts {
o(&options)
}