-
Notifications
You must be signed in to change notification settings - Fork 929
/
delete_private_domain_command.go
122 lines (98 loc) · 3.44 KB
/
delete_private_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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package v7
import (
"fmt"
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/actor/sharedaction"
"code.cloudfoundry.org/cli/actor/v7action"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/command/v7/shared"
"code.cloudfoundry.org/clock"
)
//go:generate counterfeiter . DeletePrivateDomainActor
type DeletePrivateDomainActor interface {
DeleteDomain(domain v7action.Domain) (v7action.Warnings, error)
GetDomainByName(domainName string) (v7action.Domain, v7action.Warnings, error)
}
type DeletePrivateDomainCommand struct {
RequiredArgs flag.Domain `positional-args:"yes"`
Force bool `short:"f" description:"Force deletion without confirmation"`
usage interface{} `usage:"CF_NAME delete-private-domain DOMAIN [-f]"`
relatedCommands interface{} `related_commands:"delete-shared-domain, domains, unshare-private-domain"`
UI command.UI
Config command.Config
SharedActor command.SharedActor
Actor DeletePrivateDomainActor
}
func (cmd *DeletePrivateDomainCommand) Setup(config command.Config, ui command.UI) error {
cmd.UI = ui
cmd.Config = config
cmd.SharedActor = sharedaction.NewActor(config)
ccClient, _, err := shared.GetNewClientsAndConnectToCF(config, ui, "")
if err != nil {
return err
}
cmd.Actor = v7action.NewActor(ccClient, config, nil, nil, clock.NewClock())
return nil
}
func (cmd DeletePrivateDomainCommand) Execute(args []string) error {
domainName := cmd.RequiredArgs.Domain
err := cmd.SharedActor.CheckTarget(true, false)
if err != nil {
return err
}
currentUser, err := cmd.Config.CurrentUser()
if err != nil {
return err
}
domain, warnings, err := cmd.Actor.GetDomainByName(domainName)
cmd.UI.DisplayWarningsV7(warnings)
cmd.UI.DisplayTextWithFlavor("Deleting private domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{
"DomainName": domainName,
"Username": currentUser.Name,
})
if err != nil {
if _, ok := err.(actionerror.DomainNotFoundError); ok {
cmd.UI.DisplayTextWithFlavor("Deleting private domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{
"DomainName": domainName,
"Username": currentUser.Name,
})
cmd.UI.DisplayWarningV7("Domain '{{.DomainName}}' does not exist.", map[string]interface{}{
"DomainName": cmd.RequiredArgs.Domain,
})
cmd.UI.DisplayOK()
return nil
}
return err
}
if domain.Shared() {
return fmt.Errorf("Domain '%s' is a shared domain, not a private domain.", domainName)
}
cmd.UI.DisplayText("Deleting the private domain will remove associated routes which will make apps with this domain unreachable.")
if !cmd.Force {
response, promptErr := cmd.UI.DisplayBoolPrompt(false, "Really delete the private domain {{.DomainName}}?", map[string]interface{}{
"DomainName": domainName,
})
if promptErr != nil {
return promptErr
}
if !response {
cmd.UI.DisplayText("'{{.DomainName}}' has not been deleted.", map[string]interface{}{
"DomainName": domainName,
})
return nil
}
}
cmd.UI.DisplayTextWithFlavor("Deleting private domain {{.DomainName}} as {{.Username}}...", map[string]interface{}{
"DomainName": domainName,
"Username": currentUser.Name,
})
warnings, err = cmd.Actor.DeleteDomain(domain)
cmd.UI.DisplayWarningsV7(warnings)
if err != nil {
return err
}
cmd.UI.DisplayOK()
cmd.UI.DisplayText("TIP: Run 'cf domains' to view available domains.")
return nil
}