forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_service_broker.go
56 lines (45 loc) · 1.3 KB
/
create_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
package servicebroker
import (
"cf/api"
"cf/configuration"
"cf/requirements"
"cf/terminal"
"errors"
"github.com/codegangsta/cli"
)
type CreateServiceBroker struct {
ui terminal.UI
config configuration.Reader
serviceBrokerRepo api.ServiceBrokerRepository
}
func NewCreateServiceBroker(ui terminal.UI, config configuration.Reader, serviceBrokerRepo api.ServiceBrokerRepository) (cmd CreateServiceBroker) {
cmd.ui = ui
cmd.config = config
cmd.serviceBrokerRepo = serviceBrokerRepo
return
}
func (cmd CreateServiceBroker) 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, "create-service-broker")
return
}
reqs = append(reqs, reqFactory.NewLoginRequirement())
return
}
func (cmd CreateServiceBroker) Run(c *cli.Context) {
name := c.Args()[0]
username := c.Args()[1]
password := c.Args()[2]
url := c.Args()[3]
cmd.ui.Say("Creating service broker %s as %s...",
terminal.EntityNameColor(name),
terminal.EntityNameColor(cmd.config.Username()),
)
apiResponse := cmd.serviceBrokerRepo.Create(name, url, username, password)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed(apiResponse.Message)
return
}
cmd.ui.Ok()
}