forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_shared_domain_command.go
105 lines (86 loc) · 3.06 KB
/
create_shared_domain_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package v6
import (
"code.cloudfoundry.org/cli/actor/sharedaction"
"code.cloudfoundry.org/cli/actor/v2action"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccversion"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/command/translatableerror"
"code.cloudfoundry.org/cli/command/v6/shared"
)
//go:generate counterfeiter . CreateSharedDomainActor
type CreateSharedDomainActor interface {
GetRouterGroupByName(string, v2action.RouterClient) (v2action.RouterGroup, error)
CreateSharedDomain(string, v2action.RouterGroup, bool) (v2action.Warnings, error)
CloudControllerAPIVersion() string
}
type CreateSharedDomainCommand struct {
RequiredArgs flag.Domain `positional-args:"yes"`
RouterGroup string `long:"router-group" description:"Routes for this domain will be configured only on the specified router group"`
Internal bool `long:"internal" description:"Applications that use internal routes communicate directly on the container network"`
usage interface{} `usage:"CF_NAME create-shared-domain DOMAIN [--router-group ROUTER_GROUP | --internal]"`
relatedCommands interface{} `related_commands:"create-domain, domains, router-groups"`
UI command.UI
Config command.Config
Actor CreateSharedDomainActor
SharedActor command.SharedActor
RouterClient v2action.RouterClient
}
func (cmd *CreateSharedDomainCommand) Setup(config command.Config, ui command.UI) error {
ccClient, uaaClient, err := shared.GetNewClientsAndConnectToCF(config, ui)
if err != nil {
return err
}
routerClient, err := shared.NewRouterClient(config, ui, uaaClient)
if err != nil {
return err
}
cmd.Actor = v2action.NewActor(ccClient, uaaClient, config)
cmd.RouterClient = routerClient
cmd.SharedActor = sharedaction.NewActor(config)
cmd.Config = config
cmd.UI = ui
return nil
}
func (cmd CreateSharedDomainCommand) Execute(args []string) error {
if len(args) > 0 {
return translatableerror.TooManyArgumentsError{
ExtraArgument: args[0],
}
}
if cmd.Internal {
currentVersion := cmd.Actor.CloudControllerAPIVersion()
err := command.MinimumCCAPIVersionCheck(currentVersion, ccversion.MinVersionInternalDomainV2, "Option '--internal'")
if err != nil {
return err
}
}
if cmd.RouterGroup != "" && cmd.Internal {
return translatableerror.ArgumentCombinationError{
Args: []string{"--router-group", "--internal"},
}
}
username, err := cmd.SharedActor.RequireCurrentUser()
if err != nil {
return err
}
cmd.UI.DisplayTextWithFlavor("Creating shared domain {{.Domain}} as {{.User}}...",
map[string]interface{}{
"Domain": cmd.RequiredArgs.Domain,
"User": username,
})
var routerGroup v2action.RouterGroup
if cmd.RouterGroup != "" {
routerGroup, err = cmd.Actor.GetRouterGroupByName(cmd.RouterGroup, cmd.RouterClient)
if err != nil {
return err
}
}
warnings, err := cmd.Actor.CreateSharedDomain(cmd.RequiredArgs.Domain, routerGroup, cmd.Internal)
cmd.UI.DisplayWarnings(warnings)
if err != nil {
return err
}
cmd.UI.DisplayOK()
return nil
}