Files
threshold/internal/auth/registry.go
T
Michael MiltonandMichael Gaffney 8d50a0913f Auth Method list pagination (#4165)
* wip

* implement list pagination for auth methods

* remove unused code

* update tests to fix sorting

* address PR comments

* simplify query, add token tests

* change test name

* wip sql testing

* add boolean column to indicate whether auth methods should be returned to unauthenticated users, remove secrets from api response

* is_active_public not null

* remove secrets and unwrapping

* move not null to immediately after data migration

* order public_id descending

* fix(db): Fix auth method migrations (#4193)

* wip

* fix db tests

* fix failing api tests

* reverse order of create time and update time in test

---------

Co-authored-by: Michael Gaffney <mike@gaffney.cc>
2024-01-05 07:43:21 -08:00

69 lines
1.6 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package auth
import (
"context"
"fmt"
"sync"
"github.com/hashicorp/boundary/globals"
)
// newAuthMethodFunc is a function that creates an AuthMethod from the provided result.
type newAuthMethodFunc func(context.Context, *AuthMethodListQueryResult) (AuthMethod, error)
// AuthMethodSubtypeHooks defines the interface expected to be implemented
// by auth method subtype hooks.
type AuthMethodSubtypeHooks interface {
NewAuthMethod(context.Context, *AuthMethodListQueryResult) (AuthMethod, error)
}
type registry struct {
m map[globals.Subtype]AuthMethodSubtypeHooks
sync.RWMutex
}
func (r *registry) set(s globals.Subtype, subtype AuthMethodSubtypeHooks) {
r.Lock()
defer r.Unlock()
_, previouslySet := r.m[s]
if previouslySet {
panic(fmt.Sprintf("auth method subtype %s already registered", s))
}
r.m[s] = subtype
}
func (r *registry) get(s globals.Subtype) (AuthMethodSubtypeHooks, bool) {
r.RLock()
defer r.RUnlock()
subtype, ok := r.m[s]
if ok {
return subtype, ok
}
return nil, ok
}
func (r *registry) newFunc(s globals.Subtype) (newAuthMethodFunc, bool) {
subtype, ok := r.get(s)
if !ok {
return nil, ok
}
return subtype.NewAuthMethod, ok
}
var subtypeRegistry = registry{
m: make(map[globals.Subtype]AuthMethodSubtypeHooks),
}
// RegisterAuthMethodSubtype registers repository hooks for a provided auth method sub type.
// RegisterAuthMethodSubtype panics if the subtype has already been registered.
func RegisterAuthMethodSubtype(s globals.Subtype, hooks AuthMethodSubtypeHooks) {
subtypeRegistry.set(s, hooks)
}