github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/cf/commands/space/space_ssh_allowed.go (about) 1 package space 2 3 import ( 4 "fmt" 5 6 "code.cloudfoundry.org/cli/cf/api/spaces" 7 "code.cloudfoundry.org/cli/cf/commandregistry" 8 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 9 "code.cloudfoundry.org/cli/cf/flags" 10 . "code.cloudfoundry.org/cli/cf/i18n" 11 "code.cloudfoundry.org/cli/cf/requirements" 12 "code.cloudfoundry.org/cli/cf/terminal" 13 ) 14 15 type SSHAllowed struct { 16 ui terminal.UI 17 config coreconfig.Reader 18 spaceReq requirements.SpaceRequirement 19 spaceRepo spaces.SpaceRepository 20 } 21 22 func init() { 23 commandregistry.Register(&SSHAllowed{}) 24 } 25 26 func (cmd *SSHAllowed) MetaData() commandregistry.CommandMetadata { 27 return commandregistry.CommandMetadata{ 28 Name: "space-ssh-allowed", 29 Description: T("Reports whether SSH is allowed in a space"), 30 Usage: []string{ 31 T("CF_NAME space-ssh-allowed SPACE_NAME"), 32 }, 33 } 34 } 35 36 func (cmd *SSHAllowed) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) { 37 if len(fc.Args()) != 1 { 38 cmd.ui.Failed(T("Incorrect Usage. Requires SPACE_NAME as argument\n\n") + commandregistry.Commands.CommandUsage("space-ssh-allowed")) 39 return nil, fmt.Errorf("Incorrect usage: %d arguments of %d required", len(fc.Args()), 1) 40 } 41 42 cmd.spaceReq = requirementsFactory.NewSpaceRequirement(fc.Args()[0]) 43 reqs := []requirements.Requirement{ 44 requirementsFactory.NewLoginRequirement(), 45 requirementsFactory.NewTargetedOrgRequirement(), 46 cmd.spaceReq, 47 } 48 49 return reqs, nil 50 } 51 52 func (cmd *SSHAllowed) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command { 53 cmd.ui = deps.UI 54 return cmd 55 } 56 57 func (cmd *SSHAllowed) Execute(fc flags.FlagContext) error { 58 space := cmd.spaceReq.GetSpace() 59 60 if space.AllowSSH { 61 cmd.ui.Say(fmt.Sprintf(T("ssh support is enabled in space ")+"'%s'", space.Name)) 62 } else { 63 cmd.ui.Say(fmt.Sprintf(T("ssh support is disabled in space ")+"'%s'", space.Name)) 64 } 65 return nil 66 }