From f64c2f3ad2ec09adc6ee1d3739baf4716e331017 Mon Sep 17 00:00:00 2001 From: badra001 Date: Fri, 27 Mar 2026 11:09:51 -0400 Subject: [PATCH] fix --- .../assess_check_scheduling.py | 34 ++++++++++++------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/local-app/python-tools/cross-organization/assess_check_scheduling.py b/local-app/python-tools/cross-organization/assess_check_scheduling.py index 5308ae2c..6b5da7bf 100755 --- a/local-app/python-tools/cross-organization/assess_check_scheduling.py +++ b/local-app/python-tools/cross-organization/assess_check_scheduling.py @@ -7,13 +7,13 @@ from collections import defaultdict # --- VERSIONING --- -__version__ = "1.7.3" +__version__ = "1.7.4" def get_tag(tags, key, default=""): """Case-insensitive tag lookup.""" if not tags: return default + # Handle list of dicts if AWS API returned raw format if isinstance(tags, list): - # Convert list of {'Key': 'x', 'Value': 'y'} to dict if necessary tags = {t['Key']: t['Value'] for t in tags if 'Key' in t} for k, v in tags.items(): if k.lower() == key.lower(): @@ -65,24 +65,34 @@ def main(): for file_path in audit_files: with open(file_path, 'r') as f: try: - raw_data = json.load(f) + # FIX: audit_results is a LIST of account objects + account_list = json.load(f) - # Navigate the org_runner JSON structure - # It usually looks like: {"account_id": {"data": {...}, "alias": "..."}} - for account_id, account_data in raw_data.items(): - if isinstance(account_data, dict) and "data" in account_data: + if not isinstance(account_list, list): + print(f" Warning: {file_path} is not a list. Skipping.") + continue + + for account_entry in account_list: + # Each entry has an 'account_id' key and its associated data + for acc_id, acc_content in account_entry.items(): + if not isinstance(acc_content, dict) or "data" not in acc_content: + continue + # Extract the resources from the 'data' block - for res_id, res_info in account_data["data"].items(): - if res_id == "account_summary": continue + for res_key, res_info in acc_content["data"].items(): + # Skip the metadata summary entry + if res_key == "account_summary": + continue - # Ensure we carry the account_id into the resource object - res_info['account_id'] = account_id + # Inject account context into the resource for the CSV + res_info['account_id'] = acc_id all_res.append(res_info) + except Exception as e: print(f" Skipping {file_path} due to error: {e}") if not all_res: - print("❌ Error: Files were found but no resource data was extracted. Check JSON structure."); return + print("❌ Error: No resource data could be extracted. Please verify the JSON contents."); return # --- FINOPS HEALTH REPORT --- missing_num = sum(1 for r in all_res if not get_tag(r.get('tags', {}), 'finops_project_number'))