forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
52 lines (42 loc) · 936 Bytes
/
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
package requirements
import (
"code.cloudfoundry.org/cli/cf/api"
"code.cloudfoundry.org/cli/cf/models"
)
//go:generate counterfeiter . UserRequirement
type UserRequirement interface {
Requirement
GetUser() models.UserFields
}
type userAPIRequirement struct {
username string
userRepo api.UserRepository
wantGUID bool
user models.UserFields
}
func NewUserRequirement(
username string,
userRepo api.UserRepository,
wantGUID bool,
) *userAPIRequirement {
req := new(userAPIRequirement)
req.username = username
req.userRepo = userRepo
req.wantGUID = wantGUID
return req
}
func (req *userAPIRequirement) Execute() error {
if req.wantGUID {
var err error
req.user, err = req.userRepo.FindByUsername(req.username)
if err != nil {
return err
}
} else {
req.user = models.UserFields{Username: req.username}
}
return nil
}
func (req *userAPIRequirement) GetUser() models.UserFields {
return req.user
}