diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..3c66f09 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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" diff --git a/src/auto_protect/app.py b/src/auto_protect/app.py index 04140bf..1abf748 100644 --- a/src/auto_protect/app.py +++ b/src/auto_protect/app.py @@ -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), diff --git a/src/health_digest/app.py b/src/health_digest/app.py index 5537c93..94a18bd 100644 --- a/src/health_digest/app.py +++ b/src/health_digest/app.py @@ -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:") ) ) diff --git a/src/shared/python/afi_client.py b/src/shared/python/afi_client.py index d42c24b..21b112f 100644 --- a/src/shared/python/afi_client.py +++ b/src/shared/python/afi_client.py @@ -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): diff --git a/src/shared/python/slack.py b/src/shared/python/slack.py index 29215df..fb96860 100644 --- a/src/shared/python/slack.py +++ b/src/shared/python/slack.py @@ -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)