forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
55 lines (46 loc) · 1.06 KB
/
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
package requirements
import (
"github.com/cloudfoundry/cli/cf/api"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/terminal"
)
//go:generate counterfeiter -o fakes/fake_user_requirement.go . UserRequirement
type UserRequirement interface {
Requirement
GetUser() models.UserFields
}
type userApiRequirement struct {
username string
ui terminal.UI
userRepo api.UserRepository
wantGuid bool
user models.UserFields
}
func NewUserRequirement(
username string,
ui terminal.UI,
userRepo api.UserRepository,
wantGuid bool,
) *userApiRequirement {
req := new(userApiRequirement)
req.username = username
req.ui = ui
req.userRepo = userRepo
req.wantGuid = wantGuid
return req
}
func (req *userApiRequirement) Execute() bool {
if req.wantGuid {
var err error
req.user, err = req.userRepo.FindByUsername(req.username)
if err != nil {
req.ui.Failed(err.Error())
}
} else {
req.user = models.UserFields{Username: req.username}
}
return true
}
func (req *userApiRequirement) GetUser() models.UserFields {
return req.user
}