Skip to content
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
1 change: 1 addition & 0 deletions api/cloudcontroller/ccv3/constant/role_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ const (
SpaceDeveloperRole RoleType = "space_developer"
SpaceAuditorRole RoleType = "space_auditor"
SpaceManagerRole RoleType = "space_manager"
SpaceSupporterRole RoleType = "space_supporter"
)
4 changes: 3 additions & 1 deletion command/flag/space_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`,
}
}

Expand Down
8 changes: 7 additions & 1 deletion command/flag/space_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand Down
14 changes: 9 additions & 5 deletions command/v7/set_space_role_command.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"`
}

Expand Down Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love that!

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.")
}
Expand Down
20 changes: 20 additions & 0 deletions command/v7/set_space_role_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
})
2 changes: 1 addition & 1 deletion command/v7/unset_space_role_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
18 changes: 18 additions & 0 deletions command/v7/unset_space_role_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
33 changes: 17 additions & 16 deletions integration/v7/isolated/set_space_role_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down
33 changes: 17 additions & 16 deletions integration/v7/isolated/unset_space_role_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
Expand Down