reverse-diagrams 1.3.3__py3-none-any.whl → 1.3.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
src/reports/tes.py DELETED
@@ -1,366 +0,0 @@
1
- """Describe Organizations."""
2
- import logging
3
- import os
4
-
5
- import emoji
6
- from colorama import Fore
7
-
8
- import json
9
- import logging
10
- from pathlib import Path
11
-
12
- from colorama import Fore
13
-
14
-
15
- def save_results(results, filename, directory_path="."):
16
- """
17
- Save results to a file.
18
-
19
- :param directory_path:
20
- :param results:
21
- :param filename:
22
-
23
- :return: None. Saves results to a file.
24
- """
25
- if not Path.exists(Path(directory_path)):
26
- Path.mkdir(Path(directory_path))
27
- logging.debug(f"Directory {directory_path} created")
28
- with open(f"{directory_path}/{filename}", "w") as f:
29
- json.dump(results, fp=f, indent=4)
30
- print(
31
- f"{Fore.YELLOW}ℹ️ The accounts are stored in {directory_path}/{filename} {Fore.RESET}"
32
- )
33
-
34
-
35
- def find_ou_name(ous, search_id):
36
- """
37
- Find OU Name in list.
38
-
39
- :param ous:
40
- :param search_id:
41
- :return:
42
- """
43
- for a in ous:
44
- if a["Id"] == search_id:
45
- return a["Name"]
46
-
47
-
48
- def find_ou_index(ous, search_id):
49
- """
50
- Find OU Name in list.
51
-
52
- :param ous:
53
- :param search_id:
54
- :return:
55
- """
56
- for a in ous:
57
- if a["Id"] == search_id:
58
- return a
59
-
60
-
61
- # search ou in map
62
- def search_ou_map(map_ou: dict, ou_id, level=0, tree="."):
63
- """
64
- Search OU in map.
65
-
66
- :param tree:
67
- :param level:
68
- :param map_ou:
69
- :param ou_id:
70
- :return:
71
- """
72
- for a in map_ou.keys():
73
- # print(f'Searching {ou_id}... in {map_ou[a]["nestedOus"]}')
74
-
75
- if len(map_ou[a]["nestedOus"]) > 0:
76
- level += 1
77
- tree += f".{a}"
78
-
79
- if ou_id in map_ou[a]["nestedOus"].keys():
80
- print(f"Find in {a}, for {ou_id}, level {level}")
81
- # search_ou_map(map_ou=map_ou[a]["nestedOus"], ou_id=ou_id, level=level, tree=tree)
82
-
83
- return map_ou[a]
84
- # else:
85
- # search_ou_map(map_ou=map_ou[a]["nestedOus"], ou_id=ou_id, level=level, tree=tree)
86
- return None
87
-
88
-
89
- def init_org_complete(root_id, org, list_ous, ):
90
- organizations_complete = {
91
- "rootId": root_id,
92
- "masterAccountId": org['MasterAccountId'],
93
- "noOutAccounts": [],
94
- "organizationalUnits": {}
95
- }
96
-
97
- # Iterate in ous for getting ous tree
98
- for a, i in zip(list_ous, range(len(list_ous))):
99
-
100
- for p in a["Parents"]:
101
- if p["Type"] == "ROOT":
102
- organizations_complete["organizationalUnits"][a['Name']] = {
103
- "Id": a['Id'],
104
- "Name": a['Name'],
105
- "accounts": {},
106
- "nestedOus": {}}
107
- return organizations_complete
108
-
109
-
110
- # create organization complete map
111
- def map_organizations_complete(organizations_complete: dict,
112
- list_ous, llist_accounts,
113
- reference_outs_list,
114
- ):
115
- """
116
- Create complete mapper file.
117
-
118
-
119
- :param reference_outs_list:
120
- :param organizations_complete:
121
- :param list_ous:
122
- :param llist_accounts:
123
- :return:
124
- """
125
-
126
- # Iterate in ous for getting ous tree
127
- for a, i in zip(list_ous, range(len(list_ous))):
128
-
129
- for p in a["Parents"]:
130
-
131
- if p["Type"] == "ORGANIZATIONAL_UNIT":
132
-
133
- o = find_ou_name(reference_outs_list, p['Id'])
134
-
135
- if o not in organizations_complete["organizationalUnits"].keys():
136
- print("Nested Ou", o)
137
- p = search_ou_map(organizations_complete["organizationalUnits"], ou_id=o)
138
- new_list_ous = p["nestedOus"]
139
-
140
- new_list_ous = plop_dict_out(ous_list=list_ous, ou=new_list_ous)
141
- organizations_complete = map_organizations_complete(organizations_complete=organizations_complete,
142
- list_ous=new_list_ous,
143
- llist_accounts=llist_accounts,
144
- reference_outs_list=reference_outs_list)
145
-
146
- else:
147
- organizations_complete["organizationalUnits"][o]["nestedOus"][
148
- find_ou_name(reference_outs_list, a['Id'])] = {
149
-
150
- "Id": a['Id'],
151
- "Name": a['Name'],
152
- "accounts": [],
153
- "nestedOus": {}
154
-
155
- }
156
- # print(organizations_complete["organizationalUnits"][o]["nestedOus"])
157
- if len(organizations_complete["organizationalUnits"][o]["nestedOus"]) > 0:
158
- new_list_ous = organizations_complete["organizationalUnits"][o]["nestedOus"]
159
-
160
- new_list_ous = plop_dict_out(ous_list=list_ous, ou=new_list_ous)
161
- organizations_complete = map_organizations_complete(
162
- organizations_complete=organizations_complete,
163
- list_ous=new_list_ous,
164
- llist_accounts=llist_accounts,
165
- reference_outs_list=reference_outs_list)
166
-
167
- return organizations_complete
168
-
169
-
170
- def plop_dict_out(ous_list: list, ou, ):
171
- """
172
- Clean list.
173
-
174
- :param ous_list:
175
- :param ou:
176
- :return:
177
- """
178
- for o in ou.keys():
179
-
180
- # for c in ou.keys():
181
- for unit in ous_list:
182
- if unit["Id"] == ou[o]["Id"]:
183
- ous_list.remove(unit)
184
-
185
- return ous_list
186
-
187
-
188
- def set_accounts_tree(llist_accounts, organizations_complete, list_ous):
189
- """
190
- Set accounts tree.
191
-
192
- :param llist_accounts:
193
- :param organizations_complete:
194
- :param list_ous:
195
- :return:
196
- """
197
- # Iterate in list accounts to get parent ous
198
- for c, i in zip(llist_accounts, range(len(llist_accounts))):
199
- # print(f"\n aa_{i}= OrganizationsAccount(\"{c['account']}\")", file=f)
200
- for p in c["parents"]:
201
- if p["Type"] == "ROOT":
202
- organizations_complete["noOutAccounts"].append(
203
- {
204
- "account": c["account"],
205
- "name": c['name']
206
- }
207
- )
208
-
209
- for o, j in zip(list_ous, range(len(list_ous))):
210
- if p["Id"] == o["Id"] and p["Type"] == "ORGANIZATIONAL_UNIT":
211
- organizations_complete["organizationalUnits"][find_ou_name(list_ous, o['Id'])]["accounts"][
212
- c['name']] = {
213
- "account": c["account"],
214
- "name": c['name']
215
- }
216
-
217
- return organizations_complete
218
-
219
-
220
- root = 'r-w3ow'
221
- org_data = {'Id': 'o-9tlhkjyoii', 'Arn': 'arn:aws:organizations::029921763173:organization/o-9tlhkjyoii',
222
- 'FeatureSet': 'ALL',
223
- 'MasterAccountArn': 'arn:aws:organizations::029921763173:account/o-9tlhkjyoii/029921763173',
224
- 'MasterAccountId': '029921763173',
225
- 'MasterAccountEmail': 'velez94@protonmail.com',
226
- 'AvailablePolicyTypes': [{'Type': 'SERVICE_CONTROL_POLICY', 'Status': 'ENABLED'}]}
227
-
228
- ous = [
229
- {'Id': 'ou-w3ow-oegm0al0',
230
- 'Arn': 'arn:aws:organizations::029921763173:ou/o-9tlhkjyoii/ou-w3ow-oegm0al0',
231
- 'Name': 'Research', 'Parents': [{'Id': 'r-w3ow', 'Type': 'ROOT'}]},
232
- {'Id': 'ou-w3ow-k24p2opx', 'Arn': 'arn:aws:organizations::029921763173:ou/o-9tlhkjyoii/ou-w3ow-k24p2opx',
233
- 'Name': 'Dev',
234
- 'Parents': [{'Id': 'r-w3ow', 'Type': 'ROOT'}]
235
- },
236
- {'Id': 'ou-w3ow-93hiq3zr', 'Arn': 'arn:aws:organizations::029921763173:ou/o-9tlhkjyoii/ou-w3ow-93hiq3zr',
237
- 'Name': 'Core',
238
- 'Parents': [{'Id': 'r-w3ow', 'Type': 'ROOT'}]
239
- },
240
- {'Id': 'ou-w3ow-5qsqi8b5', 'Arn': 'arn:aws:organizations::029921763173:ou/o-9tlhkjyoii/ou-w3ow-5qsqi8b5',
241
- 'Name': 'Custom', 'Parents': [{'Id': 'r-w3ow', 'Type': 'ROOT'}]},
242
- {'Id': 'ou-w3ow-w7dzhzcz', 'Arn': 'arn:aws:organizations::029921763173:ou/o-9tlhkjyoii/ou-w3ow-w7dzhzcz',
243
- 'Name': 'Shared', 'Parents': [{'Id': 'r-w3ow', 'Type': 'ROOT'}]},
244
- {'Id': 'ou-w3ow-i9xzgb9x', 'Arn': 'arn:aws:organizations::029921763173:ou/o-9tlhkjyoii/ou-w3ow-i9xzgb9x',
245
- 'Name': 'NetstedOU', 'Parents': [{'Id': 'ou-w3ow-5qsqi8b5', 'Type': 'ORGANIZATIONAL_UNIT'}]},
246
- {'Id': 'ou-w3ow-i9xzgxxx', 'Arn': 'arn:aws:organizations::029921763173:ou/o-9tlhkjyoii/ou-w3ow-i9xzxxxx',
247
- 'Name': 'NetstedOU2', 'Parents': [{'Id': 'ou-w3ow-5qsqi8b5', 'Type': 'ORGANIZATIONAL_UNIT'},
248
- {'Id': 'ou-w3ow-i9xzgb9x', 'Type': 'ORGANIZATIONAL_UNIT'}]},
249
- {'Id': 'ou-w3ow-i9xzgxx3', 'Arn': 'arn:aws:organizations::029921763173:ou/o-9tlhkjyoii/ou-w3ow-i9xzxxxx',
250
- 'Name': 'NetstedOU3', 'Parents': [{'Id': 'ou-w3ow-5qsqi8b5', 'Type': 'ORGANIZATIONAL_UNIT'},
251
- {'Id': 'ou-w3ow-i9xzgb9x', 'Type': 'ORGANIZATIONAL_UNIT'},
252
- {'Id': 'ou-w3ow-i9xzgxxx', 'Type': 'ORGANIZATIONAL_UNIT'}]}
253
-
254
- ]
255
-
256
- accounts = [
257
- {'account': '884478634998', 'name': 'Log archive',
258
- 'parents': [{'Id': 'ou-w3ow-93hiq3zr', 'Type': 'ORGANIZATIONAL_UNIT'}]},
259
- {'account': '582441254763', 'name': 'Prod',
260
- 'parents': [{'Id': 'ou-w3ow-5qsqi8b5', 'Type': 'ORGANIZATIONAL_UNIT'}]},
261
- {'account': '895882538541', 'name': 'Audit',
262
- 'parents': [{'Id': 'ou-w3ow-93hiq3zr', 'Type': 'ORGANIZATIONAL_UNIT'}]},
263
- {'account': '105171185823', 'name': 'DevSecOps',
264
- 'parents': [{'Id': 'ou-w3ow-w7dzhzcz', 'Type': 'ORGANIZATIONAL_UNIT'}]},
265
- {'account': '994261317734', 'name': 'LabVelCT',
266
- 'parents': [{'Id': 'ou-w3ow-k24p2opx', 'Type': 'ORGANIZATIONAL_UNIT'}]},
267
- {'account': '155794986228', 'name': 'SharedServices',
268
- 'parents': [{'Id': 'ou-w3ow-w7dzhzcz', 'Type': 'ORGANIZATIONAL_UNIT'}]},
269
- {'account': '029921763173', 'name': 'Alejandro Velez', 'parents': [{'Id': 'r-w3ow', 'Type': 'ROOT'}]},
270
- {'account': '571340586587', 'name': 'Dev',
271
- 'parents': [{'Id': 'ou-w3ow-k24p2opx', 'Type': 'ORGANIZATIONAL_UNIT'}]}]
272
-
273
- groups = [
274
- {'group_id': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097', 'group_name': 'AWSSecurityAuditors',
275
- 'members': []},
276
- {'group_id': '9a672b3314-c481fbee-8062-432a-8b87-eeaa36b763a8', 'group_name': 'AWSLogArchiveAdmins',
277
- 'members': []},
278
- {'group_id': '318bc590-a071-70f5-63f6-ab21233e4e33', 'group_name': 'DevSecOps_Admins', 'members': [
279
- {'IdentityStoreId': 'd-9a672b3314', 'MembershipId': '51bbe5a0-7001-7010-d7c0-46f5044d014e',
280
- 'GroupId': '318bc590-a071-70f5-63f6-ab21233e4e33',
281
- 'MemberId': {'UserId': '010be510-1061-70df-8274-96526bc47eb7', 'UserName': 'DevSecOpsAdm'}}]},
282
- {'group_id': '9a672b3314-ff479c57-03cb-440e-8902-be8ea9d7d25b', 'group_name': 'AWSLogArchiveViewers',
283
- 'members': []},
284
- {'group_id': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388', 'group_name': 'AWSSecurityAuditPowerUsers',
285
- 'members': []},
286
- {'group_id': '9a672b3314-faf36c54-a70c-4db6-aefc-e5ac006ad5a1', 'group_name': 'AWSAuditAccountAdmins',
287
- 'members': []},
288
- {'group_id': '9a672b3314-f8065505-3174-4d46-a1b4-f134fd0ca2fc', 'group_name': 'AWSAccountFactory', 'members': [
289
- {'IdentityStoreId': 'd-9a672b3314', 'MembershipId': 'e18bb590-9031-70a0-5469-42c9799e8a6b',
290
- 'GroupId': '9a672b3314-f8065505-3174-4d46-a1b4-f134fd0ca2fc',
291
- 'MemberId': {'UserId': '9a672b3314-bd21c8b3-1aa0-4922-9374-92321b4979bf',
292
- 'UserName': 'velez94@protonmail.com'}}]},
293
- {'group_id': '9a672b3314-7f743f07-169a-4172-bdbc-561e7908e463', 'group_name': 'AWSServiceCatalogAdmins',
294
- 'members': []},
295
- {'group_id': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199', 'group_name': 'AWSControlTowerAdmins',
296
- 'members': [
297
- {'IdentityStoreId': 'd-9a672b3314', 'MembershipId': 'e14b3500-3051-70b2-25b7-d5729d383061',
298
- 'GroupId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
299
- 'MemberId': {'UserId': '9a672b3314-bd21c8b3-1aa0-4922-9374-92321b4979bf',
300
- 'UserName': 'velez94@protonmail.com'}}]}]
301
-
302
- account_assignments = {'Master': [{'AccountId': '029921763173',
303
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
304
- 'PrincipalType': 'GROUP',
305
- 'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
306
- 'GroupName': 'AWSSecurityAuditPowerUsers',
307
- 'PermissionSetName': 'AWSPowerUserAccess'},
308
- {'AccountId': '029921763173',
309
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-7cc34a5a03379f6f',
310
- 'PrincipalType': 'GROUP',
311
- 'PrincipalId': '9a672b3314-f8065505-3174-4d46-a1b4-f134fd0ca2fc',
312
- 'GroupName': 'AWSAccountFactory',
313
- 'PermissionSetName': 'AWSServiceCatalogEndUserAccess'},
314
- {'AccountId': '029921763173',
315
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
316
- 'PrincipalType': 'GROUP',
317
- 'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
318
- 'GroupName': 'AWSControlTowerAdmins',
319
- 'PermissionSetName': 'AWSAdministratorAccess'},
320
- {'AccountId': '029921763173',
321
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
322
- 'PrincipalType': 'GROUP',
323
- 'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
324
- 'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'},
325
- {'AccountId': '029921763173',
326
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-83e7c23c8b2df8b3',
327
- 'PrincipalType': 'GROUP',
328
- 'PrincipalId': '9a672b3314-7f743f07-169a-4172-bdbc-561e7908e463',
329
- 'GroupName': 'AWSServiceCatalogAdmins',
330
- 'PermissionSetName': 'AWSServiceCatalogAdminFullAccess'}],
331
- 'DevSecOps': [
332
- {'AccountId': '105171185823',
333
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-ab185f05acde5e90',
334
- 'PrincipalType': 'GROUP',
335
- 'PrincipalId': '9a672b3314-b858476a-2ef9-4018-90e7-29e5e4bc4388',
336
- 'GroupName': 'AWSSecurityAuditPowerUsers', 'PermissionSetName': 'AWSPowerUserAccess'},
337
- {'AccountId': '105171185823',
338
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
339
- 'PrincipalType': 'GROUP', 'PrincipalId': '318bc590-a071-70f5-63f6-ab21233e4e33',
340
- 'GroupName': 'DevSecOps_Admins',
341
- 'PermissionSetName': 'AWSAdministratorAccess'},
342
- {'AccountId': '105171185823',
343
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-21058a9d1f62c7e2',
344
- 'PrincipalType': 'USER',
345
- 'PrincipalId': '81bb65b0-40f1-7082-2b16-83138563c37b',
346
- 'UserName': 'w.alejovl+devsecops-labs@gmail.com',
347
- 'PermissionSetName': 'AWSAdministratorAccess'},
348
- {'AccountId': '105171185823',
349
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-cf27b0efdc941a09',
350
- 'PrincipalType': 'GROUP',
351
- 'PrincipalId': '9a672b3314-f46f413e-44d7-4d3d-918b-f86721413097',
352
- 'GroupName': 'AWSSecurityAuditors', 'PermissionSetName': 'AWSReadOnlyAccess'},
353
- {'AccountId': '105171185823',
354
- 'PermissionSetArn': 'arn:aws:sso:::permissionSet/ssoins-66845289d6823727/ps-c6046bbbf15aaafc',
355
- 'PrincipalType': 'GROUP',
356
- 'PrincipalId': '9a672b3314-43117aac-887b-48ee-af49-b6b6cd059199',
357
- 'GroupName': 'AWSControlTowerAdmins',
358
- 'PermissionSetName': 'AWSOrganizationsFullAccess'}]}
359
-
360
- organizations_complete_f = map_organizations_complete(
361
- organizations_complete=init_org_complete(org=org_data, root_id=root, list_ous=ous),
362
- llist_accounts=accounts, list_ous=ous, reference_outs_list=ous.copy()
363
- )
364
- organizations_complete_f = set_accounts_tree(llist_accounts=accounts,
365
- organizations_complete=organizations_complete_f, list_ous=ous)
366
- save_results(results=organizations_complete_f, filename="organizations_complete_state.json")