Skip to content

Commit cbb3c0b

Browse files
committed
refactor(core): centralize mock bucket names in constants module
1 parent 5199371 commit cbb3c0b

4 files changed

Lines changed: 31 additions & 15 deletions

File tree

config/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# config/constants.py
2+
# Constants for mock configurations
3+
MOCK_BUCKET_AWS = "demo-s3"
4+
MOCK_BUCKET_GCP = "demo-gcp"
5+
MOCK_CONTAINER_AZURE = "demo-container"

main.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from clients.azure_client import list_blob_objects
1818
from tools.mock_fill import fill_s3_bucket, fill_azure_container, fill_gcp_bucket
1919
from tools.cleanup import cleanup_s3, cleanup_azure, cleanup_gcp
20+
from config.constants import MOCK_BUCKET_AWS, MOCK_BUCKET_GCP, MOCK_CONTAINER_AZURE
2021

2122
logging.basicConfig(filename="audit.log", level=logging.INFO)
2223

@@ -73,18 +74,18 @@ def audit(config):
7374
@click.option('--connection_string', default='UseDevelopmentStorage=true', help='Azure connection string')
7475
def fill(profile, connection_string):
7576
"""Populate buckets with mock audit objects"""
76-
fill_s3_bucket("demo-s3", profile=profile)
77-
fill_azure_container("demo-container", connection_string=connection_string)
78-
fill_gcp_bucket("demo-gcp")
77+
fill_s3_bucket(MOCK_BUCKET_AWS, profile=profile)
78+
fill_azure_container(MOCK_CONTAINER_AZURE, connection_string=connection_string)
79+
fill_gcp_bucket(MOCK_BUCKET_GCP)
7980

8081
@cli.command()
8182
@click.option('--profile', default='auditor', help='AWS profile name')
8283
@click.option('--connection_string', default='UseDevelopmentStorage=true', help='Azure connection string')
8384
def clean(profile, connection_string):
8485
"""Remove all mock objects from buckets and containers"""
85-
cleanup_s3("demo-s3", profile=profile)
86-
cleanup_azure("demo-container", connection_string=connection_string)
87-
cleanup_gcp("demo-gcp")
86+
cleanup_s3(MOCK_BUCKET_AWS, profile=profile)
87+
cleanup_azure(MOCK_CONTAINER_AZURE, connection_string=connection_string)
88+
cleanup_gcp(MOCK_BUCKET_GCP)
8889

8990
if __name__ == '__main__':
90-
cli()
91+
cli()

tools/cleanup.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
from azure.storage.blob import BlobServiceClient
33
from google.cloud import storage
44

5+
# Shared constants for mock buckets
6+
MOCK_BUCKET_AWS = "demo-s3"
7+
MOCK_CONTAINER_AZURE = "demo-container"
8+
MOCK_BUCKET_GCP = "demo-gcp"
9+
510
# 🧹 AWS S3: Remove all objects from a bucket
6-
def cleanup_s3(bucket: str, profile: str = "auditor") -> None:
11+
def cleanup_s3(bucket: str = MOCK_BUCKET_AWS, profile: str = "auditor") -> None:
712
session = boto3.Session(profile_name=profile)
813
s3 = session.client("s3")
914
try:
@@ -15,7 +20,7 @@ def cleanup_s3(bucket: str, profile: str = "auditor") -> None:
1520
print(f"[ERROR] AWS cleanup failed: {e}")
1621

1722
# 🧹 Azure Blob: Remove all blobs from a container
18-
def cleanup_azure(container: str, connection_string: str) -> None:
23+
def cleanup_azure(container: str = MOCK_CONTAINER_AZURE, connection_string: str = "UseDevelopmentStorage=true") -> None:
1924
try:
2025
client = BlobServiceClient.from_connection_string(connection_string)
2126
container_client = client.get_container_client(container)
@@ -27,7 +32,7 @@ def cleanup_azure(container: str, connection_string: str) -> None:
2732
print(f"[ERROR] Azure cleanup failed: {e}")
2833

2934
# 🧹 GCP GCS: Remove all blobs from a bucket
30-
def cleanup_gcp(bucket_name: str) -> None:
35+
def cleanup_gcp(bucket_name: str = MOCK_BUCKET_GCP) -> None:
3136
try:
3237
client = storage.Client()
3338
bucket = client.get_bucket(bucket_name)
@@ -36,4 +41,4 @@ def cleanup_gcp(bucket_name: str) -> None:
3641
blob.delete()
3742
print(f"[CLEANUP] GCP → Cleared {len(blobs)} blobs from {bucket_name}")
3843
except Exception as e:
39-
print(f"[ERROR] GCP cleanup failed: {e}")
44+
print(f"[ERROR] GCP cleanup failed: {e}")

tools/mock_fill.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
from azure.storage.blob import BlobServiceClient
33
from google.cloud import storage
44

5+
# Shared constants for mock buckets
6+
MOCK_BUCKET_AWS = "demo-s3"
7+
MOCK_CONTAINER_AZURE = "demo-container"
8+
MOCK_BUCKET_GCP = "demo-gcp"
9+
510
# AWS S3: Upload demo object
6-
def fill_s3_bucket(bucket: str, profile: str = "auditor"):
11+
def fill_s3_bucket(bucket: str = MOCK_BUCKET_AWS, profile: str = "auditor"):
712
session = boto3.Session(profile_name=profile)
813
s3 = session.client("s3")
914
s3.put_object(
@@ -14,16 +19,16 @@ def fill_s3_bucket(bucket: str, profile: str = "auditor"):
1419
print(f"[MOCK] S3 → Added demo-config.json to {bucket}")
1520

1621
# Azure Blob: Upload demo blob
17-
def fill_azure_container(container: str, connection_string: str):
22+
def fill_azure_container(container: str = MOCK_CONTAINER_AZURE, connection_string: str = "UseDevelopmentStorage=true"):
1823
client = BlobServiceClient.from_connection_string(connection_string)
1924
blob_client = client.get_blob_client(container=container, blob="demo.json")
2025
blob_client.upload_blob('{"azure":"mock"}', overwrite=True)
2126
print(f"[MOCK] Azure → Added demo.json to {container}")
2227

2328
# GCP GCS: Upload demo blob
24-
def fill_gcp_bucket(bucket_name: str):
29+
def fill_gcp_bucket(bucket_name: str = MOCK_BUCKET_GCP):
2530
client = storage.Client()
2631
bucket = client.get_bucket(bucket_name)
2732
blob = bucket.blob("demo.json")
2833
blob.upload_from_string('{"gcp":"mock"}')
29-
print(f"[MOCK] GCP → Added demo.json to {bucket_name}")
34+
print(f"[MOCK] GCP → Added demo.json to {bucket_name}")

0 commit comments

Comments
 (0)