Skip to content

Commit

Permalink
feature(resource): support role collection update
Browse files Browse the repository at this point in the history
Add support for update operation to role collection facade and resources

Also: Fix error message when adding roles to role-collection

Resolves #86
Resolves #99
Resolves #102
  • Loading branch information
kuntzed committed Jul 18, 2023
1 parent 23b00bb commit ade282c
Show file tree
Hide file tree
Showing 20 changed files with 8,436 additions and 1,269 deletions.
24 changes: 24 additions & 0 deletions internal/btpcli/facade_security_role_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ func (f *securityRoleCollectionFacade) CreateByGlobalAccount(ctx context.Context
}))
}

func (f *securityRoleCollectionFacade) UpdateByGlobalAccount(ctx context.Context, roleCollectionName string, description string) (xsuaa_authz.RoleCollection, CommandResponse, error) {
return doExecute[xsuaa_authz.RoleCollection](f.cliClient, ctx, NewUpdateRequest(f.getCommand(), map[string]string{
"globalAccount": f.cliClient.GetGlobalAccountSubdomain(),
"roleCollectionName": roleCollectionName,
"description": description,
}))
}

func (f *securityRoleCollectionFacade) DeleteByGlobalAccount(ctx context.Context, roleCollectionName string) (xsuaa_authz.RoleCollection, CommandResponse, error) {
return doExecute[xsuaa_authz.RoleCollection](f.cliClient, ctx, NewDeleteRequest(f.getCommand(), map[string]string{
"globalAccount": f.cliClient.GetGlobalAccountSubdomain(),
Expand Down Expand Up @@ -67,6 +75,14 @@ func (f *securityRoleCollectionFacade) CreateBySubaccount(ctx context.Context, s
}))
}

func (f *securityRoleCollectionFacade) UpdateBySubaccount(ctx context.Context, subaccountId string, roleCollectionName string, description string) (xsuaa_authz.RoleCollection, CommandResponse, error) {
return doExecute[xsuaa_authz.RoleCollection](f.cliClient, ctx, NewUpdateRequest(f.getCommand(), map[string]string{
"subaccount": subaccountId,
"roleCollectionName": roleCollectionName,
"description": description,
}))
}

func (f *securityRoleCollectionFacade) DeleteBySubaccount(ctx context.Context, subaccountId string, roleCollectionName string) (xsuaa_authz.RoleCollection, CommandResponse, error) {
return doExecute[xsuaa_authz.RoleCollection](f.cliClient, ctx, NewDeleteRequest(f.getCommand(), map[string]string{
"subaccount": subaccountId,
Expand Down Expand Up @@ -95,6 +111,14 @@ func (f *securityRoleCollectionFacade) CreateByDirectory(ctx context.Context, di
}))
}

func (f *securityRoleCollectionFacade) UpdateByDirectory(ctx context.Context, directoryId string, roleCollectionName string, description string) (xsuaa_authz.RoleCollection, CommandResponse, error) {
return doExecute[xsuaa_authz.RoleCollection](f.cliClient, ctx, NewUpdateRequest(f.getCommand(), map[string]string{
"directory": directoryId,
"roleCollectionName": roleCollectionName,
"description": description,
}))
}

func (f *securityRoleCollectionFacade) DeleteByDirectory(ctx context.Context, directoryId string, roleCollectionName string) (xsuaa_authz.RoleCollection, CommandResponse, error) {
return doExecute[xsuaa_authz.RoleCollection](f.cliClient, ctx, NewDeleteRequest(f.getCommand(), map[string]string{
"directory": directoryId,
Expand Down
86 changes: 86 additions & 0 deletions internal/btpcli/facade_security_role_collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,92 @@ func TestSecurityRoleCollectionFacade_CreateByDirectory(t *testing.T) {
})
}

func TestSecurityRoleCollectionFacade_UpdateByGlobalAccount(t *testing.T) {
command := "security/role-collection"

roleCollectionName := "my own rolecollection"
description := "This is the updated description of my own rolecollection"

t.Run("constructs the CLI params correctly", func(t *testing.T) {
var srvCalled bool

uut, srv := prepareClientFacadeForTest(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srvCalled = true

assertCall(t, r, command, ActionUpdate, map[string]string{
"globalAccount": "795b53bb-a3f0-4769-adf0-26173282a975",
"roleCollectionName": roleCollectionName,
"description": description,
})
}))
defer srv.Close()

_, res, err := uut.Security.RoleCollection.UpdateByGlobalAccount(context.TODO(), roleCollectionName, description)

if assert.True(t, srvCalled) && assert.NoError(t, err) {
assert.Equal(t, 200, res.StatusCode)
}
})
}

func TestSecurityRoleCollectionFacade_UpdateBySubaccount(t *testing.T) {
command := "security/role-collection"

subaccountId := "6aa64c2f-38c1-49a9-b2e8-cf9fea769b7f"
roleCollectionName := "my own rolecollection"
description := "This is the updated description of my own rolecollection"

t.Run("constructs the CLI params correctly", func(t *testing.T) {
var srvCalled bool

uut, srv := prepareClientFacadeForTest(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srvCalled = true

assertCall(t, r, command, ActionUpdate, map[string]string{
"subaccount": subaccountId,
"roleCollectionName": roleCollectionName,
"description": description,
})
}))
defer srv.Close()

_, res, err := uut.Security.RoleCollection.UpdateBySubaccount(context.TODO(), subaccountId, roleCollectionName, description)

if assert.True(t, srvCalled) && assert.NoError(t, err) {
assert.Equal(t, 200, res.StatusCode)
}
})
}

func TestSecurityRoleCollectionFacade_UpdateByDirectory(t *testing.T) {
command := "security/role-collection"

directoryId := "6aa64c2f-38c1-49a9-b2e8-cf9fea769b7f"
roleCollectionName := "my own rolecollection"
description := "This is the updated description of my own rolecollection"

t.Run("constructs the CLI params correctly", func(t *testing.T) {
var srvCalled bool

uut, srv := prepareClientFacadeForTest(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
srvCalled = true

assertCall(t, r, command, ActionUpdate, map[string]string{
"directory": directoryId,
"roleCollectionName": roleCollectionName,
"description": description,
})
}))
defer srv.Close()

_, res, err := uut.Security.RoleCollection.UpdateByDirectory(context.TODO(), directoryId, roleCollectionName, description)

if assert.True(t, srvCalled) && assert.NoError(t, err) {
assert.Equal(t, 200, res.StatusCode)
}
})
}

func TestSecurityRoleCollectionFacade_DeleteByGlobalAccount(t *testing.T) {
command := "security/role-collection"

Expand Down
Loading

0 comments on commit ade282c

Please sign in to comment.