forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_service_broker.go
61 lines (49 loc) · 1.39 KB
/
update_service_broker.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
package servicebroker
import (
"cf/api"
"cf/configuration"
"cf/requirements"
"cf/terminal"
"errors"
"github.com/codegangsta/cli"
)
type UpdateServiceBroker struct {
ui terminal.UI
config *configuration.Configuration
repo api.ServiceBrokerRepository
}
func NewUpdateServiceBroker(ui terminal.UI, config *configuration.Configuration, repo api.ServiceBrokerRepository) (cmd UpdateServiceBroker) {
cmd.ui = ui
cmd.config = config
cmd.repo = repo
return
}
func (cmd UpdateServiceBroker) GetRequirements(reqFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 4 {
err = errors.New("Incorrect Usage")
cmd.ui.FailWithUsage(c, "update-service-broker")
return
}
reqs = append(reqs, reqFactory.NewLoginRequirement())
return
}
func (cmd UpdateServiceBroker) Run(c *cli.Context) {
serviceBroker, apiResponse := cmd.repo.FindByName(c.Args()[0])
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Say("Updating service broker %s as %s...",
terminal.EntityNameColor(serviceBroker.Name),
terminal.EntityNameColor(cmd.config.Username()),
)
serviceBroker.Username = c.Args()[1]
serviceBroker.Password = c.Args()[2]
serviceBroker.Url = c.Args()[3]
apiResponse = cmd.repo.Update(serviceBroker)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
}