refact(auth): Move subtype registration into global registry
This commit is contained in:
1 parent
31ef40ec5a
commit
185d8b392d
7 files changed
+55
-75
No files matched your search
@@ -3,7 +3,6 @@ package oidc
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/auth"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/intglobals"
|
||||
@@ -11,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := auth.Register(Subtype, AuthMethodPrefix, AccountPrefix, intglobals.OidcManagedGroupPrefix); err != nil {
|
||||
if err := subtypes.Register("auth", Subtype, AuthMethodPrefix, AccountPrefix, intglobals.OidcManagedGroupPrefix); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package password
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/internal/auth"
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
"github.com/hashicorp/boundary/internal/intglobals"
|
||||
@@ -9,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := auth.Register(Subtype, AuthMethodPrefix, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix); err != nil {
|
||||
if err := subtypes.Register("auth", Subtype, AuthMethodPrefix, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,30 +2,8 @@ package auth
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/internal/boundary"
|
||||
"github.com/hashicorp/boundary/internal/types/subtypes"
|
||||
)
|
||||
|
||||
var registry = subtypes.NewRegistry()
|
||||
|
||||
// SubtypeFromType returns the Subtype from the provided string or if
|
||||
// no Subtype was registered with that string Unknown is returned.
|
||||
func SubtypeFromType(t string) subtypes.Subtype {
|
||||
return registry.SubtypeFromType(t)
|
||||
}
|
||||
|
||||
// SubtypeFromId returns the Subtype from the provided id if the id's prefix
|
||||
// was registered with a Subtype. Otherwise Unknown is returned.
|
||||
func SubtypeFromId(id string) subtypes.Subtype {
|
||||
return registry.SubtypeFromId(id)
|
||||
}
|
||||
|
||||
// Register registers all the prefixes for a provided Subtype. Register returns
|
||||
// an error if the subtype has already been registered or if any of the
|
||||
// prefixes are associated with another subtype.
|
||||
func Register(subtype subtypes.Subtype, prefixes ...string) error {
|
||||
return registry.Register(subtype, prefixes...)
|
||||
}
|
||||
|
||||
// AuthMethod contains the common methods across all the different types of auth methods.
|
||||
type AuthMethod interface {
|
||||
boundary.Resource
|
||||
|
||||
@@ -49,6 +49,8 @@ const (
|
||||
subjectField = "attributes.subject"
|
||||
nameClaimField = "attributes.full_name"
|
||||
emailClaimField = "attributes.email"
|
||||
|
||||
domain = "auth"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -144,7 +146,7 @@ func (s Service) ListAccounts(ctx context.Context, req *pbs.ListAccountsRequest)
|
||||
}
|
||||
for _, acct := range ul {
|
||||
res.Id = acct.GetPublicId()
|
||||
authorizedActions := authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[auth.SubtypeFromId(acct.GetPublicId())], requestauth.WithResource(&res)).Strings()
|
||||
authorizedActions := authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[subtypes.SubtypeFromId(domain, acct.GetPublicId())], requestauth.WithResource(&res)).Strings()
|
||||
if len(authorizedActions) == 0 {
|
||||
continue
|
||||
}
|
||||
@@ -201,7 +203,7 @@ func (s Service) GetAccount(ctx context.Context, req *pbs.GetAccountRequest) (*p
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[auth.SubtypeFromId(acct.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[subtypes.SubtypeFromId(domain, acct.GetPublicId())]).Strings()))
|
||||
}
|
||||
if outputFields.Has(globals.ManagedGroupIdsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithManagedGroupIds(mgIds))
|
||||
@@ -243,7 +245,7 @@ func (s Service) CreateAccount(ctx context.Context, req *pbs.CreateAccountReques
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[auth.SubtypeFromId(acct.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[subtypes.SubtypeFromId(domain, acct.GetPublicId())]).Strings()))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, acct, outputOpts...)
|
||||
@@ -282,7 +284,7 @@ func (s Service) UpdateAccount(ctx context.Context, req *pbs.UpdateAccountReques
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[auth.SubtypeFromId(acct.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[subtypes.SubtypeFromId(domain, acct.GetPublicId())]).Strings()))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, acct, outputOpts...)
|
||||
@@ -337,7 +339,7 @@ func (s Service) ChangePassword(ctx context.Context, req *pbs.ChangePasswordRequ
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[auth.SubtypeFromId(acct.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[subtypes.SubtypeFromId(domain, acct.GetPublicId())]).Strings()))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, acct, outputOpts...)
|
||||
@@ -376,7 +378,7 @@ func (s Service) SetPassword(ctx context.Context, req *pbs.SetPasswordRequest) (
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[auth.SubtypeFromId(acct.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, acct.GetPublicId(), IdActions[subtypes.SubtypeFromId(domain, acct.GetPublicId())]).Strings()))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, acct, outputOpts...)
|
||||
@@ -392,7 +394,7 @@ func (s Service) SetPassword(ctx context.Context, req *pbs.SetPasswordRequest) (
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (auth.Account, []string, error) {
|
||||
var acct auth.Account
|
||||
var mgIds []string
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId(domain, id) {
|
||||
case password.Subtype:
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
@@ -513,7 +515,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
}
|
||||
var out auth.Account
|
||||
switch auth.SubtypeFromId(am.GetPublicId()) {
|
||||
switch subtypes.SubtypeFromId(domain, am.GetPublicId()) {
|
||||
case password.Subtype:
|
||||
am, err := s.createPwInRepo(ctx, am, item)
|
||||
if err != nil {
|
||||
@@ -606,7 +608,7 @@ func (s Service) updateOidcInRepo(ctx context.Context, scopeId, amId, id string,
|
||||
func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string, req *pbs.UpdateAccountRequest) (auth.Account, error) {
|
||||
const op = "accounts.(Service).updateInRepo"
|
||||
var out auth.Account
|
||||
switch auth.SubtypeFromId(req.GetId()) {
|
||||
switch subtypes.SubtypeFromId(domain, req.GetId()) {
|
||||
case password.Subtype:
|
||||
a, err := s.updatePwInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
|
||||
if err != nil {
|
||||
@@ -633,7 +635,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
const op = "accounts.(Service).deleteFromRepo"
|
||||
var rows int
|
||||
var err error
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId(domain, id) {
|
||||
case password.Subtype:
|
||||
repo, iErr := s.pwRepoFn()
|
||||
if iErr != nil {
|
||||
@@ -660,7 +662,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
|
||||
const op = "accounts.(Service).listFromRepo"
|
||||
|
||||
var outUl []auth.Account
|
||||
switch auth.SubtypeFromId(authMethodId) {
|
||||
switch subtypes.SubtypeFromId(domain, authMethodId) {
|
||||
case password.Subtype:
|
||||
pwRepo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
@@ -755,7 +757,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
case action.List, action.Create:
|
||||
parentId = id
|
||||
default:
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId(domain, id) {
|
||||
case password.Subtype:
|
||||
acct, err := pwRepo.LookupAccount(ctx, id)
|
||||
if err != nil {
|
||||
@@ -783,7 +785,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
}
|
||||
|
||||
var authMeth auth.AuthMethod
|
||||
switch auth.SubtypeFromId(parentId) {
|
||||
switch subtypes.SubtypeFromId(domain, parentId) {
|
||||
case password.Subtype:
|
||||
am, err := pwRepo.LookupAuthMethod(ctx, parentId)
|
||||
if err != nil {
|
||||
@@ -951,7 +953,7 @@ func validateCreateRequest(req *pbs.CreateAccountRequest) error {
|
||||
if req.GetItem().GetAuthMethodId() == "" {
|
||||
badFields[authMethodIdField] = "This field is required."
|
||||
}
|
||||
switch auth.SubtypeFromId(req.GetItem().GetAuthMethodId()) {
|
||||
switch subtypes.SubtypeFromId(domain, req.GetItem().GetAuthMethodId()) {
|
||||
case password.Subtype:
|
||||
if req.GetItem().GetType() != "" && req.GetItem().GetType() != password.Subtype.String() {
|
||||
badFields[typeField] = "Doesn't match the parent resource's type."
|
||||
@@ -997,7 +999,7 @@ func validateUpdateRequest(req *pbs.UpdateAccountRequest) error {
|
||||
}
|
||||
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
switch auth.SubtypeFromId(req.GetId()) {
|
||||
switch subtypes.SubtypeFromId(domain, req.GetId()) {
|
||||
case password.Subtype:
|
||||
if req.GetItem().GetType() != "" && req.GetItem().GetType() != password.Subtype.String() {
|
||||
badFields[typeField] = "Cannot modify the resource type."
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/auth"
|
||||
"github.com/hashicorp/boundary/internal/auth/oidc"
|
||||
"github.com/hashicorp/boundary/internal/auth/password"
|
||||
"github.com/hashicorp/boundary/internal/authtoken"
|
||||
@@ -25,6 +24,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers/accounts"
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/boundary/internal/types/subtypes"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/accounts"
|
||||
scopepb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -36,6 +36,8 @@ import (
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
const domain = "auth"
|
||||
|
||||
var (
|
||||
pwAuthorizedActions = []string{
|
||||
action.NoOp.String(),
|
||||
@@ -224,7 +226,7 @@ func TestGet(t *testing.T) {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
|
||||
if auth.SubtypeFromId(tc.req.Id) == oidc.Subtype {
|
||||
if subtypes.SubtypeFromId(domain, tc.req.Id) == oidc.Subtype {
|
||||
// Set up managed groups before getting. First get the current
|
||||
// managed group to make sure we have the right version.
|
||||
oidcRepo, err := oidcRepoFn()
|
||||
|
||||
@@ -150,7 +150,7 @@ func (s Service) ListAuthMethods(ctx context.Context, req *pbs.ListAuthMethodsRe
|
||||
for _, am := range ul {
|
||||
res.Id = am.GetPublicId()
|
||||
res.ScopeId = am.GetScopeId()
|
||||
authorizedActions := authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())], requestauth.WithResource(&res)).Strings()
|
||||
authorizedActions := authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", am.GetPublicId())], requestauth.WithResource(&res)).Strings()
|
||||
if len(authorizedActions) == 0 {
|
||||
continue
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func (s Service) GetAuthMethod(ctx context.Context, req *pbs.GetAuthMethodReques
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", am.GetPublicId())]).Strings()))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
|
||||
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
|
||||
@@ -256,7 +256,7 @@ func (s Service) CreateAuthMethod(ctx context.Context, req *pbs.CreateAuthMethod
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", am.GetPublicId())]).Strings()))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
|
||||
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
|
||||
@@ -306,7 +306,7 @@ func (s Service) UpdateAuthMethod(ctx context.Context, req *pbs.UpdateAuthMethod
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", am.GetPublicId())]).Strings()))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
|
||||
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
|
||||
@@ -360,7 +360,7 @@ func (s Service) ChangeState(ctx context.Context, req *pbs.ChangeStateRequest) (
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[auth.SubtypeFromId(am.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, am.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", am.GetPublicId())]).Strings()))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedCollectionActionsField) {
|
||||
collectionActions, err := requestauth.CalculateAuthorizedCollectionActions(ctx, authResults, collectionTypeMap, authResults.Scope.Id, am.GetPublicId())
|
||||
@@ -401,7 +401,7 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
switch auth.SubtypeFromId(req.GetAuthMethodId()) {
|
||||
switch subtypes.SubtypeFromId("auth", req.GetAuthMethodId()) {
|
||||
case password.Subtype:
|
||||
if err := validateAuthenticatePasswordRequest(req); err != nil {
|
||||
return nil, err
|
||||
@@ -417,7 +417,7 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
|
||||
return nil, authResults.Error
|
||||
}
|
||||
|
||||
switch auth.SubtypeFromId(req.GetAuthMethodId()) {
|
||||
switch subtypes.SubtypeFromId("auth", req.GetAuthMethodId()) {
|
||||
case password.Subtype:
|
||||
return s.authenticatePassword(ctx, req, &authResults)
|
||||
|
||||
@@ -430,7 +430,7 @@ func (s Service) Authenticate(ctx context.Context, req *pbs.AuthenticateRequest)
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (auth.AuthMethod, error) {
|
||||
var lookupErr error
|
||||
var am auth.AuthMethod
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId("auth", id) {
|
||||
case password.Subtype:
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
@@ -500,7 +500,7 @@ func (s Service) listFromRepo(ctx context.Context, scopeIds []string, authResult
|
||||
func (s Service) createInRepo(ctx context.Context, scopeId string, item *pb.AuthMethod) (auth.AuthMethod, error) {
|
||||
const op = "authmethods.(Service).createInRepo"
|
||||
var out auth.AuthMethod
|
||||
switch auth.SubtypeFromType(item.GetType()) {
|
||||
switch subtypes.SubtypeFromType("auth", item.GetType()) {
|
||||
case password.Subtype:
|
||||
am, err := s.createPwInRepo(ctx, scopeId, item)
|
||||
if err != nil {
|
||||
@@ -529,7 +529,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId string, req *pbs.Upda
|
||||
var am auth.AuthMethod
|
||||
var dryRun bool
|
||||
|
||||
switch auth.SubtypeFromId(req.GetId()) {
|
||||
switch subtypes.SubtypeFromId("auth", req.GetId()) {
|
||||
case password.Subtype:
|
||||
pam, err := s.updatePwInRepo(ctx, scopeId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
|
||||
if err != nil {
|
||||
@@ -559,7 +559,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
const op = "authmethods.(Service).deleteFromRepo"
|
||||
var rows int
|
||||
var dErr error
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId("auth", id) {
|
||||
case password.Subtype:
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
@@ -588,7 +588,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
func (s Service) changeStateInRepo(ctx context.Context, req *pbs.ChangeStateRequest) (auth.AuthMethod, error) {
|
||||
const op = "authmethod_service.(Service).changeStateInRepo"
|
||||
|
||||
switch auth.SubtypeFromId(req.GetId()) {
|
||||
switch subtypes.SubtypeFromId("auth", req.GetId()) {
|
||||
case oidc.Subtype:
|
||||
repo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
@@ -651,7 +651,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) reque
|
||||
}
|
||||
default:
|
||||
var authMeth auth.AuthMethod
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId("auth", id) {
|
||||
case password.Subtype:
|
||||
repo, err := s.pwRepoFn()
|
||||
if err != nil {
|
||||
@@ -837,7 +837,7 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateAuthMethodRequest
|
||||
if req.GetItem().GetIsPrimary() {
|
||||
badFields[isPrimaryField] = "This field is read only."
|
||||
}
|
||||
switch auth.SubtypeFromType(req.GetItem().GetType()) {
|
||||
switch subtypes.SubtypeFromType("auth", req.GetItem().GetType()) {
|
||||
case password.Subtype:
|
||||
attrs := &pb.PasswordAuthMethodAttributes{}
|
||||
if err := handlers.StructToProto(req.GetItem().GetAttributes(), attrs); err != nil {
|
||||
@@ -935,9 +935,9 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAuthMethodRequest
|
||||
if handlers.MaskContains(req.GetUpdateMask().GetPaths(), isPrimaryField) {
|
||||
badFields[isPrimaryField] = "This field is read only."
|
||||
}
|
||||
switch auth.SubtypeFromId(req.GetId()) {
|
||||
switch subtypes.SubtypeFromId("auth", req.GetId()) {
|
||||
case password.Subtype:
|
||||
if req.GetItem().GetType() != "" && auth.SubtypeFromType(req.GetItem().GetType()) != password.Subtype {
|
||||
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType("auth", req.GetItem().GetType()) != password.Subtype {
|
||||
badFields[typeField] = "Cannot modify the resource type."
|
||||
}
|
||||
attrs := &pb.PasswordAuthMethodAttributes{}
|
||||
@@ -945,7 +945,7 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAuthMethodRequest
|
||||
badFields[attributesField] = "Attribute fields do not match the expected format."
|
||||
}
|
||||
case oidc.Subtype:
|
||||
if req.GetItem().GetType() != "" && auth.SubtypeFromType(req.GetItem().GetType()) != oidc.Subtype {
|
||||
if req.GetItem().GetType() != "" && subtypes.SubtypeFromType("auth", req.GetItem().GetType()) != oidc.Subtype {
|
||||
badFields[typeField] = "Cannot modify the resource type."
|
||||
}
|
||||
attrs := &pb.OidcAuthMethodAttributes{}
|
||||
@@ -1088,7 +1088,7 @@ func validateChangeStateRequest(req *pbs.ChangeStateRequest) error {
|
||||
if req == nil {
|
||||
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
|
||||
}
|
||||
if st := auth.SubtypeFromId(req.GetId()); st != oidc.Subtype {
|
||||
if st := subtypes.SubtypeFromId("auth", req.GetId()); st != oidc.Subtype {
|
||||
return handlers.NotFoundErrorf("This endpoint is only available for the %q Auth Method type.", oidc.Subtype.String())
|
||||
}
|
||||
badFields := make(map[string]string)
|
||||
@@ -1122,7 +1122,7 @@ func validateAuthenticateRequest(req *pbs.AuthenticateRequest) error {
|
||||
if strings.TrimSpace(req.GetAuthMethodId()) == "" {
|
||||
badFields[authMethodIdField] = "This is a required field."
|
||||
} else {
|
||||
st := auth.SubtypeFromId(req.GetAuthMethodId())
|
||||
st := subtypes.SubtypeFromId("auth", req.GetAuthMethodId())
|
||||
switch st {
|
||||
case password.Subtype, oidc.Subtype:
|
||||
default:
|
||||
|
||||
@@ -107,7 +107,7 @@ func (s Service) ListManagedGroups(ctx context.Context, req *pbs.ListManagedGrou
|
||||
}
|
||||
for _, mg := range ul {
|
||||
res.Id = mg.GetPublicId()
|
||||
authorizedActions := authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[auth.SubtypeFromId(mg.GetPublicId())], requestauth.WithResource(&res)).Strings()
|
||||
authorizedActions := authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", mg.GetPublicId())], requestauth.WithResource(&res)).Strings()
|
||||
if len(authorizedActions) == 0 {
|
||||
continue
|
||||
}
|
||||
@@ -164,7 +164,7 @@ func (s Service) GetManagedGroup(ctx context.Context, req *pbs.GetManagedGroupRe
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[auth.SubtypeFromId(mg.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", mg.GetPublicId())]).Strings()))
|
||||
}
|
||||
if outputFields.Has(globals.MemberIdsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithMemberIds(memberIds))
|
||||
@@ -206,7 +206,7 @@ func (s Service) CreateManagedGroup(ctx context.Context, req *pbs.CreateManagedG
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[auth.SubtypeFromId(mg.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", mg.GetPublicId())]).Strings()))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, mg, outputOpts...)
|
||||
@@ -245,7 +245,7 @@ func (s Service) UpdateManagedGroup(ctx context.Context, req *pbs.UpdateManagedG
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[auth.SubtypeFromId(mg.GetPublicId())]).Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, mg.GetPublicId(), IdActions[subtypes.SubtypeFromId("auth", mg.GetPublicId())]).Strings()))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, mg, outputOpts...)
|
||||
@@ -275,7 +275,7 @@ func (s Service) DeleteManagedGroup(ctx context.Context, req *pbs.DeleteManagedG
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (auth.ManagedGroup, []string, error) {
|
||||
var out auth.ManagedGroup
|
||||
var memberIds []string
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId("auth", id) {
|
||||
case oidc.Subtype:
|
||||
repo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
@@ -347,7 +347,7 @@ func (s Service) createInRepo(ctx context.Context, am auth.AuthMethod, item *pb.
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
}
|
||||
var out auth.ManagedGroup
|
||||
switch auth.SubtypeFromId(am.GetPublicId()) {
|
||||
switch subtypes.SubtypeFromId("auth", am.GetPublicId()) {
|
||||
case oidc.Subtype:
|
||||
am, err := s.createOidcInRepo(ctx, am, item)
|
||||
if err != nil {
|
||||
@@ -407,7 +407,7 @@ func (s Service) updateOidcInRepo(ctx context.Context, scopeId, amId, id string,
|
||||
func (s Service) updateInRepo(ctx context.Context, scopeId, authMethodId string, req *pbs.UpdateManagedGroupRequest) (auth.ManagedGroup, error) {
|
||||
const op = "managed_groups.(Service).updateInRepo"
|
||||
var out auth.ManagedGroup
|
||||
switch auth.SubtypeFromId(req.GetId()) {
|
||||
switch subtypes.SubtypeFromId("auth", req.GetId()) {
|
||||
case oidc.Subtype:
|
||||
mg, err := s.updateOidcInRepo(ctx, scopeId, authMethodId, req.GetId(), req.GetUpdateMask().GetPaths(), req.GetItem())
|
||||
if err != nil {
|
||||
@@ -425,7 +425,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
const op = "managed_groups.(Service).deleteFromRepo"
|
||||
var rows int
|
||||
var err error
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId("auth", id) {
|
||||
case oidc.Subtype:
|
||||
repo, iErr := s.oidcRepoFn()
|
||||
if iErr != nil {
|
||||
@@ -446,7 +446,7 @@ func (s Service) listFromRepo(ctx context.Context, authMethodId string) ([]auth.
|
||||
const op = "managed_groups.(Service).listFromRepo"
|
||||
|
||||
var outUl []auth.ManagedGroup
|
||||
switch auth.SubtypeFromId(authMethodId) {
|
||||
switch subtypes.SubtypeFromId("auth", authMethodId) {
|
||||
case oidc.Subtype:
|
||||
oidcRepo, err := s.oidcRepoFn()
|
||||
if err != nil {
|
||||
@@ -478,7 +478,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
case action.List, action.Create:
|
||||
parentId = id
|
||||
default:
|
||||
switch auth.SubtypeFromId(id) {
|
||||
switch subtypes.SubtypeFromId("auth", id) {
|
||||
case oidc.Subtype:
|
||||
acct, err := oidcRepo.LookupManagedGroup(ctx, id)
|
||||
if err != nil {
|
||||
@@ -498,7 +498,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
}
|
||||
|
||||
var authMeth auth.AuthMethod
|
||||
switch auth.SubtypeFromId(parentId) {
|
||||
switch subtypes.SubtypeFromId("auth", parentId) {
|
||||
case oidc.Subtype:
|
||||
am, err := oidcRepo.LookupAuthMethod(ctx, parentId)
|
||||
if err != nil {
|
||||
@@ -600,7 +600,7 @@ func validateCreateRequest(req *pbs.CreateManagedGroupRequest) error {
|
||||
if req.GetItem().GetAuthMethodId() == "" {
|
||||
badFields[globals.AuthMethodIdField] = "This field is required."
|
||||
}
|
||||
switch auth.SubtypeFromId(req.GetItem().GetAuthMethodId()) {
|
||||
switch subtypes.SubtypeFromId("auth", req.GetItem().GetAuthMethodId()) {
|
||||
case oidc.Subtype:
|
||||
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
|
||||
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
|
||||
@@ -630,7 +630,7 @@ func validateUpdateRequest(req *pbs.UpdateManagedGroupRequest) error {
|
||||
}
|
||||
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
switch auth.SubtypeFromId(req.GetId()) {
|
||||
switch subtypes.SubtypeFromId("auth", req.GetId()) {
|
||||
case oidc.Subtype:
|
||||
if req.GetItem().GetType() != "" && req.GetItem().GetType() != oidc.Subtype.String() {
|
||||
badFields[globals.TypeField] = "Cannot modify the resource type."
|
||||
|
||||
Reference in new issue
Block a user