-
Notifications
You must be signed in to change notification settings - Fork 1
/
user.go
81 lines (68 loc) · 1.56 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package xrhidgen
import (
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// User holds values to be used as input when generating a user identity record.
type User struct {
Email *string
FirstName *string
IsActive *bool
IsInternal *bool
IsOrgAdmin *bool
LastName *string
Locale *string
UserID *string
Username *string
}
// NewUser will build and return a fully populated User data structure, using
// any values that are present in template.
func NewUser(template User) (*identity.User, error) {
var id identity.User
if template.Email != nil {
id.Email = *template.Email
} else {
id.Email = faker.Email()
}
if template.FirstName != nil {
id.FirstName = *template.FirstName
} else {
id.FirstName = faker.FirstName()
}
if template.IsActive != nil {
id.Active = *template.IsActive
} else {
id.Active = faker.Bool()
}
if template.IsInternal != nil {
id.Internal = *template.IsInternal
} else {
id.Internal = faker.Bool()
}
if template.IsOrgAdmin != nil {
id.OrgAdmin = *template.IsOrgAdmin
} else {
id.OrgAdmin = faker.Bool()
}
if template.LastName != nil {
id.LastName = *template.LastName
} else {
id.LastName = faker.LastName()
}
if template.Locale != nil {
id.Locale = *template.Locale
} else {
id.Locale = faker.LangCode()
}
if template.UserID != nil {
id.UserID = *template.UserID
} else {
id.UserID = faker.Username()
}
if template.Username != nil {
id.Username = *template.Username
} else {
id.Username = faker.Username()
}
return &id, nil
}