-
Notifications
You must be signed in to change notification settings - Fork 70
/
iam.go
426 lines (335 loc) · 19.3 KB
/
iam.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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
// Package iam provides access to the Akamai Property APIs
package iam
import (
"context"
"errors"
"github.com/akamai/AkamaiOPEN-edgegrid-golang/v9/pkg/session"
)
var (
// ErrStructValidation is returned when given struct validation failed
ErrStructValidation = errors.New("struct validation")
)
type (
// IAM is the IAM api interface
IAM interface {
// API Clients
// LockAPIClient locks an API client based on `ClientID` parameter. If `ClientID` is not provided, it locks your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-lock-api-client, https://techdocs.akamai.com/iam-api/reference/put-lock-api-client-self
LockAPIClient(ctx context.Context, params LockAPIClientRequest) (*LockAPIClientResponse, error)
// UnlockAPIClient unlocks an API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-unlock-api-client
UnlockAPIClient(ctx context.Context, params UnlockAPIClientRequest) (*UnlockAPIClientResponse, error)
// ListAPIClients lists API clients an administrator can manage.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-api-clients
ListAPIClients(ctx context.Context, params ListAPIClientsRequest) (ListAPIClientsResponse, error)
// GetAPIClient provides details about an API client. If `ClientID` is not provided, it returns details about your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-api-client and https://techdocs.akamai.com/iam-api/reference/get-api-client-self
GetAPIClient(ctx context.Context, params GetAPIClientRequest) (*GetAPIClientResponse, error)
// CreateAPIClient creates a new API client. Optionally, it can automatically assign a credential for the client when creating it.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-api-clients
CreateAPIClient(ctx context.Context, params CreateAPIClientRequest) (*CreateAPIClientResponse, error)
// UpdateAPIClient updates an API client. If `ClientID` is not provided, it updates your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-api-clients and https://techdocs.akamai.com/iam-api/reference/put-api-clients-self
UpdateAPIClient(ctx context.Context, params UpdateAPIClientRequest) (*UpdateAPIClientResponse, error)
// DeleteAPIClient permanently deletes the API client, breaking any API connections with the client.
// If `ClientID` is not provided, it deletes your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/delete-api-client and https://techdocs.akamai.com/iam-api/reference/delete-api-client-self
DeleteAPIClient(ctx context.Context, params DeleteAPIClientRequest) error
// API Client Credentials
// CreateCredential creates a new credential for the API client. If `ClientID` is not provided, it creates credential for your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-self-credentials, https://techdocs.akamai.com/iam-api/reference/post-client-credentials
CreateCredential(context.Context, CreateCredentialRequest) (*CreateCredentialResponse, error)
// ListCredentials lists credentials for an API client. If `ClientID` is not provided, it lists credentials for your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-self-credentials, https://techdocs.akamai.com/iam-api/reference/get-client-credentials
ListCredentials(context.Context, ListCredentialsRequest) (ListCredentialsResponse, error)
// GetCredential returns details about a specific credential for an API client. If `ClientID` is not provided, it gets credential for your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-self-credential, https://techdocs.akamai.com/iam-api/reference/get-client-credential
GetCredential(context.Context, GetCredentialRequest) (*GetCredentialResponse, error)
// UpdateCredential updates a specific credential for an API client. If `ClientID` is not provided, it updates credential for your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-self-credential, https://techdocs.akamai.com/iam-api/reference/put-client-credential
UpdateCredential(context.Context, UpdateCredentialRequest) (*UpdateCredentialResponse, error)
// DeleteCredential deletes a specific credential from an API client. If `ClientID` is not provided, it deletes credential for your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/delete-self-credential, https://techdocs.akamai.com/iam-api/reference/delete-client-credential
DeleteCredential(context.Context, DeleteCredentialRequest) error
// DeactivateCredential deactivates a specific credential for an API client. If `ClientID` is not provided, it deactivates credential for your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-self-credential-deactivate, https://techdocs.akamai.com/iam-api/reference/post-client-credential-deactivate
DeactivateCredential(context.Context, DeactivateCredentialRequest) error
// DeactivateCredentials deactivates all credentials for a specific API client. If `ClientID` is not provided, it deactivates all credentials for your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-self-credentials-deactivate, https://techdocs.akamai.com/iam-api/reference/post-client-credentials-deactivate
DeactivateCredentials(context.Context, DeactivateCredentialsRequest) error
// Blocked Properties
// ListBlockedProperties returns all properties a user doesn't have access to in a group.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-blocked-properties
ListBlockedProperties(context.Context, ListBlockedPropertiesRequest) ([]int64, error)
// UpdateBlockedProperties removes or grants user access to properties.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-blocked-properties
UpdateBlockedProperties(context.Context, UpdateBlockedPropertiesRequest) ([]int64, error)
// CIDR Blocks
// ListCIDRBlocks lists all CIDR blocks on selected account's allowlist.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-allowlist
ListCIDRBlocks(context.Context, ListCIDRBlocksRequest) (ListCIDRBlocksResponse, error)
// CreateCIDRBlock adds CIDR blocks to your account's allowlist.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-allowlist
CreateCIDRBlock(context.Context, CreateCIDRBlockRequest) (*CreateCIDRBlockResponse, error)
// GetCIDRBlock retrieves a CIDR block's details.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-allowlist-cidrblockid
GetCIDRBlock(context.Context, GetCIDRBlockRequest) (*GetCIDRBlockResponse, error)
// UpdateCIDRBlock modifies an existing CIDR block.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-allowlist-cidrblockid
UpdateCIDRBlock(context.Context, UpdateCIDRBlockRequest) (*UpdateCIDRBlockResponse, error)
// DeleteCIDRBlock deletes an existing CIDR block from the IP allowlist.
//
// See: https://techdocs.akamai.com/iam-api/reference/delete-allowlist-cidrblockid
DeleteCIDRBlock(context.Context, DeleteCIDRBlockRequest) error
// ValidateCIDRBlock checks the format of CIDR block.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-allowlist-validate
ValidateCIDRBlock(context.Context, ValidateCIDRBlockRequest) error
// Groups
// CreateGroup creates a new group within a parent group_id specified in the request.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-group
CreateGroup(context.Context, GroupRequest) (*Group, error)
// GetGroup returns a group's details.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-group
GetGroup(context.Context, GetGroupRequest) (*Group, error)
// ListAffectedUsers lists users who are affected when a group is moved.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-move-affected-users
ListAffectedUsers(context.Context, ListAffectedUsersRequest) ([]GroupUser, error)
// ListGroups lists all groups in which you have a scope of admin for the current account and contract type.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-groups
ListGroups(context.Context, ListGroupsRequest) ([]Group, error)
// RemoveGroup removes a group based on group_id. We can only delete a sub-group, and only if that sub-group doesn't include any users.
//
// See: https://techdocs.akamai.com/iam-api/reference/delete-group
RemoveGroup(context.Context, RemoveGroupRequest) error
// UpdateGroupName changes the name of the group.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-group
UpdateGroupName(context.Context, GroupRequest) (*Group, error)
// MoveGroup moves a nested group under another group within the same parent hierarchy.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-groups-move
MoveGroup(context.Context, MoveGroupRequest) error
// Helpers
// ListAllowedCPCodes lists available CP codes for a user.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-api-clients-users-allowed-cpcodes
ListAllowedCPCodes(context.Context, ListAllowedCPCodesRequest) (ListAllowedCPCodesResponse, error)
// ListAuthorizedUsers lists authorized API client users.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-api-clients-users
ListAuthorizedUsers(context.Context) (ListAuthorizedUsersResponse, error)
// ListAllowedAPIs lists available APIs for a user.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-api-clients-users-allowed-apis
ListAllowedAPIs(context.Context, ListAllowedAPIsRequest) (ListAllowedAPIsResponse, error)
// ListAccessibleGroups lists groups available to a user.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-api-clients-users-group-access
ListAccessibleGroups(context.Context, ListAccessibleGroupsRequest) (ListAccessibleGroupsResponse, error)
// IP Allowlist
// DisableIPAllowlist disables IP allowlist on your account. After you disable IP allowlist,
// users can access Control Center regardless of their IP address or who assigns it.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-allowlist-disable
DisableIPAllowlist(context.Context) error
// EnableIPAllowlist enables IP allowlist on your account. Before you enable IP allowlist,
// add at least one IP address to allow access to Control Center.
// The allowlist can't be empty with IP allowlist enabled.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-allowlist-enable
EnableIPAllowlist(context.Context) error
// GetIPAllowlistStatus indicates whether IP allowlist is enabled or disabled on your account.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-allowlist-status
GetIPAllowlistStatus(context.Context) (*GetIPAllowlistStatusResponse, error)
// Properties
// ListProperties lists the properties for the current account or other managed accounts using the accountSwitchKey parameter.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-properties
ListProperties(context.Context, ListPropertiesRequest) (ListPropertiesResponse, error)
// ListUsersForProperty lists users who can access a property.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-property-users
ListUsersForProperty(context.Context, ListUsersForPropertyRequest) (ListUsersForPropertyResponse, error)
// GetProperty lists a property's details.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-property
GetProperty(context.Context, GetPropertyRequest) (*GetPropertyResponse, error)
// MoveProperty moves a property from one group to another group.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-property
MoveProperty(context.Context, MovePropertyRequest) error
// MapPropertyIDToName returns property name for given (IAM) property ID
// Mainly to be used to map (IAM) Property ID to (PAPI) Property ID
// To finish the mapping, please use papi.MapPropertyNameToID
MapPropertyIDToName(context.Context, MapPropertyIDToNameRequest) (*string, error)
// BlockUsers blocks the users on a property.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-property-users-block
BlockUsers(context.Context, BlockUsersRequest) (*BlockUsersResponse, error)
// Roles
// CreateRole creates a custom role.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-role
CreateRole(context.Context, CreateRoleRequest) (*Role, error)
// GetRole gets details for a specific role.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-role
GetRole(context.Context, GetRoleRequest) (*Role, error)
// UpdateRole adds or removes permissions from a role and updates other parameters.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-role
UpdateRole(context.Context, UpdateRoleRequest) (*Role, error)
// DeleteRole deletes a role. This operation is only allowed if the role isn't assigned to any users.
//
// See: https://techdocs.akamai.com/iam-api/reference/delete-role
DeleteRole(context.Context, DeleteRoleRequest) error
// ListRoles lists roles for the current account and contract type.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-roles
ListRoles(context.Context, ListRolesRequest) ([]Role, error)
// ListGrantableRoles lists which grantable roles can be included in a new custom role or added to an existing custom role.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-grantable-roles
ListGrantableRoles(context.Context) ([]RoleGrantedRole, error)
// Support
// GetPasswordPolicy gets the password policy for the account.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-common-password-policy
GetPasswordPolicy(ctx context.Context) (*GetPasswordPolicyResponse, error)
// ListProducts lists products a user can subscribe to and receive notifications for on the account.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-common-notification-products
ListProducts(context.Context) ([]string, error)
// ListStates lists U.S. states or Canadian provinces.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-common-states
ListStates(context.Context, ListStatesRequest) ([]string, error)
// ListTimeoutPolicies lists all the possible session timeout policies.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-common-timeout-policies
ListTimeoutPolicies(context.Context) ([]TimeoutPolicy, error)
// ListAccountSwitchKeys lists account switch keys available for a specific API client. If `ClientID` is not provided, it lists account switch keys available for your API client.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-client-account-switch-keys, https://techdocs.akamai.com/iam-api/reference/get-self-account-switch-keys
ListAccountSwitchKeys(context.Context, ListAccountSwitchKeysRequest) (ListAccountSwitchKeysResponse, error)
// SupportedContactTypes lists supported contact types.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-common-contact-types
SupportedContactTypes(context.Context) ([]string, error)
// SupportedCountries lists supported countries.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-common-countries
SupportedCountries(context.Context) ([]string, error)
// SupportedLanguages lists supported languages.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-common-languages
SupportedLanguages(context.Context) ([]string, error)
// SupportedTimezones lists supported timezones.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-common-timezones
SupportedTimezones(context.Context) ([]Timezone, error)
// Users
// LockUser locks the user.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-ui-identity-lock
LockUser(context.Context, LockUserRequest) error
// UnlockUser releases the lock on a user's account.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-ui-identity-unlock
UnlockUser(context.Context, UnlockUserRequest) error
// ResetUserPassword optionally sends a one-time use password to the user.
// If you send the email with the password directly to the user, the response for this operation doesn't include that password.
// If you don't send the password to the user through email, the password is included in the response.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-reset-password
ResetUserPassword(context.Context, ResetUserPasswordRequest) (*ResetUserPasswordResponse, error)
// SetUserPassword sets a specific password for a user.
//
// See: https://techdocs.akamai.com/iam-api/reference/post-set-password
SetUserPassword(context.Context, SetUserPasswordRequest) error
// CreateUser creates a user in the account specified in your own API client credentials or clone an existing user's role assignments.
//
// See: https://techdocs.akamai.com/iam-user-admin/reference/post-ui-identity
CreateUser(context.Context, CreateUserRequest) (*User, error)
// GetUser gets a specific user's profile.
//
// See: https://techdocs.akamai.com/iam-user-admin/reference/get-ui-identity
GetUser(context.Context, GetUserRequest) (*User, error)
// ListUsers returns a list of users who have access on this account.
//
// See: https://techdocs.akamai.com/iam-api/reference/get-ui-identities
ListUsers(context.Context, ListUsersRequest) ([]UserListItem, error)
// RemoveUser removes a user identity.
//
// See: https://techdocs.akamai.com/iam-api/reference/delete-ui-identity
RemoveUser(context.Context, RemoveUserRequest) error
// UpdateUserAuthGrants edits what groups a user has access to, and how the user can interact with the objects in those groups.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-ui-uiidentity-auth-grants
UpdateUserAuthGrants(context.Context, UpdateUserAuthGrantsRequest) ([]AuthGrant, error)
// UpdateUserInfo updates a user's information.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-ui-identity-basic-info
UpdateUserInfo(context.Context, UpdateUserInfoRequest) (*UserBasicInfo, error)
// UpdateUserNotifications subscribes or un-subscribes user to product notification emails.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-notifications
UpdateUserNotifications(context.Context, UpdateUserNotificationsRequest) (*UserNotifications, error)
// UpdateTFA updates a user's two-factor authentication setting and can reset tfa.
//
// See: https://techdocs.akamai.com/iam-user-admin/reference/put-ui-identity-tfa
/** @deprecated */
UpdateTFA(context.Context, UpdateTFARequest) error
// UpdateMFA updates a user's profile authentication method.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-user-profile-additional-authentication
UpdateMFA(context.Context, UpdateMFARequest) error
// ResetMFA resets a user's profile authentication method.
//
// See: https://techdocs.akamai.com/iam-api/reference/put-ui-identity-reset-additional-authentication
ResetMFA(context.Context, ResetMFARequest) error
}
iam struct {
session.Session
}
// Option defines a IAM option.
Option func(*iam)
// ClientFunc is an IAM client new method, this can be used for mocking.
ClientFunc func(sess session.Session, opts ...Option) IAM
)
// Client returns a new IAM Client instance with the specified controller.
func Client(sess session.Session, opts ...Option) IAM {
p := &iam{
Session: sess,
}
for _, opt := range opts {
opt(p)
}
return p
}