-
Notifications
You must be signed in to change notification settings - Fork 927
/
delete_shared_domain.go
83 lines (69 loc) · 1.98 KB
/
delete_shared_domain.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
package domain
import (
"cf/api"
"cf/configuration"
"cf/requirements"
"cf/terminal"
"errors"
"github.com/codegangsta/cli"
)
type DeleteSharedDomain struct {
ui terminal.UI
config configuration.Reader
orgReq requirements.TargetedOrgRequirement
domainRepo api.DomainRepository
}
func NewDeleteSharedDomain(ui terminal.UI, config configuration.Reader, repo api.DomainRepository) (cmd *DeleteSharedDomain) {
cmd = new(DeleteSharedDomain)
cmd.ui = ui
cmd.config = config
cmd.domainRepo = repo
return
}
func (cmd *DeleteSharedDomain) GetRequirements(reqFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 1 {
err = errors.New("Incorrect Usage")
cmd.ui.FailWithUsage(c, "delete-shared-domain")
return
}
loginReq := reqFactory.NewLoginRequirement()
cmd.orgReq = reqFactory.NewTargetedOrgRequirement()
reqs = []requirements.Requirement{
loginReq,
cmd.orgReq,
}
return
}
func (cmd *DeleteSharedDomain) Run(c *cli.Context) {
domainName := c.Args()[0]
force := c.Bool("f")
cmd.ui.Say("Deleting domain %s as %s...",
terminal.EntityNameColor(domainName),
terminal.EntityNameColor(cmd.config.Username()),
)
domain, apiResponse := cmd.domainRepo.FindByNameInOrg(domainName, cmd.orgReq.GetOrganizationFields().Guid)
if apiResponse.IsError() {
cmd.ui.Failed("Error finding domain %s\n%s", domainName, apiResponse.Message)
return
}
if apiResponse.IsNotFound() {
cmd.ui.Ok()
cmd.ui.Warn(apiResponse.Message)
return
}
if !force {
answer := cmd.ui.Confirm(
`This domain is shared across all orgs.
Deleting it will remove all associated routes, and will make any app with this domain unreachable.
Are you sure you want to delete the domain %s? `, domainName)
if !answer {
return
}
}
apiResponse = cmd.domainRepo.DeleteSharedDomain(domain.Guid)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed("Error deleting domain %s\n%s", domainName, apiResponse.Message)
return
}
cmd.ui.Ok()
}