-
Notifications
You must be signed in to change notification settings - Fork 1
/
identity.go
188 lines (149 loc) · 4.59 KB
/
identity.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package xrhidgen
import (
"github.com/pioz/faker"
"github.com/redhatinsights/platform-go-middlewares/v2/identity"
)
// Identity holds values to be used as input when generating a main identity
// record.
type Identity struct {
AccountNumber *string
AuthType *string
EmployeeAccountNumber *string
OrgID *string
Type *string
}
// NewIdentity will build and return a partially populated Identity data
// structure, using any values that are present in template.
func NewIdentity(template Identity) (*identity.XRHID, error) {
var id identity.XRHID
if template.AccountNumber != nil {
id.Identity.AccountNumber = *template.AccountNumber
} else {
if faker.Bool() {
id.Identity.AccountNumber = faker.DigitsWithSize(5)
}
}
if template.AuthType != nil {
id.Identity.AuthType = *template.AuthType
} else {
id.Identity.AuthType = faker.Pick("basic-auth", "cert-auth")
}
if template.EmployeeAccountNumber != nil {
id.Identity.EmployeeAccountNumber = *template.EmployeeAccountNumber
} else {
if faker.Bool() {
id.Identity.EmployeeAccountNumber = faker.DigitsWithSize(5)
}
}
if template.OrgID != nil {
id.Identity.OrgID = *template.OrgID
} else {
id.Identity.OrgID = faker.DigitsWithSize(5)
}
if template.Type != nil {
id.Identity.Type = *template.Type
} else {
id.Identity.Type = faker.String()
}
return &id, nil
}
// NewAssociateIdentity will build and return a fully populated Associate
// identity record, using any values that are present in identityTemplate and
// associateTemplate.
func NewAssociateIdentity(identityTemplate Identity, associateTemplate Associate) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
}
associate, err := NewAssociate(associateTemplate)
if err != nil {
return nil, err
}
id.Identity.Associate = associate
id.Identity.Type = "Associate"
return id, nil
}
// NewInternalIdentity will build and return a fully populated Internal identity
// record, using any values that are present in identityTemplate and
// internalTemplate.
func NewInternalIdentity(identityTemplate Identity, internalTemplate Internal) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
}
internal, err := NewInternal(internalTemplate)
if err != nil {
return nil, err
}
id.Identity.Internal = *internal
id.Identity.Type = "Internal"
return id, nil
}
// NewSystemIdentity will build and return a fully populated System identity
// record, using any values that are present in identityTemplate and
// systemTemplate.
func NewSystemIdentity(identityTemplate Identity, systemTemplate System) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
}
system, err := NewSystem(systemTemplate)
if err != nil {
return nil, err
}
id.Identity.System = system
id.Identity.Type = "System"
id.Identity.Internal = identity.Internal{
OrgID: id.Identity.OrgID,
}
return id, nil
}
// NewX509Identity will build and return a fully populated X509 identity record,
// using any values that are present in identityTemplate and x509Template.
func NewX509Identity(identityTemplate Identity, x509Template X509) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
}
x509, err := NewX509(x509Template)
if err != nil {
return nil, err
}
id.Identity.X509 = x509
id.Identity.Type = "X509"
return id, nil
}
// NewUserIdentity will build and return a fully populated User identity record,
// using any values that are present in identityTemplate and userTemplate.
func NewUserIdentity(identityTemplate Identity, userTemplate User) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
}
user, err := NewUser(userTemplate)
if err != nil {
return nil, err
}
id.Identity.User = user
id.Identity.Type = "User"
id.Identity.Internal = identity.Internal{
OrgID: id.Identity.OrgID,
}
return id, nil
}
// NewServiceAccountIdentity will build and return a fully populated
// ServiceAccount identity record, using any values that are present in
// identityTemplate and serviceAccountTemplate.
func NewServiceAccountIdentity(identityTemplate Identity, serviceAccountTemplate ServiceAccount) (*identity.XRHID, error) {
id, err := NewIdentity(identityTemplate)
if err != nil {
return nil, err
}
serviceAccount, err := NewServiceAccount(serviceAccountTemplate)
if err != nil {
return nil, err
}
id.Identity.ServiceAccount = serviceAccount
id.Identity.Type = "ServiceAccount"
return id, nil
}