github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/create_shared_domain_command.go (about) 1 package v6 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/sharedaction" 5 "code.cloudfoundry.org/cli/actor/v2action" 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 7 "code.cloudfoundry.org/cli/command" 8 "code.cloudfoundry.org/cli/command/flag" 9 "code.cloudfoundry.org/cli/command/translatableerror" 10 "code.cloudfoundry.org/cli/command/v6/shared" 11 ) 12 13 //go:generate counterfeiter . CreateSharedDomainActor 14 15 type CreateSharedDomainActor interface { 16 GetRouterGroupByName(string, v2action.RouterClient) (v2action.RouterGroup, error) 17 CreateSharedDomain(string, v2action.RouterGroup, bool) (v2action.Warnings, error) 18 CloudControllerAPIVersion() string 19 } 20 21 type CreateSharedDomainCommand struct { 22 RequiredArgs flag.Domain `positional-args:"yes"` 23 RouterGroup string `long:"router-group" description:"Routes for this domain will be configured only on the specified router group"` 24 Internal bool `long:"internal" description:"Applications that use internal routes communicate directly on the container network"` 25 usage interface{} `usage:"CF_NAME create-shared-domain DOMAIN [--router-group ROUTER_GROUP | --internal]"` 26 relatedCommands interface{} `related_commands:"create-domain, domains, router-groups"` 27 28 UI command.UI 29 Config command.Config 30 Actor CreateSharedDomainActor 31 SharedActor command.SharedActor 32 RouterClient v2action.RouterClient 33 } 34 35 func (cmd *CreateSharedDomainCommand) Setup(config command.Config, ui command.UI) error { 36 ccClient, uaaClient, err := shared.GetNewClientsAndConnectToCF(config, ui) 37 38 if err != nil { 39 return err 40 } 41 42 routerClient, err := shared.NewRouterClient(config, ui, uaaClient) 43 44 if err != nil { 45 return err 46 } 47 48 cmd.Actor = v2action.NewActor(ccClient, uaaClient, config) 49 cmd.RouterClient = routerClient 50 cmd.SharedActor = sharedaction.NewActor(config) 51 cmd.Config = config 52 cmd.UI = ui 53 return nil 54 } 55 56 func (cmd CreateSharedDomainCommand) Execute(args []string) error { 57 if len(args) > 0 { 58 return translatableerror.TooManyArgumentsError{ 59 ExtraArgument: args[0], 60 } 61 } 62 63 if cmd.Internal { 64 currentVersion := cmd.Actor.CloudControllerAPIVersion() 65 err := command.MinimumCCAPIVersionCheck(currentVersion, ccversion.MinVersionInternalDomainV2, "Option '--internal'") 66 if err != nil { 67 return err 68 } 69 } 70 71 if cmd.RouterGroup != "" && cmd.Internal { 72 return translatableerror.ArgumentCombinationError{ 73 Args: []string{"--router-group", "--internal"}, 74 } 75 } 76 77 username, err := cmd.SharedActor.RequireCurrentUser() 78 if err != nil { 79 return err 80 } 81 cmd.UI.DisplayTextWithFlavor("Creating shared domain {{.Domain}} as {{.User}}...", 82 map[string]interface{}{ 83 "Domain": cmd.RequiredArgs.Domain, 84 "User": username, 85 }) 86 87 var routerGroup v2action.RouterGroup 88 89 if cmd.RouterGroup != "" { 90 routerGroup, err = cmd.Actor.GetRouterGroupByName(cmd.RouterGroup, cmd.RouterClient) 91 if err != nil { 92 return err 93 } 94 } 95 96 warnings, err := cmd.Actor.CreateSharedDomain(cmd.RequiredArgs.Domain, routerGroup, cmd.Internal) 97 cmd.UI.DisplayWarnings(warnings) 98 99 if err != nil { 100 return err 101 } 102 103 cmd.UI.DisplayOK() 104 return nil 105 }