-
Notifications
You must be signed in to change notification settings - Fork 1
/
associate.go
57 lines (48 loc) · 1.23 KB
/
associate.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
package xrhidgen
import (
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// Associate holds values to be used as input when generating an associate
// identity record.
type Associate struct {
Email *string
GivenName *string
RHatUUID *string
Role *[]string
Surname *string
}
// NewAssociate will build and return a fully populated Associate data
// structure, using any values that are present in template.
func NewAssociate(template Associate) (*identity.Associate, error) {
var id identity.Associate
if template.Email != nil {
id.Email = *template.Email
} else {
id.Email = faker.Email()
}
if template.GivenName != nil {
id.GivenName = *template.GivenName
} else {
id.GivenName = faker.FirstName()
}
if template.RHatUUID != nil {
id.RHatUUID = *template.RHatUUID
} else {
id.RHatUUID = faker.UUID()
}
if template.Role != nil {
id.Role = *template.Role
} else {
slice := faker.Slice(faker.IntInRange(0, 3), func() interface{} { return faker.String() })
for _, v := range slice {
id.Role = append(id.Role, v.(string))
}
}
if template.Surname != nil {
id.Surname = *template.Surname
} else {
id.Surname = faker.LastName()
}
return &id, nil
}