github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/cf/commands/space/disallow_space_ssh.go (about) 1 package space 2 3 import ( 4 "errors" 5 "fmt" 6 7 "code.cloudfoundry.org/cli/cf/api/spaces" 8 "code.cloudfoundry.org/cli/cf/commandregistry" 9 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 10 "code.cloudfoundry.org/cli/cf/flags" 11 . "code.cloudfoundry.org/cli/cf/i18n" 12 "code.cloudfoundry.org/cli/cf/requirements" 13 "code.cloudfoundry.org/cli/cf/terminal" 14 ) 15 16 type DisallowSpaceSSH struct { 17 ui terminal.UI 18 config coreconfig.Reader 19 spaceReq requirements.SpaceRequirement 20 spaceRepo spaces.SpaceRepository 21 } 22 23 func init() { 24 commandregistry.Register(&DisallowSpaceSSH{}) 25 } 26 27 func (cmd *DisallowSpaceSSH) MetaData() commandregistry.CommandMetadata { 28 return commandregistry.CommandMetadata{ 29 Name: "disallow-space-ssh", 30 Description: T("Disallow SSH access for the space"), 31 Usage: []string{ 32 T("CF_NAME disallow-space-ssh SPACE_NAME"), 33 }, 34 } 35 } 36 37 func (cmd *DisallowSpaceSSH) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) { 38 if len(fc.Args()) != 1 { 39 cmd.ui.Failed(T("Incorrect Usage. Requires SPACE_NAME as argument\n\n") + commandregistry.Commands.CommandUsage("disallow-space-ssh")) 40 return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1) 41 } 42 43 cmd.spaceReq = requirementsFactory.NewSpaceRequirement(fc.Args()[0]) 44 45 reqs := []requirements.Requirement{ 46 requirementsFactory.NewLoginRequirement(), 47 requirementsFactory.NewTargetedOrgRequirement(), 48 cmd.spaceReq, 49 } 50 51 return reqs, nil 52 } 53 54 func (cmd *DisallowSpaceSSH) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command { 55 cmd.ui = deps.UI 56 cmd.config = deps.Config 57 cmd.spaceRepo = deps.RepoLocator.GetSpaceRepository() 58 return cmd 59 } 60 61 func (cmd *DisallowSpaceSSH) Execute(fc flags.FlagContext) error { 62 space := cmd.spaceReq.GetSpace() 63 64 if !space.AllowSSH { 65 cmd.ui.Say(fmt.Sprintf(T("ssh support is already disabled in space ")+"'%s'", space.Name)) 66 return nil 67 } 68 69 cmd.ui.Say(T("Disabling ssh support for space '{{.SpaceName}}'...", 70 map[string]interface{}{ 71 "SpaceName": space.Name, 72 }, 73 )) 74 cmd.ui.Say("") 75 76 err := cmd.spaceRepo.SetAllowSSH(space.GUID, false) 77 if err != nil { 78 return errors.New(T("Error disabling ssh support for space ") + space.Name + ": " + err.Error()) 79 } 80 81 cmd.ui.Ok() 82 return nil 83 }