Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Mar 27, 2026
1 parent ddb458d commit f64c2f3
Showing 1 changed file with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit f64c2f3

Please sign in to comment.