Add CI workflow and apply ruff formatting (#7)

This commit is contained in:
Adam Moussa 2026-05-08 15:48:29 -04:00 • committed by GitHub
parent 468e16b173
commit 40711bbc8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 9 deletions

10
.github/workflows/ci.yaml vendored Normal file
View file

@ -0,0 +1,10 @@
name: CI
on:
pull_request:
branches: [main]
jobs:
ci:
uses: Sea-Haven-Industries/.github/.github/workflows/ci-python-sam.yaml@main
with:
source-dirs: "src"

View file

@ -23,7 +23,8 @@ def handler(event, context):
# Filter to unprotected, non-archived resources
unprotected = [
r for r in resources
r
for r in resources
if r["id"] not in protected_ids and not r.get("archived", False)
]
@ -79,7 +80,9 @@ def handler(event, context):
)
)
slack.post_message(blocks=blocks, text=f"Afi Auto-Protect: {len(succeeded)} new users added")
slack.post_message(
blocks=blocks, text=f"Afi Auto-Protect: {len(succeeded)} new users added"
)
return {
"protected": len(succeeded),

View file

@ -13,12 +13,12 @@ import slack
def _format_bytes(value, units):
"""Format storage value to human-readable string."""
if units == "bytes":
gb = value / (1024 ** 3)
gb = value / (1024**3)
if gb >= 1024:
return f"{gb / 1024:.1f} TB"
if gb >= 1:
return f"{gb:.1f} GB"
mb = value / (1024 ** 2)
mb = value / (1024**2)
if mb >= 1:
return f"{mb:.1f} MB"
return f"{value} bytes"
@ -44,7 +44,9 @@ def handler(event, context):
end_time = now.strftime("%Y-%m-%dT%H:00:00Z")
# Fetch data
task_stats = afi_client.get_task_statistics(api_key, tenant_id, start_time, end_time)
task_stats = afi_client.get_task_statistics(
api_key, tenant_id, start_time, end_time
)
quotas = afi_client.get_tenant_quotas(api_key, tenant_id)
resource_stats = afi_client.get_resource_statistics(api_key, tenant_id)
@ -117,13 +119,19 @@ def handler(event, context):
else:
limit_str = _format_bytes(limit, units)
pct = used / limit * 100
warn = " :rotating_light:" if exceeded else (" :warning:" if pct > 80 else "")
warn = (
" :rotating_light:"
if exceeded
else (" :warning:" if pct > 80 else "")
)
quota_lines.append(
f"- *{kind}:* {used_str} / {limit_str} ({pct:.0f}%){warn}"
)
blocks.append(slack.section_block("\n".join(quota_lines)))
else:
blocks.append(slack.section_block(":floppy_disk: *Storage:* No quota data available"))
blocks.append(
slack.section_block(":floppy_disk: *Storage:* No quota data available")
)
blocks.append(slack.divider_block())
@ -140,7 +148,7 @@ def handler(event, context):
f":busts_in_silhouette: *Resource Coverage*\n"
f"- Protected: *{prot}* / {total_r}\n"
f"- Unprotected: *{unprot}*"
+ (f" :warning:" if unprot > 0 else " :white_check_mark:")
+ (" :warning:" if unprot > 0 else " :white_check_mark:")
)
)

View file

@ -81,7 +81,9 @@ def protect_resource(api_key, tenant_id, resource_id, policy_id):
def get_resource_statistics(api_key, tenant_id):
"""Get resource protection statistics summary."""
return _request("GET", f"/tenants/{tenant_id}/resources/statistics/summary", api_key)
return _request(
"GET", f"/tenants/{tenant_id}/resources/statistics/summary", api_key
)
def get_task_statistics(api_key, tenant_id, start_time, end_time):

View file

@ -11,6 +11,7 @@ def _get_webhook_url():
global _webhook_url
if _webhook_url is None:
import boto3
client = boto3.client("secretsmanager")
secret_arn = os.environ["SLACK_WEBHOOK_SECRET_ARN"]
response = client.get_secret_value(SecretId=secret_arn)