forked from cloudfoundry/cli
/
allow_space_ssh_command.go
54 lines (39 loc) · 1.23 KB
/
allow_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
54
package v7
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/command/flag"
)
type AllowSpaceSSHCommand struct {
BaseCommand
RequiredArgs flag.Space `positional-args:"yes"`
usage interface{} `usage:"CF_NAME allow-space-ssh SPACE_NAME"`
relatedCommands interface{} `related_commands:"enable-ssh, space-ssh-allowed, ssh, ssh-enabled"`
}
func (cmd *AllowSpaceSSHCommand) 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("Enabling ssh support for space {{.Space}} as {{.CurrentUserName}}...", map[string]interface{}{
"Space": inputSpace,
"CurrentUserName": currentUserName,
})
warnings, err := cmd.Actor.UpdateSpaceFeature(inputSpace, targetedOrgGUID, true, "ssh")
cmd.UI.DisplayWarnings(warnings)
if _, ok := err.(actionerror.SpaceSSHAlreadyEnabledError); ok {
cmd.UI.DisplayText(err.Error())
cmd.UI.DisplayOK()
return nil
}
if err != nil {
return err
}
cmd.UI.DisplayOK()
return err
}