Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resource): support role collection update #299

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading