-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgroups.py
63 lines (54 loc) · 2.06 KB
/
groups.py
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
import okta_api
def import_groups(filename):
"""CSV should have this header:
name,description
"""
groups = okta_api.import_csv(filename)
for group in groups:
okta_api.new_group({'profile': group})
def add_users_to_group(filename, groupid):
users = okta_api.import_csv(filename)
for user in users:
res = okta_api.add_group_member(groupid, user['id'])
if not res.ok:
error = res.json()
print('error:', error['errorSummary'])
def update_groups():
groups = okta_api.get_groups(q='a api group').json()
for group in groups:
print(group['profile']['name'], group['profile']['description'])
group['profile']['description'] = 'new desc'
okta_api.update_group(group['id'], group)
def new_okta_group():
group = {'profile': {'name': 'aa python group'}} # ...
okta_api.new_group(group)
def export_group_ids(filename):
groups = okta_api.get_groups(q='z group', limit=3).json()
okta_api.export_csv(filename, groups, ['id'])
def export_groups():
groups = okta_api.get_groups(q='z group', limit=3).json()
if not groups:
print('0 groups found.')
return
flat_groups = [
{
'id': group['id'],
'name': group['profile']['name'],
'description': group['profile']['description']
}
for group in groups
]
okta_api.export_csv(filename, flat_groups, flat_groups[0].keys())
def delete_groups(filename):
for group in okta_api.import_csv(filename):
okta_api.delete_group(group['id'])
def search_groups():
"""Local search"""
for group in okta_api.get_groups().json():
if group['profile']['description'] == 'test':
print(group['id'], group['profile']['name'])
def search_okta_groups():
userid = okta_api.get_user('me').json()['id']
for group in okta_api.get_groups(q='grp-atlassian').json():
print(group['id'], group['profile']['name'])
okta_api.add_group_member(group['id'], userid)