Remove some unneeded resource types and fix the resource typing for default role in global scope (#256)
This commit is contained in:
1 parent
4cfab04307
commit
73a38b1433
16 files changed
+47
-139
No files matched your search
@@ -175,13 +175,6 @@ func TestHandler_AuthDecoration(t *testing.T) {
|
||||
resource: resource.Scope,
|
||||
id: "o_1234",
|
||||
},
|
||||
{
|
||||
name: "org scope, get on collection is list",
|
||||
path: "/v1/scopes/o_abc123/projects",
|
||||
action: action.List,
|
||||
scope: "o_abc123",
|
||||
resource: resource.Project,
|
||||
},
|
||||
{
|
||||
name: "global action, valid",
|
||||
path: "/v1/scopes/global/:read",
|
||||
|
||||
@@ -957,7 +957,7 @@ insert into iam_role (public_id, name, description, scope_id)
|
||||
values('r_default', 'default', 'default role', 'global');
|
||||
|
||||
insert into iam_role_grant (role_id, canonical_grant, raw_grant)
|
||||
values('r_default', 'type=org;actions=list', 'type=org;actions=list');
|
||||
values('r_default', 'type=scope;actions=list', 'type=scope;actions=list');
|
||||
|
||||
create table iam_group (
|
||||
public_id wt_public_id not null primary key,
|
||||
|
||||
@@ -451,7 +451,7 @@ insert into iam_role (public_id, name, description, scope_id)
|
||||
values('r_default', 'default', 'default role', 'global');
|
||||
|
||||
insert into iam_role_grant (role_id, canonical_grant, raw_grant)
|
||||
values('r_default', 'type=org;actions=list', 'type=org;actions=list');
|
||||
values('r_default', 'type=scope;actions=list', 'type=scope;actions=list');
|
||||
|
||||
create table iam_group (
|
||||
public_id wt_public_id not null primary key,
|
||||
|
||||
@@ -52,7 +52,7 @@ func (a *authAccount) VetForWrite(ctx context.Context, r db.Reader, opType db.Op
|
||||
}
|
||||
|
||||
func (a *authAccount) validScopeTypes() []scope.Type {
|
||||
return []scope.Type{scope.Org}
|
||||
return []scope.Type{scope.Global, scope.Org}
|
||||
}
|
||||
|
||||
// GetScope returns the scope for the auth account.
|
||||
|
||||
@@ -71,7 +71,7 @@ func (g *Group) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType,
|
||||
}
|
||||
|
||||
func (u *Group) validScopeTypes() []scope.Type {
|
||||
return []scope.Type{scope.Org, scope.Project}
|
||||
return []scope.Type{scope.Global, scope.Org, scope.Project}
|
||||
}
|
||||
|
||||
// GetScope returns the scope for the Group.
|
||||
|
||||
@@ -72,7 +72,7 @@ func (role *Role) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType
|
||||
}
|
||||
|
||||
func (u *Role) validScopeTypes() []scope.Type {
|
||||
return []scope.Type{scope.Org, scope.Project}
|
||||
return []scope.Type{scope.Global, scope.Org, scope.Project}
|
||||
}
|
||||
|
||||
// Getscope returns the scope for the Role.
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/iam/store"
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -87,9 +86,6 @@ func (g *RoleGrant) VetForWrite(ctx context.Context, r db.Reader, opType db.OpTy
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResourceType returns the type of the RoleGrant
|
||||
func (*RoleGrant) ResourceType() resource.Type { return resource.RoleGrant }
|
||||
|
||||
// TableName returns the tablename to override the default gorm table name
|
||||
func (g *RoleGrant) TableName() string {
|
||||
if g.tableName != "" {
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"github.com/hashicorp/boundary/internal/db"
|
||||
"github.com/hashicorp/boundary/internal/iam/store"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -216,13 +215,6 @@ func TestRoleGrant_Delete(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRoleGrant_ResourceType(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
r := &RoleGrant{}
|
||||
ty := r.ResourceType()
|
||||
assert.Equal(ty, resource.RoleGrant)
|
||||
}
|
||||
|
||||
func TestRoleGrant_Clone(t *testing.T) {
|
||||
t.Parallel()
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
|
||||
@@ -165,7 +165,7 @@ func TestScope_ResourceType(t *testing.T) {
|
||||
o, err := NewOrg()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, o.ResourceType(), resource.Scope)
|
||||
assert.Equal(t, o.GetParentId(), resource.Global.String())
|
||||
assert.Equal(t, o.GetParentId(), scope.Global.String())
|
||||
}
|
||||
|
||||
func TestScope_Clone(t *testing.T) {
|
||||
|
||||
@@ -72,7 +72,7 @@ func (u *User) VetForWrite(ctx context.Context, r db.Reader, opType db.OpType, o
|
||||
}
|
||||
|
||||
func (u *User) validScopeTypes() []scope.Type {
|
||||
return []scope.Type{scope.Org}
|
||||
return []scope.Type{scope.Global, scope.Org}
|
||||
}
|
||||
|
||||
// GetScope returns the scope for the User
|
||||
|
||||
@@ -124,18 +124,6 @@ func Test_UserCreate(t *testing.T) {
|
||||
require.Error(err)
|
||||
assert.Equal("create: vet for write failed: scope is not found", err.Error())
|
||||
})
|
||||
t.Run("bad-scope", func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
w := db.New(conn)
|
||||
user, err := NewUser("global")
|
||||
require.NoError(err)
|
||||
id, err := newUserId()
|
||||
require.NoError(err)
|
||||
user.PublicId = id
|
||||
err = w.Create(context.Background(), user)
|
||||
require.Error(err)
|
||||
assert.Equal("create: vet for write failed: global not a valid scope type for this resource", err.Error())
|
||||
})
|
||||
}
|
||||
|
||||
func Test_UserUpdate(t *testing.T) {
|
||||
|
||||
@@ -298,14 +298,15 @@ func (g Grant) validateType() error {
|
||||
switch g.typ {
|
||||
case resource.Unknown,
|
||||
resource.All,
|
||||
resource.Role,
|
||||
resource.Group,
|
||||
resource.Scope,
|
||||
resource.User,
|
||||
resource.Group,
|
||||
resource.Role,
|
||||
resource.AuthMethod,
|
||||
resource.Account,
|
||||
resource.HostCatalog,
|
||||
resource.HostSet,
|
||||
resource.Host,
|
||||
resource.Org,
|
||||
resource.Target:
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -104,13 +104,6 @@ func Test_ValidateType(t *testing.T) {
|
||||
{
|
||||
name: "no specifier",
|
||||
},
|
||||
{
|
||||
name: "unknown specifier",
|
||||
input: Grant{
|
||||
typ: resource.RoleGrant,
|
||||
},
|
||||
errResult: `unknown type specifier "role-grant"`,
|
||||
},
|
||||
{
|
||||
name: "valid specifier",
|
||||
input: Grant{
|
||||
|
||||
@@ -51,10 +51,7 @@ var _ pbs.ScopeServiceServer = Service{}
|
||||
// ListScopes implements the interface pbs.ScopeServiceServer.
|
||||
func (s Service) ListScopes(ctx context.Context, req *pbs.ListScopesRequest) (*pbs.ListScopesResponse, error) {
|
||||
if req.GetScopeId() == "" {
|
||||
return nil, handlers.InvalidArgumentErrorf(
|
||||
"Argument errors found in the request.",
|
||||
map[string]string{"scope_id": "Missing value for scope_id"},
|
||||
)
|
||||
req.ScopeId = scope.Global.String()
|
||||
}
|
||||
authResults := auth.Verify(ctx, auth.WithScopeId(req.GetScopeId()))
|
||||
if !authResults.Valid {
|
||||
|
||||
@@ -4,75 +4,51 @@ package resource
|
||||
type Type int
|
||||
|
||||
const (
|
||||
Unknown Type = 0
|
||||
Scope Type = 1
|
||||
User Type = 2
|
||||
Group Type = 3
|
||||
Role Type = 4
|
||||
Org Type = 5
|
||||
GroupMember Type = 6
|
||||
GroupUserMember Type = 7
|
||||
AssignedRole Type = 8
|
||||
AssignedUserRole Type = 9
|
||||
AssignedGroupRole Type = 10
|
||||
RoleGrant Type = 11
|
||||
AuthMethod Type = 12
|
||||
Project Type = 13
|
||||
All Type = 14
|
||||
HostCatalog Type = 15
|
||||
HostSet Type = 16
|
||||
Host Type = 17
|
||||
Target Type = 18
|
||||
Global Type = 19
|
||||
AuthToken Type = 20
|
||||
Unknown Type = 0
|
||||
All Type = 1
|
||||
Scope Type = 2
|
||||
User Type = 3
|
||||
Group Type = 4
|
||||
Role Type = 5
|
||||
AuthMethod Type = 6
|
||||
Account Type = 7
|
||||
AuthToken Type = 8
|
||||
HostCatalog Type = 9
|
||||
HostSet Type = 10
|
||||
Host Type = 11
|
||||
Target Type = 12
|
||||
)
|
||||
|
||||
func (r Type) String() string {
|
||||
return [...]string{
|
||||
"unknown",
|
||||
"*",
|
||||
"scope",
|
||||
"user",
|
||||
"group",
|
||||
"role",
|
||||
"org",
|
||||
"group-member",
|
||||
"group-user-member",
|
||||
"assigned-role",
|
||||
"assigned-user-role",
|
||||
"assigned-group-role",
|
||||
"role-grant",
|
||||
"auth-method",
|
||||
"project",
|
||||
"*",
|
||||
"account",
|
||||
"auth-token",
|
||||
"host-catalog",
|
||||
"host-set",
|
||||
"host",
|
||||
"target",
|
||||
"global",
|
||||
"auth-token",
|
||||
}[r]
|
||||
}
|
||||
|
||||
var Map = map[string]Type{
|
||||
Scope.String(): Scope,
|
||||
User.String(): User,
|
||||
Group.String(): Group,
|
||||
Role.String(): Role,
|
||||
Org.String(): Org,
|
||||
GroupMember.String(): GroupMember,
|
||||
GroupUserMember.String(): GroupUserMember,
|
||||
AssignedRole.String(): AssignedRole,
|
||||
AssignedUserRole.String(): AssignedUserRole,
|
||||
AssignedGroupRole.String(): AssignedGroupRole,
|
||||
RoleGrant.String(): RoleGrant,
|
||||
AuthMethod.String(): AuthMethod,
|
||||
Project.String(): Project,
|
||||
All.String(): All,
|
||||
HostCatalog.String(): HostCatalog,
|
||||
HostSet.String(): HostSet,
|
||||
Host.String(): Host,
|
||||
Target.String(): Target,
|
||||
Global.String(): Global,
|
||||
Group.String(): Group,
|
||||
AuthToken.String(): AuthToken,
|
||||
Unknown.String(): Unknown,
|
||||
All.String(): All,
|
||||
Scope.String(): Scope,
|
||||
User.String(): User,
|
||||
Group.String(): Group,
|
||||
Role.String(): Role,
|
||||
AuthMethod.String(): AuthMethod,
|
||||
Account.String(): Account,
|
||||
AuthToken.String(): AuthToken,
|
||||
HostCatalog.String(): HostCatalog,
|
||||
HostSet.String(): HostSet,
|
||||
Host.String(): Host,
|
||||
Target.String(): Target,
|
||||
}
|
||||
@@ -32,41 +32,17 @@ func Test_Resource(t *testing.T) {
|
||||
typeString: "role",
|
||||
want: Role,
|
||||
},
|
||||
{
|
||||
typeString: "org",
|
||||
want: Org,
|
||||
},
|
||||
{
|
||||
typeString: "group-member",
|
||||
want: GroupMember,
|
||||
},
|
||||
{
|
||||
typeString: "group-user-member",
|
||||
want: GroupUserMember,
|
||||
},
|
||||
{
|
||||
typeString: "assigned-role",
|
||||
want: AssignedRole,
|
||||
},
|
||||
{
|
||||
typeString: "assigned-user-role",
|
||||
want: AssignedUserRole,
|
||||
},
|
||||
{
|
||||
typeString: "assigned-group-role",
|
||||
want: AssignedGroupRole,
|
||||
},
|
||||
{
|
||||
typeString: "role-grant",
|
||||
want: RoleGrant,
|
||||
},
|
||||
{
|
||||
typeString: "auth-method",
|
||||
want: AuthMethod,
|
||||
},
|
||||
{
|
||||
typeString: "project",
|
||||
want: Project,
|
||||
typeString: "account",
|
||||
want: Account,
|
||||
},
|
||||
{
|
||||
typeString: "auth-token",
|
||||
want: AuthToken,
|
||||
},
|
||||
{
|
||||
typeString: "*",
|
||||
@@ -88,10 +64,6 @@ func Test_Resource(t *testing.T) {
|
||||
typeString: "target",
|
||||
want: Target,
|
||||
},
|
||||
{
|
||||
typeString: "global",
|
||||
want: Global,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.typeString, func(t *testing.T) {
|
||||
|
||||
Reference in new issue
Block a user