2020-09-01 12:31:54 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2021-01-13 14:42:37 -05:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2020-07-22 15:10:44 -04:00
|
|
|
package auth
|
|
|
|
|
|
2020-09-01 12:31:54 -04:00
|
|
|
import (
|
|
|
|
|
"github.com/hashicorp/boundary/internal/kms"
|
2021-01-13 14:42:37 -05:00
|
|
|
"github.com/hashicorp/boundary/internal/perms"
|
2020-09-01 12:31:54 -04:00
|
|
|
"github.com/hashicorp/boundary/internal/types/action"
|
2020-09-04 14:48:11 -07:00
|
|
|
"github.com/hashicorp/boundary/internal/types/resource"
|
2020-09-01 12:31:54 -04:00
|
|
|
)
|
2020-08-20 13:34:03 -04:00
|
|
|
|
2020-07-22 15:10:44 -04:00
|
|
|
func getOpts(opt ...Option) options {
|
|
|
|
|
opts := getDefaultOptions()
|
|
|
|
|
for _, o := range opt {
|
|
|
|
|
o(&opts)
|
|
|
|
|
}
|
|
|
|
|
return opts
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Option - how Options are passed as arguments
|
|
|
|
|
type Option func(*options)
|
|
|
|
|
|
|
|
|
|
// options = how options are represented
|
|
|
|
|
type options struct {
|
2020-12-17 10:30:40 -05:00
|
|
|
withScopeId string
|
|
|
|
|
withPin string
|
|
|
|
|
withId string
|
|
|
|
|
withAction action.Type
|
|
|
|
|
withType resource.Type
|
|
|
|
|
withUserId string
|
|
|
|
|
withKms *kms.Kms
|
|
|
|
|
withRecoveryTokenNotAllowed bool
|
|
|
|
|
withAnonymousUserNotAllowed bool
|
2021-01-13 14:42:37 -05:00
|
|
|
withResource *perms.Resource
|
2020-07-22 15:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getDefaultOptions() options {
|
2021-05-04 19:57:35 -05:00
|
|
|
return options{}
|
2020-07-22 15:10:44 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WithScopeId(id string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withScopeId = id
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-13 17:39:48 -04:00
|
|
|
|
2020-09-01 12:31:54 -04:00
|
|
|
func WithPin(pin string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withPin = pin
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WithId(id string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withId = id
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WithAction(action action.Type) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withAction = action
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 14:48:11 -07:00
|
|
|
func WithType(rt resource.Type) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withType = rt
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-13 17:39:48 -04:00
|
|
|
func WithUserId(id string) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withUserId = id
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-08-20 13:34:03 -04:00
|
|
|
|
|
|
|
|
func WithKms(kms *kms.Kms) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withKms = kms
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-17 10:30:40 -05:00
|
|
|
|
|
|
|
|
func WithRecoveryTokenNotAllowed(notAllowed bool) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withRecoveryTokenNotAllowed = notAllowed
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func WithAnonymousUserNotAllowed(notAllowed bool) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withAnonymousUserNotAllowed = notAllowed
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-13 14:42:37 -05:00
|
|
|
|
|
|
|
|
// WithResource specifies a resouce to use
|
|
|
|
|
func WithResource(resource *perms.Resource) Option {
|
|
|
|
|
return func(o *options) {
|
|
|
|
|
o.withResource = resource
|
|
|
|
|
}
|
|
|
|
|
}
|