29
29
from principalmapper .graphing .gathering import get_organizations_data
30
30
from principalmapper .querying .query_orgs import produce_scp_list
31
31
from principalmapper .util import botocore_tools
32
- from principalmapper .util .storage import get_storage_root
32
+ from principalmapper .util .storage import get_storage_root , get_default_graph_path
33
33
34
34
35
35
logger = logging .getLogger (__name__ )
@@ -106,15 +106,20 @@ def process_arguments(parsed_args: Namespace):
106
106
# create the account -> OU path map and apply to all accounts (same as orgs update operation)
107
107
account_ou_map = _map_account_ou_paths (org_tree )
108
108
logger .debug ('account_ou_map: {}' .format (account_ou_map ))
109
- _update_accounts_with_ou_path_map (org_tree .org_id , account_ou_map , get_storage_root ())
109
+ root_path = get_storage_root () if org_tree .partition == 'aws' else os .path .join (get_storage_root (), org_tree .partition )
110
+ _update_accounts_with_ou_path_map (org_tree .org_id , account_ou_map , root_path )
110
111
logger .info ('Updated currently stored Graphs with applicable AWS Organizations data' )
111
112
112
113
# create and cache a list of edges between all the accounts we have data for
113
114
edge_list = []
114
115
graph_objs = []
115
116
for account in org_tree .accounts :
116
117
try :
117
- potential_path = os .path .join (get_storage_root (), account )
118
+ if org_tree .partition != 'aws' :
119
+ potential_path = get_default_graph_path (f'{ org_tree .partition } :{ account } ' )
120
+ else :
121
+ potential_path = get_default_graph_path (account )
122
+
118
123
logger .debug ('Trying to load a Graph from {}' .format (potential_path ))
119
124
graph_obj = Graph .create_graph_from_local_disk (potential_path )
120
125
graph_objs .append (graph_obj )
@@ -135,26 +140,34 @@ def process_arguments(parsed_args: Namespace):
135
140
org_tree .edge_list = edge_list
136
141
logger .info ('Compiled cross-account edges' )
137
142
138
- org_tree .save_organization_to_disk (os .path .join (get_storage_root (), org_tree .org_id ))
143
+ if org_tree .partition != 'aws' :
144
+ org_storage_path = get_default_graph_path (f'{ org_tree .partition } :{ org_tree .org_id } ' )
145
+ else :
146
+ org_storage_path = get_default_graph_path (org_tree .org_id )
147
+ org_tree .save_organization_to_disk (org_storage_path )
139
148
logger .info ('Stored organization data to disk' )
140
149
141
150
elif parsed_args .picked_orgs_cmd == 'update' :
142
151
# pull the existing data from disk
143
- org_filepath = os . path . join ( get_storage_root (), parsed_args .org )
152
+ org_filepath = get_default_graph_path ( parsed_args .org )
144
153
org_tree = OrganizationTree .create_from_dir (org_filepath )
145
154
146
155
# create the account -> OU path map and apply to all accounts
147
156
account_ou_map = _map_account_ou_paths (org_tree )
148
157
logger .debug ('account_ou_map: {}' .format (account_ou_map ))
149
- _update_accounts_with_ou_path_map (org_tree .org_id , account_ou_map , get_storage_root ())
158
+ root_path = get_storage_root () if org_tree .partition == 'aws' else os .path .join (get_storage_root (), org_tree .partition )
159
+ _update_accounts_with_ou_path_map (org_tree .org_id , account_ou_map , root_path )
150
160
logger .info ('Updated currently stored Graphs with applicable AWS Organizations data' )
151
161
152
162
# create and cache a list of edges between all the accounts we have data for
153
163
edge_list = []
154
164
graph_objs = []
155
165
for account in org_tree .accounts :
156
166
try :
157
- potential_path = os .path .join (get_storage_root (), account )
167
+ if org_tree .partition != 'aws' :
168
+ potential_path = get_default_graph_path (f'{ org_tree .partition } :{ account } ' )
169
+ else :
170
+ potential_path = get_default_graph_path (account )
158
171
logger .debug ('Trying to load a Graph from {}' .format (potential_path ))
159
172
graph_obj = Graph .create_graph_from_local_disk (potential_path )
160
173
graph_objs .append (graph_obj )
@@ -175,12 +188,16 @@ def process_arguments(parsed_args: Namespace):
175
188
org_tree .edge_list = edge_list
176
189
logger .info ('Compiled cross-account edges' )
177
190
178
- org_tree .save_organization_to_disk (os .path .join (get_storage_root (), org_tree .org_id ))
191
+ if org_tree .partition != 'aws' :
192
+ org_storage_path = get_default_graph_path (f'{ org_tree .partition } :{ org_tree .org_id } ' )
193
+ else :
194
+ org_storage_path = get_default_graph_path (org_tree .org_id )
195
+ org_tree .save_organization_to_disk (org_storage_path )
179
196
logger .info ('Stored organization data to disk' )
180
197
181
198
elif parsed_args .picked_orgs_cmd == 'display' :
182
199
# pull the existing data from disk
183
- org_filepath = os . path . join ( get_storage_root (), parsed_args .org )
200
+ org_filepath = get_default_graph_path ( parsed_args .org )
184
201
org_tree = OrganizationTree .create_from_dir (org_filepath )
185
202
186
203
def _print_account (org_account : OrganizationAccount , indent_level : int , inherited_scps : List [Policy ]):
0 commit comments