Files
mtusi2026lab6/scripts/check_bucket_private.py
T
2026-11-19 15:03:52 +03:00

11 lines
447 B
Python

import os, sys, urllib.request, urllib.error
BUCKET = os.getenv("S3_BUCKET", "messenger-attachments")
KEY = os.getenv("S3_KEY")
URL = f"http://s3:8333/{BUCKET}/{KEY}"
try:
urllib.request.urlopen(URL)
print("FAIL: object accessible without auth"); sys.exit(1)
except urllib.error.HTTPError as e:
if e.code in (401, 403):
print(f"PASS: anonymous GET -> {e.code}"); sys.exit(0)
print(f"FAIL: unexpected {e.code}"); sys.exit(1)