forked from cloudfoundry/cli
/
disallow_space_ssh_command.go
53 lines (39 loc) · 1.24 KB
/
disallow_space_ssh_command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package v7
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/command/flag"
)
type DisallowSpaceSSHCommand struct {
BaseCommand
RequiredArgs flag.Space `positional-args:"yes"`
usage interface{} `usage:"CF_NAME disallow-space-ssh SPACE_NAME"`
relatedCommands interface{} `related_commands:"disable-ssh, space-ssh-allowed, ssh, ssh-enabled"`
}
func (cmd *DisallowSpaceSSHCommand) Execute(args []string) error {
err := cmd.SharedActor.CheckTarget(true, false)
if err != nil {
return err
}
currentUserName, err := cmd.Config.CurrentUserName()
if err != nil {
return err
}
targetedOrgGUID := cmd.Config.TargetedOrganization().GUID
inputSpace := cmd.RequiredArgs.Space
cmd.UI.DisplayTextWithFlavor("Disabling ssh support for space {{.Space}} as {{.CurrentUserName}}...", map[string]interface{}{
"Space": inputSpace,
"CurrentUserName": currentUserName,
})
warnings, err := cmd.Actor.UpdateSpaceFeature(inputSpace, targetedOrgGUID, false, "ssh")
cmd.UI.DisplayWarnings(warnings)
if _, ok := err.(actionerror.SpaceSSHAlreadyDisabledError); ok {
cmd.UI.DisplayText(err.Error())
cmd.UI.DisplayOK()
return nil
}
if err != nil {
return err
}
cmd.UI.DisplayOK()
return err
}