-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
309 lines (280 loc) · 14 KB
/
model.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
package azure
import (
"errors"
"strings"
"time"
)
type GroupsListResponse struct {
OdataContext string `json:"@odata.context"`
OdataNextLink string `json:"@odata.nextLink"`
Value []struct {
ID string `json:"id"`
DeletedDateTime interface{} `json:"deletedDateTime"`
Classification interface{} `json:"classification"`
CreatedDateTime time.Time `json:"createdDateTime"`
CreationOptions []interface{} `json:"creationOptions"`
Description string `json:"description"`
DisplayName string `json:"displayName"`
ExpirationDateTime interface{} `json:"expirationDateTime"`
GroupTypes []interface{} `json:"groupTypes"`
IsAssignableToRole interface{} `json:"isAssignableToRole"`
Mail interface{} `json:"mail"`
MailEnabled bool `json:"mailEnabled"`
MailNickname string `json:"mailNickname"`
MembershipRule interface{} `json:"membershipRule"`
MembershipRuleProcessingState interface{} `json:"membershipRuleProcessingState"`
OnPremisesDomainName string `json:"onPremisesDomainName"`
OnPremisesLastSyncDateTime time.Time `json:"onPremisesLastSyncDateTime"`
OnPremisesNetBiosName string `json:"onPremisesNetBiosName"`
OnPremisesSamAccountName string `json:"onPremisesSamAccountName"`
OnPremisesSecurityIdentifier string `json:"onPremisesSecurityIdentifier"`
OnPremisesSyncEnabled bool `json:"onPremisesSyncEnabled"`
PreferredDataLocation interface{} `json:"preferredDataLocation"`
PreferredLanguage interface{} `json:"preferredLanguage"`
ProxyAddresses []interface{} `json:"proxyAddresses"`
RenewedDateTime time.Time `json:"renewedDateTime"`
ResourceBehaviorOptions []interface{} `json:"resourceBehaviorOptions"`
ResourceProvisioningOptions []interface{} `json:"resourceProvisioningOptions"`
SecurityEnabled bool `json:"securityEnabled"`
SecurityIdentifier string `json:"securityIdentifier"`
Theme interface{} `json:"theme"`
Visibility interface{} `json:"visibility"`
OnPremisesProvisioningErrors []interface{} `json:"onPremisesProvisioningErrors"`
} `json:"value"`
}
type GroupMembers struct {
OdataContext string `json:"@odata.context"`
Value []struct {
OdataType string `json:"@odata.type"`
ID string `json:"id"`
BusinessPhones []interface{} `json:"businessPhones"`
DisplayName string `json:"displayName"`
GivenName string `json:"givenName"`
JobTitle string `json:"jobTitle"`
Mail string `json:"mail"`
MobilePhone string `json:"mobilePhone"`
OfficeLocation interface{} `json:"officeLocation"`
PreferredLanguage interface{} `json:"preferredLanguage"`
Surname string `json:"surname"`
UserPrincipalName string `json:"userPrincipalName"`
} `json:"value"`
}
type GetAdministrativeUnitsResponse struct {
OdataContext string `json:"@odata.context"`
Value []*GetAdministrativeUnitsResponseUnit `json:"value"`
}
type CreateAdministrativeUnitGroupRequest struct {
OdataType string `json:"@odata.type"`
Description string `json:"description"`
DisplayName string `json:"displayName"`
MailNickname string `json:"mailNickname"`
GroupTypes []interface{} `json:"groupTypes"`
MailEnabled bool `json:"mailEnabled"`
SecurityEnabled bool `json:"securityEnabled"`
ParentAdministrativeUnitId string `json:"-"`
}
type AddGroupMemberRequest struct {
OdataId string `json:"@odata.id"`
}
type GetUserViaUPNResponse struct {
OdataContext string `json:"@odata.context"`
BusinessPhones []interface{} `json:"businessPhones"`
DisplayName string `json:"displayName"`
GivenName string `json:"givenName"`
JobTitle string `json:"jobTitle"`
Mail string `json:"mail"`
MobilePhone interface{} `json:"mobilePhone"`
OfficeLocation interface{} `json:"officeLocation"`
PreferredLanguage interface{} `json:"preferredLanguage"`
Surname string `json:"surname"`
UserPrincipalName string `json:"userPrincipalName"`
ID string `json:"id"`
}
type CreateAdministrativeUnitGroupResponse struct {
OdataContext string `json:"@odata.context"`
OdataType string `json:"@odata.type"`
ID string `json:"id"`
DeletedDateTime interface{} `json:"deletedDateTime"`
Classification interface{} `json:"classification"`
CreatedDateTime time.Time `json:"createdDateTime"`
CreationOptions []interface{} `json:"creationOptions"`
Description string `json:"description"`
DisplayName string `json:"displayName"`
ExpirationDateTime interface{} `json:"expirationDateTime"`
GroupTypes []interface{} `json:"groupTypes"`
IsAssignableToRole interface{} `json:"isAssignableToRole"`
Mail interface{} `json:"mail"`
MailEnabled bool `json:"mailEnabled"`
MailNickname string `json:"mailNickname"`
MembershipRule interface{} `json:"membershipRule"`
MembershipRuleProcessingState interface{} `json:"membershipRuleProcessingState"`
OnPremisesDomainName interface{} `json:"onPremisesDomainName"`
OnPremisesLastSyncDateTime interface{} `json:"onPremisesLastSyncDateTime"`
OnPremisesNetBiosName interface{} `json:"onPremisesNetBiosName"`
OnPremisesSamAccountName interface{} `json:"onPremisesSamAccountName"`
OnPremisesSecurityIdentifier interface{} `json:"onPremisesSecurityIdentifier"`
OnPremisesSyncEnabled interface{} `json:"onPremisesSyncEnabled"`
PreferredDataLocation interface{} `json:"preferredDataLocation"`
PreferredLanguage interface{} `json:"preferredLanguage"`
ProxyAddresses []interface{} `json:"proxyAddresses"`
RenewedDateTime time.Time `json:"renewedDateTime"`
ResourceBehaviorOptions []interface{} `json:"resourceBehaviorOptions"`
ResourceProvisioningOptions []interface{} `json:"resourceProvisioningOptions"`
SecurityEnabled bool `json:"securityEnabled"`
SecurityIdentifier string `json:"securityIdentifier"`
Theme interface{} `json:"theme"`
Visibility interface{} `json:"visibility"`
OnPremisesProvisioningErrors []interface{} `json:"onPremisesProvisioningErrors"`
}
type GetAdministrativeUnitsResponseUnit struct {
ID string `json:"id"`
DeletedDateTime interface{} `json:"deletedDateTime"`
DisplayName string `json:"displayName"`
Description string `json:"description"`
MembershipRule interface{} `json:"membershipRule"`
MembershipType interface{} `json:"membershipType"`
MembershipRuleProcessingState interface{} `json:"membershipRuleProcessingState"`
Visibility interface{} `json:"visibility"`
}
func (g *GetAdministrativeUnitsResponse) GetUnit(name string) *GetAdministrativeUnitsResponseUnit {
for _, aUnit := range g.Value {
if aUnit.DisplayName == name {
return aUnit
}
}
return nil
}
type GetAdministrativeUnitMembersResponse struct {
OdataContext string `json:"@odata.context"`
OdataNextLink string `json:"@odata.nextLink,omitempty"`
Value []GetAdministrativeUnitMembersResponseUnit `json:"value"`
}
type GetAdministrativeUnitMembersResponseUnit struct {
OdataType string `json:"@odata.type"`
ID string `json:"id"`
DeletedDateTime interface{} `json:"deletedDateTime"`
Classification interface{} `json:"classification"`
CreatedDateTime time.Time `json:"createdDateTime"`
CreationOptions []interface{} `json:"creationOptions"`
Description interface{} `json:"description"`
DisplayName string `json:"displayName"`
ExpirationDateTime interface{} `json:"expirationDateTime"`
GroupTypes []interface{} `json:"groupTypes"`
IsAssignableToRole interface{} `json:"isAssignableToRole"`
Mail interface{} `json:"mail"`
MailEnabled bool `json:"mailEnabled"`
MailNickname string `json:"mailNickname"`
MembershipRule interface{} `json:"membershipRule"`
MembershipRuleProcessingState interface{} `json:"membershipRuleProcessingState"`
OnPremisesDomainName interface{} `json:"onPremisesDomainName"`
OnPremisesLastSyncDateTime interface{} `json:"onPremisesLastSyncDateTime"`
OnPremisesNetBiosName interface{} `json:"onPremisesNetBiosName"`
OnPremisesSamAccountName interface{} `json:"onPremisesSamAccountName"`
OnPremisesSecurityIdentifier interface{} `json:"onPremisesSecurityIdentifier"`
OnPremisesSyncEnabled interface{} `json:"onPremisesSyncEnabled"`
PreferredDataLocation interface{} `json:"preferredDataLocation"`
PreferredLanguage interface{} `json:"preferredLanguage"`
ProxyAddresses []interface{} `json:"proxyAddresses"`
RenewedDateTime time.Time `json:"renewedDateTime"`
ResourceBehaviorOptions []interface{} `json:"resourceBehaviorOptions"`
ResourceProvisioningOptions []interface{} `json:"resourceProvisioningOptions"`
SecurityEnabled bool `json:"securityEnabled"`
SecurityIdentifier string `json:"securityIdentifier"`
Theme interface{} `json:"theme"`
Visibility interface{} `json:"visibility"`
OnPremisesProvisioningErrors []interface{} `json:"onPremisesProvisioningErrors"`
}
type GetApplicationRolesResponse struct {
OdataContext string `json:"@odata.context"`
Value []struct {
DisplayName string `json:"displayName"`
AppID string `json:"appId"`
AppRoles []struct {
AllowedMemberTypes []string `json:"allowedMemberTypes"`
Description string `json:"description"`
DisplayName string `json:"displayName"`
ID string `json:"id"`
IsEnabled bool `json:"isEnabled"`
Origin string `json:"origin"`
Value interface{} `json:"value"`
} `json:"appRoles"`
} `json:"value"`
}
func (g *GetApplicationRolesResponse) GetRoleId(name string) (string, error) {
if len(g.Value) != 1 {
return "", errors.New("too many application entries returned, only expected one")
}
app := g.Value[0]
for _, role := range app.AppRoles {
if role.DisplayName == name {
return role.ID, nil
}
}
return "", errors.New("application role not found")
}
type AssignGroupToApplicationRequest struct {
PrincipalID string `json:"principalId"`
ResourceID string `json:"resourceId"`
AppRoleID string `json:"appRoleId"`
}
type AssignGroupToApplicationResponse struct {
OdataContext string `json:"@odata.context"`
ID string `json:"id"`
DeletedDateTime interface{} `json:"deletedDateTime"`
AppRoleID string `json:"appRoleId"`
CreatedDateTime time.Time `json:"createdDateTime"`
PrincipalDisplayName string `json:"principalDisplayName"`
PrincipalID string `json:"principalId"`
PrincipalType string `json:"principalType"`
ResourceDisplayName string `json:"resourceDisplayName"`
ResourceID string `json:"resourceId"`
}
type GetAssignmentsForApplicationResponse struct {
OdataContext string `json:"@odata.context"`
OdataNextLink string `json:"@odata.nextLink,omitempty"`
Value []*GetAssignmentsForApplicationResponseAssignment `json:"value"`
}
type GetAssignmentsForApplicationResponseAssignment struct {
ID string `json:"id"`
CreationTimestamp time.Time `json:"creationTimestamp"`
AppRoleID string `json:"appRoleId"`
PrincipalDisplayName string `json:"principalDisplayName"`
PrincipalID string `json:"principalId"`
PrincipalType string `json:"principalType"`
ResourceDisplayName string `json:"resourceDisplayName"`
ResourceID string `json:"resourceId"`
}
func (g *GetAssignmentsForApplicationResponse) ContainsGroup(name string) bool {
for _, assignment := range g.Value {
if assignment.PrincipalDisplayName == name {
return true
}
}
return false
}
func (g *GetAssignmentsForApplicationResponse) GetAssignmentByGroupName(name string) *GetAssignmentsForApplicationResponseAssignment {
for _, assignment := range g.Value {
if assignment.PrincipalDisplayName == name {
return assignment
}
}
return nil
}
type Group struct {
ID string `json:"id"`
DisplayName string `json:"displayName"`
Members []*Member `json:"members"`
}
func (g *Group) HasMember(email string) bool {
for _, member := range g.Members {
if strings.ToLower(member.UserPrincipalName) == strings.ToLower(email) {
return true
}
}
return false
}
type Member struct {
ID string `json:"id"`
DisplayName string `json:"displayName"`
UserPrincipalName string `json:"userPrincipalName"`
}