feat(handlers): Register actions for each resource type
This registers the ActionSets for each resource when the handler packages are initialized. This then allows other packages to retrieve the ActionSets for a given resource from the action package. The initial consumer of this will be the ratelimit package so that it can programmatically enumerate all of the valid combinations of a resource and action. This leaves a number of TODO to refactor the handler packages to also retrieve the action sets from the registered actions instead of using a package variable. This is left as a TODO since there is some inconsistencies in how these package variables are used between the handlers. For example a number of packages use a map of subtypes to ActionSets which is then used withing the handler implementation. Others use a map, but don't seem to use it at all. And others just use an ActionSet.
This commit is contained in:
19 files changed
+90
No files matched your search
@@ -28,6 +28,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"github.com/hashicorp/boundary/internal/types/subtypes"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/accounts"
|
||||
"golang.org/x/exp/maps"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
@@ -108,6 +109,9 @@ func init() {
|
||||
if oidcMaskManager, err = handlers.NewMaskManager(context.Background(), handlers.MaskDestination{&oidcstore.Account{}}, handlers.MaskSource{&pb.Account{}, &pb.OidcAccountAttributes{}}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.Account, action.Union(maps.Values(IdActions)...), CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.AccountServiceServer interface.
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package authmethods
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
// init functions process in alphabetical order of filenames within a package.
|
||||
// this needs to run last since it used the IdActions variable which gets
|
||||
// modified in other init functions in this package.
|
||||
func init() {
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
// Then this registration can happen in authmethod_service.go and we don't
|
||||
// need to worry about the order of init functions in a package.
|
||||
action.RegisterResource(resource.AuthMethod, action.Union(maps.Values(IdActions)...), CollectionActions)
|
||||
}
|
||||
@@ -42,6 +42,11 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO: refactor to remove IdActionsMap and CollectionActions package variables
|
||||
action.RegisterResource(resource.AuthToken, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.AuthTokenServiceServer interface.
|
||||
type Service struct {
|
||||
pbs.UnsafeAuthTokenServiceServer
|
||||
|
||||
@@ -103,6 +103,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActionsMap and CollectionActions package variables
|
||||
action.RegisterResource(resource.CredentialLibrary, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.CredentialLibraryServiceServer interface.
|
||||
|
||||
@@ -86,6 +86,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActionsMap and CollectionActions package variables
|
||||
action.RegisterResource(resource.Credential, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.CredentialServiceServer interface.
|
||||
|
||||
@@ -86,6 +86,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActionsMap and CollectionActions package variables
|
||||
action.RegisterResource(resource.CredentialStore, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.CredentialStoreServiceServer interface.
|
||||
|
||||
@@ -59,6 +59,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActionsMap and CollectionActions package variables
|
||||
action.RegisterResource(resource.Group, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.GroupServiceServer interface.
|
||||
|
||||
@@ -89,6 +89,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove idActionsMap and CollectionActions package variables
|
||||
action.RegisterResource(resource.HostCatalog, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostsets"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
"golang.org/x/exp/maps"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
@@ -83,6 +84,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove idActionsMap and CollectionActions package variables
|
||||
action.RegisterResource(resource.HostSet, action.Union(maps.Values(idActionsTypeMap)...), CollectionActions)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/types/subtypes"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hosts"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
|
||||
"golang.org/x/exp/maps"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
@@ -68,6 +69,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove idActionsMap and CollectionActions package variables
|
||||
action.RegisterResource(resource.Host, action.Union(maps.Values(idActionsTypeMap)...), CollectionActions)
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
|
||||
@@ -26,6 +26,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/types/subtypes"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/managedgroups"
|
||||
"github.com/hashicorp/go-bexpr"
|
||||
"golang.org/x/exp/maps"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
@@ -83,6 +84,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.ManagedGroup, action.Union(maps.Values(IdActions)...), CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.ManagedGroupServiceServer interface.
|
||||
|
||||
@@ -63,6 +63,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.Role, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.RoleServiceServer interface.
|
||||
|
||||
@@ -67,6 +67,7 @@ var (
|
||||
action.DestroyScopeKeyVersion,
|
||||
)
|
||||
|
||||
// TODO: get this from action registry
|
||||
scopeCollectionTypeMapMap = map[string]map[resource.Type]action.ActionSet{
|
||||
scope.Global.String(): {
|
||||
resource.AuthMethod: authmethods.CollectionActions,
|
||||
@@ -117,6 +118,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.Scope, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles requests as described by the pbs.ScopeServiceServer interface.
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
intglobals "github.com/hashicorp/boundary/internal/globals"
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -32,6 +33,11 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.SessionRecording, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// NewServiceFn returns a storage bucket service which is not implemented in OSS
|
||||
var NewServiceFn = func(ctx context.Context,
|
||||
iamRepoFn common.IamRepoFactory,
|
||||
|
||||
@@ -44,6 +44,11 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.Session, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.SessionServiceServer interface.
|
||||
type Service struct {
|
||||
pbs.UnsafeSessionServiceServer
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/globals"
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -32,6 +33,11 @@ var (
|
||||
)
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.StorageBucket, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// NewServiceFn returns a storage bucket service which is not implemented in OSS
|
||||
var NewServiceFn = func(ctx context.Context,
|
||||
pluginStorageRepoFn common.PluginStorageBucketRepoFactory,
|
||||
|
||||
@@ -102,6 +102,11 @@ var (
|
||||
WorkerFilterDeprecationMessage = fmt.Sprintf("This field is deprecated. Use %s instead.", globals.EgressWorkerFilterField)
|
||||
)
|
||||
|
||||
func init() {
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.Target, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
func IngressWorkerFilterUnsupported(string) error {
|
||||
return fmt.Errorf("Ingress Worker Filter field is not supported in OSS")
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.User, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
// Service handles request as described by the pbs.UserServiceServer interface.
|
||||
|
||||
@@ -80,6 +80,9 @@ func init() {
|
||||
); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: refactor to remove IdActions and CollectionActions package variables
|
||||
action.RegisterResource(resource.Worker, IdActions, CollectionActions)
|
||||
}
|
||||
|
||||
func emptyDownstreamWorkers(context.Context, string, common.Downstreamers) []string {
|
||||
|
||||
Reference in new issue
Block a user