-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
262 lines (213 loc) · 8.33 KB
/
main.py
File metadata and controls
262 lines (213 loc) · 8.33 KB
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
# main.py
import json
from graph_users import (
create_user,
get_user,
list_users,
update_user,
disable_user,
delete_user
)
from graph_groups import (
create_group,
get_group,
list_groups,
delete_group,
add_user_to_group,
remove_user_from_group,
get_group_id_by_display_name
)
from graph_licenses import (
list_skus,
get_user_licenses,
assign_license,
remove_license
)
from graph_roles import (
list_directory_roles,
get_role_members,
assign_role,
remove_role
)
def pretty_print(data):
"""Clean JSON formatting for consistent CLI output."""
print(json.dumps(data, indent=4))
def menu():
print("\n==============================")
print(" IAM AUTOMATION TOOL")
print("==============================")
print("[1] Create User")
print("[2] Get User")
print("[3] List Users")
print("[4] Update User")
print("[5] Disable User")
print("[6] Delete User")
print("------------------------------")
print("[7] Create Group")
print("[8] List Groups")
print("[9] Add User to Group")
print("[10] Remove User from Group")
print("[11] Delete Group")
print("------------------------------")
print("[12] List License SKUs")
print("[13] Get User Licenses")
print("[14] Assign License to User")
print("[15] Remove License from User")
print("------------------------------")
print("[16] List Directory Roles")
print("[17] Get Role Members")
print("[18] Assign Role to User")
print("[19] Remove Role from User")
print("------------------------------")
print("[20] User Creation Wizard")
print("------------------------------")
print("[30] Process Workday HR Feed")
print("------------------------------")
print("[0] Exit")
print("==============================")
return input("Select an option: ").strip()
def main():
while True:
choice = menu()
# -------------------------
# USER OPERATIONS
# -------------------------
if choice == "1":
print("\n--- Create User ---")
first = input("First name: ").strip()
last = input("Last name: ").strip()
password = input("Temporary password: ").strip()
pretty_print(create_user(first, last, password))
elif choice == "2":
print("\n--- Get User ---")
upn = input("Enter UPN or Object ID: ").strip()
pretty_print(get_user(upn))
elif choice == "3":
print("\n--- List Users ---")
top = input("How many users to list (default 25): ").strip()
top = int(top) if top.isdigit() else 25
pretty_print(list_users(top))
elif choice == "4":
print("\n--- Update User ---")
upn = input("Enter UPN or Object ID: ").strip()
field = input("Field to update (e.g., displayName): ").strip()
value = input("New value: ").strip()
pretty_print(update_user(upn, {field: value}))
elif choice == "5":
print("\n--- Disable User ---")
upn = input("Enter UPN or Object ID: ").strip()
pretty_print(disable_user(upn))
elif choice == "6":
print("\n--- Delete User ---")
upn = input("Enter UPN or Object ID: ").strip()
pretty_print(delete_user(upn))
# -------------------------
# GROUP OPERATIONS
# -------------------------
elif choice == "7":
print("\n--- Create Group ---")
name = input("Group display name: ").strip()
desc = input("Description (optional): ").strip()
pretty_print(create_group(name, desc))
elif choice == "8":
print("\n--- List Groups ---")
top = input("How many groups to list (default 25): ").strip()
top = int(top) if top.isdigit() else 25
pretty_print(list_groups(top))
elif choice == "9":
print("\n--- Add User to Group ---")
user_id = input("User Object ID: ").strip()
group_name = input("Group display name: ").strip()
group_id = get_group_id_by_display_name(group_name)
if not group_id:
print(f"\nGroup '{group_name}' not found.")
else:
pretty_print(add_user_to_group(user_id, group_id))
elif choice == "10":
print("\n--- Remove User from Group ---")
user_id = input("User Object ID: ").strip()
group_name = input("Group display name: ").strip()
group_id = get_group_id_by_display_name(group_name)
if not group_id:
print(f"\nGroup '{group_name}' not found.")
else:
pretty_print(remove_user_from_group(user_id, group_id))
elif choice == "11":
print("\n--- Delete Group ---")
group_name = input("Group display name: ").strip()
group_id = get_group_id_by_display_name(group_name)
if not group_id:
print(f"\nGroup '{group_name}' not found.")
else:
pretty_print(delete_group(group_id))
# -------------------------
# LICENSE OPERATIONS
# -------------------------
elif choice == "12":
print("\n--- List License SKUs ---")
pretty_print(list_skus())
elif choice == "13":
print("\n--- Get User Licenses ---")
user_id = input("User Object ID: ").strip()
pretty_print(get_user_licenses(user_id))
elif choice == "14":
print("\n--- Assign License to User ---")
user_id = input("User Object ID: ").strip()
sku_name = input("SKU Name (e.g., AAD_PREMIUM_P1): ").strip()
pretty_print(assign_license(user_id, sku_name))
elif choice == "15":
print("\n--- Remove License from User ---")
user_id = input("User Object ID: ").strip()
sku_name = input("SKU Name (e.g., AAD_PREMIUM_P1): ").strip()
pretty_print(remove_license(user_id, sku_name))
# -------------------------
# ROLE OPERATIONS
# -------------------------
elif choice == "16":
print("\n--- List Directory Roles ---")
pretty_print(list_directory_roles())
elif choice == "17":
print("\n--- Get Role Members ---")
role_name = input("Role name (e.g., Global Reader): ").strip()
roles = list_directory_roles()
role_id = roles["roles"].get(role_name)
if not role_id:
print(f"\nRole '{role_name}' not found.")
else:
pretty_print(get_role_members(role_id))
elif choice == "18":
print("\n--- Assign Role to User ---")
user_id = input("User Object ID: ").strip()
role_name = input("Role name (e.g., Global Reader): ").strip()
pretty_print(assign_role(user_id, role_name))
elif choice == "19":
print("\n--- Remove Role from User ---")
user_id = input("User Object ID: ").strip()
role_name = input("Role name (e.g., Global Reader): ").strip()
pretty_print(remove_role(user_id, role_name))
elif choice == "20":
from user_wizard import user_creation_wizard
summary = user_creation_wizard()
pretty_print(summary)
elif choice == "30":
from hr.workday_feed import load_workday_feed
from hr.workday_events import detect_event
from hr.provision_new_hire import process_new_hire
feed = load_workday_feed()
for record in feed:
event = detect_event(record)
if event == "NewHire":
summary = process_new_hire(record)
pretty_print(summary)
elif event == "Update":
from hr.provision_update import process_update
entra_user = get_user(record["employeeId"])
summary = process_update(record, entra_user)
pretty_print(summary)
elif choice == "0":
print("\nExiting IAM Automation Tool. Goodbye.")
break
else:
print("\nInvalid option. Please try again.")
if __name__ == "__main__":
main()