diff --git a/internal/auth/ldap/account.go b/internal/auth/ldap/account.go index f3a8fcf5d..ac3633b67 100644 --- a/internal/auth/ldap/account.go +++ b/internal/auth/ldap/account.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/auth/ldap/store" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -120,6 +121,11 @@ func (a *Account) GetSubject() string { return "" } +// GetResourceType returns the resource type of the Account +func (a *Account) GetResourceType() resource.Type { + return resource.Account +} + // oplog will create oplog metadata for the Account. func (a *Account) oplog(ctx context.Context, opType oplog.OpType) (oplog.Metadata, error) { const op = "ldap.(Account).oplog" diff --git a/internal/auth/ldap/auth_method.go b/internal/auth/ldap/auth_method.go index c97ddad00..bc0affa03 100644 --- a/internal/auth/ldap/auth_method.go +++ b/internal/auth/ldap/auth_method.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/auth/ldap/store" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -112,6 +113,11 @@ func (am *AuthMethod) SetTableName(n string) { am.tableName = n } +// GetResourceType returns the resource type of the AuthMethod +func (am *AuthMethod) GetResourceType() resource.Type { + return resource.AuthMethod +} + // oplog will create oplog metadata for the AuthMethod. func (am *AuthMethod) oplog(ctx context.Context, opType oplog.OpType) (oplog.Metadata, error) { const op = "ldap.(AuthMethod).oplog" diff --git a/internal/auth/ldap/managed_group.go b/internal/auth/ldap/managed_group.go index 7f452156b..fab71a643 100644 --- a/internal/auth/ldap/managed_group.go +++ b/internal/auth/ldap/managed_group.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/boundary/internal/auth/ldap/store" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -80,6 +81,11 @@ func (mg *ManagedGroup) SetTableName(n string) { mg.tableName = n } +// GetResourceType returns the resource type of the ManagedGroup +func (mg *ManagedGroup) GetResourceType() resource.Type { + return resource.ManagedGroup +} + // oplog will create oplog metadata for the ManagedGroup. func (mg *ManagedGroup) oplog(ctx context.Context, opType oplog.OpType, authMethodScopeId string) (oplog.Metadata, error) { const op = "ldap.(ManagedGroup).oplog" diff --git a/internal/auth/oidc/account.go b/internal/auth/oidc/account.go index c5fbe507a..627778556 100644 --- a/internal/auth/oidc/account.go +++ b/internal/auth/oidc/account.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/boundary/internal/auth/oidc/store" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -115,6 +116,11 @@ func (a *Account) SetTableName(n string) { a.tableName = n } +// GetResourceType returns the resource type of the Account +func (a *Account) GetResourceType() resource.Type { + return resource.Account +} + // GetLoginName returns the login name, which will always be empty as this type // doesn't currently support login name func (a *Account) GetLoginName() string { diff --git a/internal/auth/oidc/auth_method.go b/internal/auth/oidc/auth_method.go index 5b719eb71..dd86a29f9 100644 --- a/internal/auth/oidc/auth_method.go +++ b/internal/auth/oidc/auth_method.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/libs/crypto" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" wrapping "github.com/hashicorp/go-kms-wrapping/v2" "github.com/hashicorp/go-kms-wrapping/v2/extras/structwrapping" kvbuilder "github.com/hashicorp/go-secure-stdlib/kv-builder" @@ -196,6 +197,11 @@ func (a *AuthMethod) SetTableName(n string) { a.tableName = n } +// GetResourceType returns the resource type of the AuthMethod +func (a *AuthMethod) GetResourceType() resource.Type { + return resource.AuthMethod +} + // oplog will create oplog metadata for the AuthMethod. func (a *AuthMethod) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ diff --git a/internal/auth/oidc/managed_group.go b/internal/auth/oidc/managed_group.go index af356ec95..b6b004711 100644 --- a/internal/auth/oidc/managed_group.go +++ b/internal/auth/oidc/managed_group.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/boundary/internal/auth/oidc/store" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "github.com/hashicorp/go-bexpr" "google.golang.org/protobuf/proto" ) @@ -86,6 +87,11 @@ func (mg *ManagedGroup) SetTableName(n string) { mg.tableName = n } +// GetResourceType returns the resource type of the ManagedGroup +func (mg *ManagedGroup) GetResourceType() resource.Type { + return resource.ManagedGroup +} + // oplog will create oplog metadata for the ManagedGroup. func (mg *ManagedGroup) oplog(op oplog.OpType, authMethodScopeId string) oplog.Metadata { metadata := oplog.Metadata{ diff --git a/internal/auth/password/account.go b/internal/auth/password/account.go index d02d60b9d..aa346a12b 100644 --- a/internal/auth/password/account.go +++ b/internal/auth/password/account.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/boundary/internal/auth/password/store" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -70,6 +71,11 @@ func (a *Account) SetTableName(n string) { a.tableName = n } +// GetResourceType returns the resource type of the Account +func (a *Account) GetResourceType() resource.Type { + return resource.Account +} + // GetEmail returns the email, which will always be empty as this type doesn't // currently support email func (a *Account) GetEmail() string { diff --git a/internal/auth/password/authmethod.go b/internal/auth/password/authmethod.go index 726b7e970..6aeefd6e9 100644 --- a/internal/auth/password/authmethod.go +++ b/internal/auth/password/authmethod.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/boundary/internal/auth/password/store" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -69,6 +70,11 @@ func (a *AuthMethod) SetTableName(n string) { a.tableName = n } +// GetResourceType returns the resource type of the AuthMethod +func (a *AuthMethod) GetResourceType() resource.Type { + return resource.AuthMethod +} + func (a *AuthMethod) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ "resource-public-id": []string{a.GetPublicId()}, diff --git a/internal/boundary/boundary.go b/internal/boundary/boundary.go index 271d54e38..461c8da49 100644 --- a/internal/boundary/boundary.go +++ b/internal/boundary/boundary.go @@ -7,6 +7,7 @@ package boundary import ( "github.com/hashicorp/boundary/internal/db/timestamp" + "github.com/hashicorp/boundary/internal/types/resource" ) // An Entity is an object distinguished by its identity, rather than its @@ -24,11 +25,12 @@ type Aggregate interface { GetUpdateTime() *timestamp.Timestamp } -// A Resource is an aggregate with a name and description. +// A Resource is an aggregate with a name, description, and resource type. type Resource interface { Aggregate GetName() string GetDescription() string + GetResourceType() resource.Type } // AuthzProtectedEntity is used by some functions (primarily diff --git a/internal/credential/static/credential_store.go b/internal/credential/static/credential_store.go index ba0b904a9..e4ba4e4ab 100644 --- a/internal/credential/static/credential_store.go +++ b/internal/credential/static/credential_store.go @@ -6,6 +6,7 @@ package static import ( "github.com/hashicorp/boundary/internal/credential/static/store" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -55,6 +56,11 @@ func (cs *CredentialStore) SetTableName(n string) { cs.tableName = n } +// GetResourceType returns the resource type of the CredentialStore +func (cs *CredentialStore) GetResourceType() resource.Type { + return resource.CredentialStore +} + func (cs *CredentialStore) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ "resource-public-id": []string{cs.PublicId}, diff --git a/internal/credential/static/json_credential.go b/internal/credential/static/json_credential.go index 0cabd833a..7df72c484 100644 --- a/internal/credential/static/json_credential.go +++ b/internal/credential/static/json_credential.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/libs/crypto" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" wrapping "github.com/hashicorp/go-kms-wrapping/v2" "github.com/hashicorp/go-kms-wrapping/v2/extras/structwrapping" "google.golang.org/protobuf/proto" @@ -88,6 +89,11 @@ func (c *JsonCredential) SetTableName(n string) { c.tableName = n } +// GetResourceType returns the resource type of the Credential +func (c *JsonCredential) GetResourceType() resource.Type { + return resource.Credential +} + func (c *JsonCredential) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ "resource-public-id": []string{c.PublicId}, diff --git a/internal/credential/static/ssh_private_key_credential.go b/internal/credential/static/ssh_private_key_credential.go index 5e5f995e9..6778fde30 100644 --- a/internal/credential/static/ssh_private_key_credential.go +++ b/internal/credential/static/ssh_private_key_credential.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/libs/crypto" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" wrapping "github.com/hashicorp/go-kms-wrapping/v2" "golang.org/x/crypto/ssh" "google.golang.org/protobuf/proto" @@ -105,6 +106,11 @@ func (c *SshPrivateKeyCredential) SetTableName(n string) { c.tableName = n } +// GetResourceType returns the resource type of the Credential +func (c *SshPrivateKeyCredential) GetResourceType() resource.Type { + return resource.Credential +} + func (c *SshPrivateKeyCredential) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ "resource-public-id": []string{c.PublicId}, diff --git a/internal/credential/static/usernamepassword_credential.go b/internal/credential/static/usernamepassword_credential.go index e093bdf12..55af0b4b7 100644 --- a/internal/credential/static/usernamepassword_credential.go +++ b/internal/credential/static/usernamepassword_credential.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/libs/crypto" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" wrapping "github.com/hashicorp/go-kms-wrapping/v2" "github.com/hashicorp/go-kms-wrapping/v2/extras/structwrapping" "google.golang.org/protobuf/proto" @@ -73,6 +74,11 @@ func (c *UsernamePasswordCredential) SetTableName(n string) { c.tableName = n } +// GetResourceType returns the resource type of the Credential +func (c *UsernamePasswordCredential) GetResourceType() resource.Type { + return resource.Credential +} + func (c *UsernamePasswordCredential) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ "resource-public-id": []string{c.PublicId}, diff --git a/internal/credential/vault/credential_library.go b/internal/credential/vault/credential_library.go index a599fa4b2..13d624fb7 100644 --- a/internal/credential/vault/credential_library.go +++ b/internal/credential/vault/credential_library.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/credential/vault/store" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -103,6 +104,11 @@ func (l *CredentialLibrary) SetTableName(n string) { l.tableName = n } +// GetResourceType returns the resource type of the CredentialLibrary +func (l *CredentialLibrary) GetResourceType() resource.Type { + return resource.CredentialLibrary +} + func (l *CredentialLibrary) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ "resource-public-id": []string{l.PublicId}, diff --git a/internal/credential/vault/credential_store.go b/internal/credential/vault/credential_store.go index 456313749..9b7e5001c 100644 --- a/internal/credential/vault/credential_store.go +++ b/internal/credential/vault/credential_store.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/boundary/internal/db" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -134,6 +135,11 @@ func (cs *CredentialStore) SetTableName(n string) { cs.tableName = n } +// GetResourceType returns the resource type of the CredentialStore +func (cs *CredentialStore) GetResourceType() resource.Type { + return resource.CredentialStore +} + func (cs *CredentialStore) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ "resource-public-id": []string{cs.PublicId}, diff --git a/internal/credential/vault/private_library.go b/internal/credential/vault/private_library.go index a5dc34246..c349a4b4c 100644 --- a/internal/credential/vault/private_library.go +++ b/internal/credential/vault/private_library.go @@ -28,6 +28,7 @@ import ( "github.com/hashicorp/boundary/internal/db/timestamp" "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/kms" + "github.com/hashicorp/boundary/internal/types/resource" "github.com/hashicorp/boundary/internal/util/template" wrapping "github.com/hashicorp/go-kms-wrapping/v2" "github.com/hashicorp/go-kms-wrapping/v2/extras/structwrapping" @@ -269,6 +270,11 @@ func (pl *genericIssuingCredentialLibrary) CredentialType() globals.CredentialTy } } +// GetResourceType returns the resource type of the CredentialLibrary +func (pl *genericIssuingCredentialLibrary) GetResourceType() resource.Type { + return resource.CredentialLibrary +} + func (pl *genericIssuingCredentialLibrary) client(ctx context.Context) (vaultClient, error) { const op = "vault.(genericIssuingCredentialLibrary).client" clientConfig := &clientConfig{ @@ -496,6 +502,11 @@ type privateCredentialLibraryAllTypes struct { func (pl *privateCredentialLibraryAllTypes) GetPublicId() string { return pl.PublicId } +// GetResourceType returns the resource type of the CredentialLibrary +func (pl *privateCredentialLibraryAllTypes) GetResourceType() resource.Type { + return resource.CredentialLibrary +} + func (pl *privateCredentialLibraryAllTypes) decrypt(ctx context.Context, cipher wrapping.Wrapper) error { const op = "vault.(privateCredentialLibraryAllTypes).decrypt" @@ -754,6 +765,11 @@ func (lib *sshCertIssuingCredentialLibrary) CredentialType() globals.CredentialT } } +// GetResourceType returns the resource type of the CredentialLibrary +func (lib *sshCertIssuingCredentialLibrary) GetResourceType() resource.Type { + return resource.CredentialLibrary +} + func (lib *sshCertIssuingCredentialLibrary) client(ctx context.Context) (vaultClient, error) { const op = "vault.(genericIssuingCredentialLibrary).client" clientConfig := &clientConfig{ diff --git a/internal/credential/vault/ssh_certificate_credential_library.go b/internal/credential/vault/ssh_certificate_credential_library.go index a40cd5e3e..4816dcb3a 100644 --- a/internal/credential/vault/ssh_certificate_credential_library.go +++ b/internal/credential/vault/ssh_certificate_credential_library.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/boundary/internal/credential" "github.com/hashicorp/boundary/internal/credential/vault/store" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -96,6 +97,11 @@ func (l *SSHCertificateCredentialLibrary) SetTableName(n string) { l.tableName = n } +// GetResourceType returns the resource type of the CredentialLibrary +func (l *SSHCertificateCredentialLibrary) GetResourceType() resource.Type { + return resource.CredentialLibrary +} + func (l *SSHCertificateCredentialLibrary) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ "resource-public-id": []string{l.PublicId}, diff --git a/internal/host/plugin/host.go b/internal/host/plugin/host.go index 9dc238715..c42e32cb9 100644 --- a/internal/host/plugin/host.go +++ b/internal/host/plugin/host.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/boundary/internal/event" "github.com/hashicorp/boundary/internal/host/plugin/store" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "github.com/hashicorp/go-secure-stdlib/strutil" "google.golang.org/protobuf/proto" ) @@ -90,6 +91,11 @@ func (s *Host) SetTableName(n string) { s.tableName = n } +// GetResourceType returns the resource type of the Host +func (s *Host) GetResourceType() resource.Type { + return resource.Host +} + func allocHost() *Host { return &Host{ Host: &store.Host{}, diff --git a/internal/host/plugin/host_catalog.go b/internal/host/plugin/host_catalog.go index 0cbe5e4af..a4713a49a 100644 --- a/internal/host/plugin/host_catalog.go +++ b/internal/host/plugin/host_catalog.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/boundary/internal/host/plugin/store" "github.com/hashicorp/boundary/internal/libs/crypto" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" wrapping "github.com/hashicorp/go-kms-wrapping/v2" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/structpb" @@ -122,14 +123,19 @@ func (c *HostCatalog) SetTableName(n string) { c.tableName = n } -func (s *HostCatalog) oplog(op oplog.OpType) oplog.Metadata { +// GetResourceType returns the resource type of the HostCatalog +func (c *HostCatalog) GetResourceType() resource.Type { + return resource.HostCatalog +} + +func (c *HostCatalog) oplog(op oplog.OpType) oplog.Metadata { metadata := oplog.Metadata{ - "resource-public-id": []string{s.PublicId}, + "resource-public-id": []string{c.PublicId}, "resource-type": []string{"plugin-host-catalog"}, "op-type": []string{op.String()}, } - if s.ProjectId != "" { - metadata["project-id"] = []string{s.ProjectId} + if c.ProjectId != "" { + metadata["project-id"] = []string{c.ProjectId} } return metadata } diff --git a/internal/host/plugin/host_set.go b/internal/host/plugin/host_set.go index 1ccbab1a1..252c23c71 100644 --- a/internal/host/plugin/host_set.go +++ b/internal/host/plugin/host_set.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/host/plugin/store" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -65,6 +66,11 @@ func (s *HostSet) SetTableName(n string) { s.tableName = n } +// GetResourceType returns the resource type of the HostSet +func (s *HostSet) GetResourceType() resource.Type { + return resource.HostSet +} + func allocHostSet() *HostSet { return &HostSet{ HostSet: &store.HostSet{}, diff --git a/internal/host/static/host.go b/internal/host/static/host.go index e4882ccbd..7b967944b 100644 --- a/internal/host/static/host.go +++ b/internal/host/static/host.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/host/static/store" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -71,6 +72,11 @@ func (h *Host) SetTableName(n string) { h.tableName = n } +// GetResourceType returns the resource type of the Host +func (h *Host) GetResourceType() resource.Type { + return resource.Host +} + func allocHost() *Host { return &Host{ Host: &store.Host{}, diff --git a/internal/host/static/host_catalog.go b/internal/host/static/host_catalog.go index 79b20f7c5..94a3c0ee0 100644 --- a/internal/host/static/host_catalog.go +++ b/internal/host/static/host_catalog.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/host/static/store" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -59,6 +60,11 @@ func (c *HostCatalog) SetTableName(n string) { c.tableName = n } +// GetResourceType returns the resource type of the HostCatalog +func (c *HostCatalog) GetResourceType() resource.Type { + return resource.HostCatalog +} + func allocCatalog() *HostCatalog { fresh := &HostCatalog{ HostCatalog: &store.HostCatalog{}, diff --git a/internal/host/static/host_set.go b/internal/host/static/host_set.go index c82a69f68..b88f96503 100644 --- a/internal/host/static/host_set.go +++ b/internal/host/static/host_set.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/host/static/store" "github.com/hashicorp/boundary/internal/oplog" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -51,6 +52,11 @@ func (s *HostSet) SetTableName(n string) { s.tableName = n } +// GetResourceType returns the resource type of the HostSet +func (s *HostSet) GetResourceType() resource.Type { + return resource.HostSet +} + func allocHostSet() *HostSet { return &HostSet{ HostSet: &store.HostSet{}, diff --git a/internal/iam/group.go b/internal/iam/group.go index ffc43ecce..34eee094d 100644 --- a/internal/iam/group.go +++ b/internal/iam/group.go @@ -86,8 +86,8 @@ func (g *Group) GetScope(ctx context.Context, r db.Reader) (*Scope, error) { return LookupScope(ctx, r, g) } -// ResourceType returns the type of the Group. -func (*Group) ResourceType() resource.Type { return resource.Group } +// GetResourceType returns the type of the Group. +func (*Group) GetResourceType() resource.Type { return resource.Group } // Actions returns the available actions for Group func (*Group) Actions() map[string]action.Type { diff --git a/internal/iam/group_test.go b/internal/iam/group_test.go index 890e55559..d07cc5b43 100644 --- a/internal/iam/group_test.go +++ b/internal/iam/group_test.go @@ -453,7 +453,7 @@ func TestGroup_Actions(t *testing.T) { func TestGroup_ResourceType(t *testing.T) { assert := assert.New(t) r := &Group{} - ty := r.ResourceType() + ty := r.GetResourceType() assert.Equal(ty, resource.Group) } diff --git a/internal/iam/repository.go b/internal/iam/repository.go index db41ac4e9..dd176fd97 100644 --- a/internal/iam/repository.go +++ b/internal/iam/repository.go @@ -259,14 +259,14 @@ func (r *Repository) stdMetadata(ctx context.Context, resource Resource) (oplog. "resource-public-id": []string{resource.GetPublicId()}, "scope-id": []string{newScope.PublicId}, "scope-type": []string{newScope.Type}, - "resource-type": []string{resource.ResourceType().String()}, + "resource-type": []string{resource.GetResourceType().String()}, }, nil case scope.Project.String(): return oplog.Metadata{ "resource-public-id": []string{resource.GetPublicId()}, "scope-id": []string{newScope.ParentId}, "scope-type": []string{newScope.Type}, - "resource-type": []string{resource.ResourceType().String()}, + "resource-type": []string{resource.GetResourceType().String()}, }, nil default: return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("not a supported scope for metadata: %s", s.Type)) @@ -284,7 +284,7 @@ func (r *Repository) stdMetadata(ctx context.Context, resource Resource) (oplog. "resource-public-id": []string{resource.GetPublicId()}, "scope-id": []string{scope.PublicId}, "scope-type": []string{scope.Type}, - "resource-type": []string{resource.ResourceType().String()}, + "resource-type": []string{resource.GetResourceType().String()}, }, nil } diff --git a/internal/iam/resource.go b/internal/iam/resource.go index d7e2e39e5..11590231d 100644 --- a/internal/iam/resource.go +++ b/internal/iam/resource.go @@ -33,7 +33,7 @@ type Resource interface { GetScope(ctx context.Context, r db.Reader) (*Scope, error) // Type of Resource (Target, Policy, User, Group, etc) - ResourceType() resource.Type + GetResourceType() resource.Type // Actions that can be assigned permissions for // the Resource in Policies. Action String() is key for diff --git a/internal/iam/role.go b/internal/iam/role.go index 39f22872f..453a9b9ab 100644 --- a/internal/iam/role.go +++ b/internal/iam/role.go @@ -86,8 +86,8 @@ func (role *Role) GetScope(ctx context.Context, r db.Reader) (*Scope, error) { return LookupScope(ctx, r, role) } -// ResourceType returns the type of the Role. -func (*Role) ResourceType() resource.Type { return resource.Role } +// GetResourceType returns the type of the Role. +func (*Role) GetResourceType() resource.Type { return resource.Role } // Actions returns the available actions for Role. func (*Role) Actions() map[string]action.Type { diff --git a/internal/iam/role_test.go b/internal/iam/role_test.go index 4918cc8e7..29d90961a 100644 --- a/internal/iam/role_test.go +++ b/internal/iam/role_test.go @@ -558,7 +558,7 @@ func TestRole_Actions(t *testing.T) { func TestRole_ResourceType(t *testing.T) { assert := assert.New(t) r := &Role{} - ty := r.ResourceType() + ty := r.GetResourceType() assert.Equal(ty, resource.Role) } diff --git a/internal/iam/scope.go b/internal/iam/scope.go index aa45f1316..cef27dadc 100644 --- a/internal/iam/scope.go +++ b/internal/iam/scope.go @@ -150,8 +150,8 @@ func (s *Scope) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType, return nil } -// ResourceType returns the type of scope -func (s *Scope) ResourceType() resource.Type { +// GetResourceType returns the type of scope +func (s *Scope) GetResourceType() resource.Type { return resource.Scope } diff --git a/internal/iam/scope_test.go b/internal/iam/scope_test.go index 42b9e6b3b..6276c8a6e 100644 --- a/internal/iam/scope_test.go +++ b/internal/iam/scope_test.go @@ -175,7 +175,7 @@ func TestScope_Actions(t *testing.T) { func TestScope_ResourceType(t *testing.T) { o, err := NewOrg(context.Background()) require.NoError(t, err) - assert.Equal(t, o.ResourceType(), resource.Scope) + assert.Equal(t, o.GetResourceType(), resource.Scope) assert.Equal(t, o.GetParentId(), scope.Global.String()) } diff --git a/internal/iam/user.go b/internal/iam/user.go index 514da7f86..45e2658e0 100644 --- a/internal/iam/user.go +++ b/internal/iam/user.go @@ -89,8 +89,8 @@ func (u *User) GetScope(ctx context.Context, r db.Reader) (*Scope, error) { return LookupScope(ctx, r, u) } -// ResourceType returns the type of the User -func (*User) ResourceType() resource.Type { return resource.User } +// GetResourceType returns the type of the User +func (*User) GetResourceType() resource.Type { return resource.User } // Actions returns the available actions for Users func (*User) Actions() map[string]action.Type { diff --git a/internal/iam/user_test.go b/internal/iam/user_test.go index 21e1ad0af..731d545f0 100644 --- a/internal/iam/user_test.go +++ b/internal/iam/user_test.go @@ -389,7 +389,7 @@ func TestUser_Actions(t *testing.T) { func TestUser_ResourceType(t *testing.T) { t.Parallel() u := AllocUser() - assert.Equal(t, resource.User, u.ResourceType()) + assert.Equal(t, resource.User, u.GetResourceType()) } func TestUser_SetTableName(t *testing.T) { diff --git a/internal/target/target.go b/internal/target/target.go index 255fb53e3..0554d9abb 100644 --- a/internal/target/target.go +++ b/internal/target/target.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/boundary/internal/errors" "github.com/hashicorp/boundary/internal/oplog" "github.com/hashicorp/boundary/internal/target/store" + "github.com/hashicorp/boundary/internal/types/resource" ) // Target is a commmon interface for all target subtypes @@ -26,6 +27,7 @@ type Target interface { GetDescription() string GetVersion() uint32 GetType() globals.Subtype + GetResourceType() resource.Type GetCreateTime() *timestamp.Timestamp GetUpdateTime() *timestamp.Timestamp GetSessionMaxSeconds() uint32 @@ -108,6 +110,11 @@ func (t *targetView) SetTableName(n string) { } } +// GetResourceType returns the resource type of the Target +func (t *targetView) GetResourceType() resource.Type { + return resource.Target +} + func (t *targetView) SetHostSources(hs []HostSource) { t.HostSource = hs } diff --git a/internal/target/targettest/target.go b/internal/target/targettest/target.go index 0a1b70e78..eade3ec22 100644 --- a/internal/target/targettest/target.go +++ b/internal/target/targettest/target.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/boundary/internal/oplog" "github.com/hashicorp/boundary/internal/target" "github.com/hashicorp/boundary/internal/target/targettest/store" + "github.com/hashicorp/boundary/internal/types/resource" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" ) @@ -181,6 +182,11 @@ func (t *Target) SetDescription(description string) { t.Description = description } +// GetResourceType returns the resource type of the Target +func (t *Target) GetResourceType() resource.Type { + return resource.Target +} + func (t *Target) SetVersion(v uint32) { t.Version = v } diff --git a/internal/target/tcp/target.go b/internal/target/tcp/target.go index 3257bffaf..f9dce1755 100644 --- a/internal/target/tcp/target.go +++ b/internal/target/tcp/target.go @@ -18,6 +18,7 @@ import ( "github.com/hashicorp/boundary/internal/oplog" "github.com/hashicorp/boundary/internal/target" "github.com/hashicorp/boundary/internal/target/tcp/store" + "github.com/hashicorp/boundary/internal/types/resource" "google.golang.org/protobuf/proto" ) @@ -178,6 +179,11 @@ func (t *Target) SetDescription(description string) { t.Description = description } +// GetResourceType returns the resource type of the Target +func (t *Target) GetResourceType() resource.Type { + return resource.Target +} + func (t *Target) SetVersion(v uint32) { t.Version = v }