diff --git a/api/cloudcontroller/ccv3/constant/role_type.go b/api/cloudcontroller/ccv3/constant/role_type.go index 117140b9b02..70d3a599478 100644 --- a/api/cloudcontroller/ccv3/constant/role_type.go +++ b/api/cloudcontroller/ccv3/constant/role_type.go @@ -11,4 +11,5 @@ const ( SpaceDeveloperRole RoleType = "space_developer" SpaceAuditorRole RoleType = "space_auditor" SpaceManagerRole RoleType = "space_manager" + SpaceSupporterRole RoleType = "space_supporter" ) diff --git a/command/flag/space_role.go b/command/flag/space_role.go index 1216f0b3dd1..85d9c063fcd 100644 --- a/command/flag/space_role.go +++ b/command/flag/space_role.go @@ -22,10 +22,12 @@ func (s *SpaceRole) UnmarshalFlag(val string) error { s.Role = "SpaceDeveloper" case "spacemanager": s.Role = "SpaceManager" + case "spacesupporter": + s.Role = "SpaceSupporter" default: return &flags.Error{ Type: flags.ErrRequired, - Message: `ROLE must be "SpaceManager", "SpaceDeveloper" and "SpaceAuditor"`, + Message: `ROLE must be "SpaceManager", "SpaceDeveloper", "SpaceAuditor" or "SpaceSupporter"`, } } diff --git a/command/flag/space_role_test.go b/command/flag/space_role_test.go index 5c3108638d3..97f0bea9a3b 100644 --- a/command/flag/space_role_test.go +++ b/command/flag/space_role_test.go @@ -59,11 +59,17 @@ var _ = Describe("SpaceRole", func() { Expect(spaceRole).To(Equal(SpaceRole{Role: "SpaceAuditor"})) }) + It("accepts SpaceSupporter", func() { + err := spaceRole.UnmarshalFlag("spaceSupporter") + Expect(err).ToNot(HaveOccurred()) + Expect(spaceRole).To(Equal(SpaceRole{Role: "SpaceSupporter"})) + }) + It("errors on anything else", func() { err := spaceRole.UnmarshalFlag("I AM A BANANANANANANANANA") Expect(err).To(MatchError(&flags.Error{ Type: flags.ErrRequired, - Message: `ROLE must be "SpaceManager", "SpaceDeveloper" and "SpaceAuditor"`, + Message: `ROLE must be "SpaceManager", "SpaceDeveloper", "SpaceAuditor" or "SpaceSupporter"`, })) Expect(spaceRole.Role).To(BeEmpty()) }) diff --git a/command/v7/set_space_role_command.go b/command/v7/set_space_role_command.go index b3ff564cbc8..f23d45b853b 100644 --- a/command/v7/set_space_role_command.go +++ b/command/v7/set_space_role_command.go @@ -1,6 +1,8 @@ package v7 import ( + "strings" + "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" "code.cloudfoundry.org/cli/cf/errors" @@ -14,7 +16,7 @@ type SetSpaceRoleCommand struct { Args flag.SpaceRoleArgs `positional-args:"yes"` IsClient bool `long:"client" description:"Assign a space role to a client-id of a (non-user) service account"` Origin string `long:"origin" description:"Indicates the identity provider to be used for authentication"` - usage interface{} `usage:"CF_NAME set-space-role USERNAME ORG SPACE ROLE\n CF_NAME set-space-role USERNAME ORG SPACE ROLE [--client]\n CF_NAME set-space-role USERNAME ORG SPACE ROLE [--origin ORIGIN]\n\nROLES:\n SpaceManager - Invite and manage users, and enable features for a given space\n SpaceDeveloper - Create and manage apps and services, and see logs and reports\n SpaceAuditor - View logs, reports, and settings on this space"` + usage interface{} `usage:"CF_NAME set-space-role USERNAME ORG SPACE ROLE\n CF_NAME set-space-role USERNAME ORG SPACE ROLE [--client]\n CF_NAME set-space-role USERNAME ORG SPACE ROLE [--origin ORIGIN]\n\nROLES:\n SpaceManager - Invite and manage users, and enable features for a given space\n SpaceDeveloper - Create and manage apps and services, and see logs and reports\n SpaceAuditor - View logs, reports, and settings on this space\n SpaceSupporter [Beta role, subject to change] - Manage app lifecycle and service bindings"` relatedCommands interface{} `related_commands:"space-users, unset-space-role"` } @@ -89,13 +91,15 @@ func (cmd SetSpaceRoleCommand) validateFlags() error { } func convertSpaceRoleType(givenRole flag.SpaceRole) (constant.RoleType, error) { - switch givenRole.Role { - case "SpaceAuditor": + switch strings.ToLower(givenRole.Role) { + case "spaceauditor": return constant.SpaceAuditorRole, nil - case "SpaceManager": + case "spacemanager": return constant.SpaceManagerRole, nil - case "SpaceDeveloper": + case "spacedeveloper": return constant.SpaceDeveloperRole, nil + case "spacesupporter": + return constant.SpaceSupporterRole, nil default: return "", errors.New("Invalid role type.") } diff --git a/command/v7/set_space_role_command_test.go b/command/v7/set_space_role_command_test.go index d79196e908e..6b9cd1249e8 100644 --- a/command/v7/set_space_role_command_test.go +++ b/command/v7/set_space_role_command_test.go @@ -258,4 +258,24 @@ var _ = Describe("set-space-role Command", func() { Expect(executeErr).To(MatchError("create-role-error")) }) }) + + When("creating a space supporter space role", func() { + BeforeEach(func() { + cmd.Args.Role = flag.SpaceRole{Role: "SpaceSupporter"} + cmd.Args.Organization = "some-org-name" + cmd.Args.Space = "some-space-name" + cmd.Args.Username = "target-user-name" + + }) + It("creates the space role", func() { + Expect(fakeActor.CreateSpaceRoleCallCount()).To(Equal(1)) + givenRoleType, givenOrgGUID, givenSpaceGUID, givenUserName, givenOrigin, givenIsClient := fakeActor.CreateSpaceRoleArgsForCall(0) + Expect(givenRoleType).To(Equal(constant.SpaceSupporterRole)) + Expect(givenOrgGUID).To(Equal("some-org-guid")) + Expect(givenSpaceGUID).To(Equal("some-space-guid")) + Expect(givenUserName).To(Equal("target-user-name")) + Expect(givenOrigin).To(Equal("")) + Expect(givenIsClient).To(BeFalse()) + }) + }) }) diff --git a/command/v7/unset_space_role_command.go b/command/v7/unset_space_role_command.go index 51b56556dc5..0bfc040bf58 100644 --- a/command/v7/unset_space_role_command.go +++ b/command/v7/unset_space_role_command.go @@ -11,7 +11,7 @@ type UnsetSpaceRoleCommand struct { Args flag.SpaceRoleArgs `positional-args:"yes"` IsClient bool `long:"client" description:"Remove space role from a client-id of a (non-user) service account"` Origin string `long:"origin" description:"Indicates the identity provider to be used for authentication"` - usage interface{} `usage:"CF_NAME unset-space-role USERNAME ORG SPACE ROLE\n CF_NAME unset-space-role USERNAME ORG SPACE ROLE [--client]\n CF_NAME unset-space-role USERNAME ORG SPACE ROLE [--origin ORIGIN]\n\nROLES:\n SpaceManager - Invite and manage users, and enable features for a given space\n SpaceDeveloper - Create and manage apps and services, and see logs and reports\n SpaceAuditor - View logs, reports, and settings on this space"` + usage interface{} `usage:"CF_NAME unset-space-role USERNAME ORG SPACE ROLE\n CF_NAME unset-space-role USERNAME ORG SPACE ROLE [--client]\n CF_NAME unset-space-role USERNAME ORG SPACE ROLE [--origin ORIGIN]\n\nROLES:\n SpaceManager - Invite and manage users, and enable features for a given space\n SpaceDeveloper - Create and manage apps and services, and see logs and reports\n SpaceAuditor - View logs, reports, and settings on this space\n SpaceSupporter [Beta role, subject to change] - Manage app lifecycle and service bindings"` relatedCommands interface{} `related_commands:"set-space-role, space-users"` } diff --git a/command/v7/unset_space_role_command_test.go b/command/v7/unset_space_role_command_test.go index f1c976d814d..ef0105e3885 100644 --- a/command/v7/unset_space_role_command_test.go +++ b/command/v7/unset_space_role_command_test.go @@ -134,6 +134,24 @@ var _ = Describe("unset-space-role Command", func() { cmd.IsClient = true }) + When("the role is space supporter", func() { + BeforeEach(func() { + cmd.Args.Role = flag.SpaceRole{Role: "SpaceSupporter"} + }) + + It("deletes the space role correctly", func() { + givenRoleType, givenSpaceGUID, givenUserName, givenOrigin, givenIsClient := fakeActor.DeleteSpaceRoleArgsForCall(0) + Expect(givenRoleType).To(Equal(constant.SpaceSupporterRole)) + Expect(givenSpaceGUID).To(Equal("some-space-guid")) + Expect(givenUserName).To(Equal("target-user-name")) + Expect(givenOrigin).To(Equal("")) + Expect(givenIsClient).To(BeTrue()) + + Expect(testUI.Out).To(Say("Removing role SpaceSupporter from user target-user-name in org some-org-name / space some-space-name as current-user...")) + Expect(testUI.Out).To(Say("OK")) + Expect(executeErr).NotTo(HaveOccurred()) + }) + }) It("does not try to get the user", func() { Expect(fakeActor.GetUserCallCount()).To(Equal(0)) }) diff --git a/integration/v7/isolated/set_space_role_command_test.go b/integration/v7/isolated/set_space_role_command_test.go index a7224d8952d..8cce52ff55f 100644 --- a/integration/v7/isolated/set_space_role_command_test.go +++ b/integration/v7/isolated/set_space_role_command_test.go @@ -13,29 +13,30 @@ var _ = Describe("set-space-role command", func() { When("--help flag is set", func() { It("Displays command usage to output", func() { session := helpers.CF("set-space-role", "--help") - Eventually(session).Should(Say("NAME:")) - Eventually(session).Should(Say("set-space-role - Assign a space role to a user")) - Eventually(session).Should(Say("USAGE:")) - Eventually(session).Should(Say("cf set-space-role USERNAME ORG SPACE ROLE")) - Eventually(session).Should(Say(`cf set-space-role USERNAME ORG SPACE ROLE \[--client\]`)) - Eventually(session).Should(Say(`cf set-space-role USERNAME ORG SPACE ROLE \[--origin ORIGIN\]`)) - Eventually(session).Should(Say("ROLES:")) - Eventually(session).Should(Say("SpaceManager - Invite and manage users, and enable features for a given space")) - Eventually(session).Should(Say("SpaceDeveloper - Create and manage apps and services, and see logs and reports")) - Eventually(session).Should(Say("SpaceAuditor - View logs, reports, and settings on this space")) - Eventually(session).Should(Say("OPTIONS:")) - Eventually(session).Should(Say(`--client\s+Assign a space role to a client-id of a \(non-user\) service account`)) - Eventually(session).Should(Say(`--origin\s+Indicates the identity provider to be used for authentication`)) - Eventually(session).Should(Say("SEE ALSO:")) - Eventually(session).Should(Say("space-users, unset-space-role")) Eventually(session).Should(Exit(0)) + Expect(session).To(Say("NAME:")) + Expect(session).To(Say("set-space-role - Assign a space role to a user")) + Expect(session).To(Say("USAGE:")) + Expect(session).To(Say("cf set-space-role USERNAME ORG SPACE ROLE")) + Expect(session).To(Say(`cf set-space-role USERNAME ORG SPACE ROLE \[--client\]`)) + Expect(session).To(Say(`cf set-space-role USERNAME ORG SPACE ROLE \[--origin ORIGIN\]`)) + Expect(session).To(Say("ROLES:")) + Expect(session).To(Say("SpaceManager - Invite and manage users, and enable features for a given space")) + Expect(session).To(Say("SpaceDeveloper - Create and manage apps and services, and see logs and reports")) + Expect(session).To(Say("SpaceAuditor - View logs, reports, and settings on this space")) + Expect(session).To(Say(`SpaceSupporter \[Beta role, subject to change\] - Manage app lifecycle and service bindings`)) + Expect(session).To(Say("OPTIONS:")) + Expect(session).To(Say(`--client\s+Assign a space role to a client-id of a \(non-user\) service account`)) + Expect(session).To(Say(`--origin\s+Indicates the identity provider to be used for authentication`)) + Expect(session).To(Say("SEE ALSO:")) + Expect(session).To(Say("space-users, unset-space-role")) }) }) When("the role type is invalid", func() { It("prints a useful error, prints help text, and exits 1", func() { session := helpers.CF("set-space-role", "some-user", "some-org", "some-space", "NotARealRole") - Eventually(session.Err).Should(Say(`Incorrect Usage: ROLE must be "SpaceManager", "SpaceDeveloper" and "SpaceAuditor"`)) + Eventually(session.Err).Should(Say(`Incorrect Usage: ROLE must be "SpaceManager", "SpaceDeveloper", "SpaceAuditor" or "SpaceSupporter"`)) Eventually(session).Should(Say(`NAME:`)) Eventually(session).Should(Exit(1)) }) diff --git a/integration/v7/isolated/unset_space_role_command_test.go b/integration/v7/isolated/unset_space_role_command_test.go index d68a4b65cc2..f6cf0937ced 100644 --- a/integration/v7/isolated/unset_space_role_command_test.go +++ b/integration/v7/isolated/unset_space_role_command_test.go @@ -32,29 +32,30 @@ var _ = Describe("unset-space-role command", func() { When("--help flag is unset", func() { It("Displays command usage to output", func() { session := helpers.CF("unset-space-role", "--help") - Eventually(session).Should(Say("NAME:")) - Eventually(session).Should(Say("unset-space-role - Remove a space role from a user")) - Eventually(session).Should(Say("USAGE:")) - Eventually(session).Should(Say("cf unset-space-role USERNAME ORG SPACE ROLE")) - Eventually(session).Should(Say(`cf unset-space-role USERNAME ORG SPACE ROLE \[--client\]`)) - Eventually(session).Should(Say(`cf unset-space-role USERNAME ORG SPACE ROLE \[--origin ORIGIN\]`)) - Eventually(session).Should(Say("ROLES:")) - Eventually(session).Should(Say("SpaceManager - Invite and manage users, and enable features for a given space")) - Eventually(session).Should(Say("SpaceDeveloper - Create and manage apps and services, and see logs and reports")) - Eventually(session).Should(Say("SpaceAuditor - View logs, reports, and settings on this space")) - Eventually(session).Should(Say("OPTIONS:")) - Eventually(session).Should(Say(`--client\s+Remove space role from a client-id of a \(non-user\) service account`)) - Eventually(session).Should(Say(`--origin\s+Indicates the identity provider to be used for authentication`)) - Eventually(session).Should(Say("SEE ALSO:")) - Eventually(session).Should(Say("set-space-role, space-users")) Eventually(session).Should(Exit(0)) + Expect(session).To(Say("NAME:")) + Expect(session).To(Say("unset-space-role - Remove a space role from a user")) + Expect(session).To(Say("USAGE:")) + Expect(session).To(Say("cf unset-space-role USERNAME ORG SPACE ROLE")) + Expect(session).To(Say(`cf unset-space-role USERNAME ORG SPACE ROLE \[--client\]`)) + Expect(session).To(Say(`cf unset-space-role USERNAME ORG SPACE ROLE \[--origin ORIGIN\]`)) + Expect(session).To(Say("ROLES:")) + Expect(session).To(Say("SpaceManager - Invite and manage users, and enable features for a given space")) + Expect(session).To(Say("SpaceDeveloper - Create and manage apps and services, and see logs and reports")) + Expect(session).To(Say("SpaceAuditor - View logs, reports, and settings on this space")) + Expect(session).To(Say(`SpaceSupporter \[Beta role, subject to change\] - Manage app lifecycle and service bindings`)) + Expect(session).To(Say("OPTIONS:")) + Expect(session).To(Say(`--client\s+Remove space role from a client-id of a \(non-user\) service account`)) + Expect(session).To(Say(`--origin\s+Indicates the identity provider to be used for authentication`)) + Expect(session).To(Say("SEE ALSO:")) + Expect(session).To(Say("set-space-role, space-users")) }) }) When("the role type does not exist", func() { It("prints a useful error, prints help text, and exits 1", func() { session := helpers.CF("unset-space-role", "some-user", "some-org", "some-space", "NotARealRole") - Eventually(session.Err).Should(Say(`Incorrect Usage: ROLE must be "SpaceManager", "SpaceDeveloper" and "SpaceAuditor"`)) + Eventually(session.Err).Should(Say(`Incorrect Usage: ROLE must be "SpaceManager", "SpaceDeveloper", "SpaceAuditor" or "SpaceSupporter"`)) Eventually(session).Should(Say(`NAME:`)) Eventually(session).Should(Exit(1)) })