Skip to content

Commit

Permalink
add headers back
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jan 15, 2026
1 parent 5af5d3d commit 4810bec
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions local-app/python-tools/cross-organization/tag-checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from botocore.exceptions import ClientError
from tqdm import tqdm

__version__ = "1.1.9"
__version__ = "1.1.10"

def get_args():
parser = argparse.ArgumentParser(description=f"AWS Org Tag Scanner v{__version__}")
Expand Down Expand Up @@ -73,7 +73,7 @@ def scan_account(account, management_session, role_name, partition, tag_keys, re
global_tags_found = set()
regional_metrics = []

# UI Alignment: Fixed size title with lane ID padding
# UI Alignment: Zero-padded lane + fixed width label
label = f"{acc_id} {alias}".ljust(bar_width)
pbar = tqdm(total=len(tag_keys), desc=f"Lane {lane_id:02d} | {label}",
position=lane_id, leave=False, bar_format='{l_bar}{bar}| {n_fmt}/{total_fmt}')
Expand Down Expand Up @@ -114,7 +114,6 @@ def scan_account(account, management_session, role_name, partition, tag_keys, re
})
else:
r_entry['hits'] += r_hits
# Logic update for resource uniqueness within the region
current_tags = set(r_entry['tags_found_list']) | r_tags_found
r_entry['tags_found_list'] = sorted(list(current_tags))
r_entry['tags_found_count'] = len(current_tags)
Expand Down Expand Up @@ -157,28 +156,45 @@ def main():
with open(args.accounts_from, 'r') as f:
target_ids = [l.strip() for l in f if l.strip()]

all_accs = []
# Initial Discovery for Header info
all_raw_accounts = []
paginator = org.get_paginator('list_accounts')
for page in paginator.paginate():
for a in page['Accounts']:
if a['Status'] == 'ACTIVE' and (not target_ids or a['Id'] in target_ids):
all_accs.append(a)
all_raw_accounts.extend(page['Accounts'])

if args.limit > 0: all_accs = all_accs[:args.limit]
to_process = []
for a in all_raw_accounts:
if a['Status'] == 'ACTIVE':
if not target_ids or a['Id'] in target_ids:
to_process.append(a)

if args.limit > 0: to_process = to_process[:args.limit]

# UI Alignment with +1 padding fix
max_label_len = max([12 + 1 + len(a['Name']) for a in all_accs]) + 1 if all_accs else 40
# Calculate bar width
max_label_len = max([12 + 1 + len(a['Name']) for a in to_process]) + 1 if to_process else 40

# STARTUP HEADER
print(f"\n{'='*85}\nAWS TAG CHECKER v{__version__}\n{'='*85}")
print(f"Execution Profile : {args.profile}")
print(f"Execution Region : {args.region}")
print(f"Assume Role Name : {args.role_name}")
print(f"Partition : {partition}")
print(f"Thread Count : {args.max_workers}")
print(f"Tags Read : {len(tag_keys)}")
print(f"Accounts Found : {len(all_raw_accounts)}")
print(f"Accounts Targeted : {len(to_process)}")
print(f"{'-'*85}")
print(f"Arguments: {vars(args)}")
print(f"{'='*85}\n")

all_findings = []
account_results = []
overall_pbar = tqdm(total=len(all_accs), desc="Total Org Progress", position=0)
overall_pbar = tqdm(total=len(to_process), desc="Total Org Progress", position=0)

with ThreadPoolExecutor(max_workers=args.max_workers) as executor:
futures = {executor.submit(scan_account, acc, session, args.role_name, partition,
tag_keys, args.region, (i % args.max_workers) + 1,
args.account_regex, args.verbose, max_label_len): acc for i, acc in enumerate(all_accs)}
args.account_regex, args.verbose, max_label_len): acc for i, acc in enumerate(to_process)}

for future in as_completed(futures):
res, acc_id, alias, m, status = future.result()
Expand All @@ -196,7 +212,7 @@ def main():
overall_pbar.close()
print("\n" * (args.max_workers + 1))

# Final Summary Construction
# Summary Aggregation
total_hits = sum(a['global_metrics']['hits'] for a in account_results)
total_res = len(set(f['arn'] for f in all_findings))
all_found_keys = set(f['tag_name'] for f in all_findings)
Expand Down

0 comments on commit 4810bec

Please sign in to comment.