-
Notifications
You must be signed in to change notification settings - Fork 929
/
delete_domain.go
85 lines (71 loc) · 2.09 KB
/
delete_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
84
85
package domain
import (
"cf/api"
"cf/configuration"
"cf/requirements"
"cf/terminal"
"errors"
"github.com/codegangsta/cli"
)
type DeleteDomain struct {
ui terminal.UI
config *configuration.Configuration
orgReq requirements.TargetedOrgRequirement
domainRepo api.DomainRepository
}
func NewDeleteDomain(ui terminal.UI, config *configuration.Configuration, repo api.DomainRepository) (cmd *DeleteDomain) {
cmd = new(DeleteDomain)
cmd.ui = ui
cmd.config = config
cmd.domainRepo = repo
return
}
func (cmd *DeleteDomain) 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-domain")
return
}
loginReq := reqFactory.NewLoginRequirement()
cmd.orgReq = reqFactory.NewTargetedOrgRequirement()
reqs = []requirements.Requirement{
loginReq,
cmd.orgReq,
}
return
}
func (cmd *DeleteDomain) 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.GetOrganization())
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 {
var answer bool
if domain.Shared {
answer = cmd.ui.Confirm("This domain is shared across all orgs.\nDeleting it will remove all associated routes, and will make any app with this domain unreachable.\nAre you sure you want to delete the domain %s? ", domainName)
} else {
answer = cmd.ui.Confirm("Are you sure you want to delete the domain %s and all of its associations?", domainName)
}
if !answer {
return
}
}
apiResponse = cmd.domainRepo.Delete(domain)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed("Error deleting domain %s\n%s", domainName, apiResponse.Message)
return
}
cmd.ui.Ok()
}