forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_user.go
59 lines (48 loc) · 1.33 KB
/
create_user.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
package user
import (
"cf"
"cf/api"
"cf/configuration"
"cf/requirements"
"cf/terminal"
"errors"
"github.com/codegangsta/cli"
)
type CreateUser struct {
ui terminal.UI
config *configuration.Configuration
userRepo api.UserRepository
}
func NewCreateUser(ui terminal.UI, config *configuration.Configuration, userRepo api.UserRepository) (cmd CreateUser) {
cmd.ui = ui
cmd.config = config
cmd.userRepo = userRepo
return
}
func (cmd CreateUser) GetRequirements(reqFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 2 {
err = errors.New("Incorrect Usage")
cmd.ui.FailWithUsage(c, "create-user")
}
reqs = append(reqs, reqFactory.NewLoginRequirement())
return
}
func (cmd CreateUser) Run(c *cli.Context) {
username := c.Args()[0]
password := c.Args()[1]
cmd.ui.Say("Creating user %s as %s...",
terminal.EntityNameColor(username),
terminal.EntityNameColor(cmd.config.Username()),
)
user := cf.User{
Username: username,
Password: password,
}
apiResponse := cmd.userRepo.Create(user)
if apiResponse.IsNotSuccessful() {
cmd.ui.Failed("Error creating user %s.\n%s", terminal.EntityNameColor(username), apiResponse.Message)
return
}
cmd.ui.Ok()
cmd.ui.Say("\nTIP: Assign roles with '%s set-org-role' and '%s set-space-role'", cf.Name(), cf.Name())
}