Skip to content

Commit

Permalink
add top 20
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Jul 17, 2026
1 parent ef39e3f commit c5179bf
Showing 1 changed file with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections import defaultdict

# --- VERSIONING ---
__version__ = "1.2.2"
__version__ = "1.3.0"

UNIT_CONVERSION_MAP = {
"B": {"divisor": 1, "label": "Bytes"},
Expand All @@ -24,7 +24,7 @@ def find_latest_file(pattern):
return max(files, key=os.path.getctime) if files else None

def main():
parser = argparse.ArgumentParser(description="AWS S3 Fleet Storage Filtered Assessor Suite v1.2.2")
parser = argparse.ArgumentParser(description="AWS S3 Fleet Storage Filtered Assessor Suite v1.3.0")
parser.add_argument("--input", help="JSON file (default: latest audit_results.check_s3_buckets.*.json)")
parser.add_argument("--size-units", default="GB", choices=["B", "MB", "GB", "TB", "PB"],
help="Target size scale unit representation to output in reports (Default: GB)")
Expand Down Expand Up @@ -149,13 +149,39 @@ def main():
tf.write(fmt_tier.format(s_tier, scaled_tier_size, share))
tf.write("\n")

# --- FIXED: Use clean pre-compiled f-string masks to inject tracking widths safely ---
tf.write("[SECTION 4: GRANULAR BUCKET METADATA INVENTORY MATRIX]\n")
# --- NEW SECTION 5: TOP 20 LARGEST BUCKETS ---
tf.write("[SECTION 5: TOP 20 LARGEST BUCKETS BY INSTALLED VOLUME FOOTPRINT]\n")
size_data_spec = ",d" if target_unit == "B" else ",.2f"
fmt_top_size_header = f" {{:<4}} | {{:<12}} | {{:<{max_alias_w}}} | {{:<{max_bucket_w}}} | {{:<12}} | {{:>18}} | {{:>12}}\n"
fmt_top_size_data = f" #{{:<3}} | {{:<12}} | {{:<{max_alias_w}}} | {{:<{max_bucket_w}}} | {{:<12}} | {{:>18{size_data_spec}}} | {{:>12,}}\n"

size_header_str = f"Size ({target_unit})"
tf.write(fmt_top_size_header.format("Idx", "Account ID", "Account Alias", "Bucket Name", "Region", size_header_str, "Objects"))
tf.write(" " + "-" * (max_alias_w + max_bucket_w + 65) + "\n")

fmt_row_header = f" {{:<12}} | {{:<{max_alias_w}}} | {{:<{max_bucket_w}}} | {{:<12}} | {{:>18}} | {{:>12}} | {{:<10}} | {{:<13}}\n"
largest_buckets = sorted(flat_rows, key=lambda x: x[5], reverse=True)[:20]
for idx, r in enumerate(largest_buckets, start=1):
scaled_bucket_size = r[5] if target_unit == "B" else (r[5] / divisor)
tf.write(fmt_top_size_data.format(idx, r[0], r[1], r[2], r[3], scaled_bucket_size, r[6]))
tf.write("\n")

# --- NEW SECTION 6: TOP 20 BUCKETS BY TOTAL OBJECT COUNT ---
tf.write("[SECTION 6: TOP 20 MOST POPULATED BUCKETS BY ALLOCATED OBJECT DENSITY]\n")
fmt_top_obj_header = f" {{:<4}} | {{:<12}} | {{:<{max_alias_w}}} | {{:<{max_bucket_w}}} | {{:<12}} | {{:>18}} | {{:>12}}\n"
fmt_top_obj_data = f" #{{:<3}} | {{:<12}} | {{:<{max_alias_w}}} | {{:<{max_bucket_w}}} | {{:<12}} | {{:>18{size_data_spec}}} | {{:>12,}}\n"

size_data_spec = ",d" if target_unit == "B" else ",.2f"
tf.write(fmt_top_obj_header.format("Idx", "Account ID", "Account Alias", "Bucket Name", "Region", size_header_str, "Objects"))
tf.write(" " + "-" * (max_alias_w + max_bucket_w + 65) + "\n")

most_populated = sorted(flat_rows, key=lambda x: x[6], reverse=True)[:20]
for idx, r in enumerate(most_populated, start=1):
scaled_bucket_size = r[5] if target_unit == "B" else (r[5] / divisor)
tf.write(fmt_top_obj_data.format(idx, r[0], r[1], r[2], r[3], scaled_bucket_size, r[6]))
tf.write("\n")

# Section 4: Master Matrix Table
tf.write("[SECTION 4: GRANULAR BUCKET METADATA INVENTORY MATRIX]\n")
fmt_row_header = f" {{:<12}} | {{:<{max_alias_w}}} | {{:<{max_bucket_w}}} | {{:<12}} | {{:>18}} | {{:>12}} | {{:<10}} | {{:<13}}\n"
fmt_row_data = f" {{:<12}} | {{:<{max_alias_w}}} | {{:<{max_bucket_w}}} | {{:<12}} | {{:>18{size_data_spec}}} | {{:>12,}} | {{:<10}} | {{:<13}}\n"

tf.write(fmt_row_header.format("Account ID", "Account Alias", "Bucket Name", "Region", size_header_str, "Objects", "Version", "Lifecycle"))
Expand Down

0 comments on commit c5179bf

Please sign in to comment.