add level 3

This commit is contained in:
Матвей
2026-10-20 17:24:32 +03:00
parent 3b52b91fb7
commit e9ef559c34
33 changed files with 1138 additions and 96 deletions
+38
View File
@@ -0,0 +1,38 @@
"""Idempotent private bucket bootstrap; executed with separate admin credentials."""
import time
from botocore.exceptions import BotoCoreError, ClientError
from .storage.s3 import S3Settings, S3Store
def main():
store = S3Store(S3Settings.load())
try:
for attempt in range(60):
try:
store.client.list_buckets()
break
except (BotoCoreError, ClientError):
if attempt == 59:
raise RuntimeError("S3 startup timed out") from None
time.sleep(1)
bucket = store.settings.bucket
try:
store.client.head_bucket(Bucket=bucket)
except ClientError as error:
if str(error.response["Error"]["Code"]) not in {"404", "NoSuchBucket", "NotFound"}:
raise
store.client.create_bucket(Bucket=bucket)
# No anonymous identity; revoke any previously configured public grants/policy.
store.client.put_bucket_acl(Bucket=bucket, ACL="private")
try:
store.client.delete_bucket_policy(Bucket=bucket)
except ClientError as error:
if error.response["Error"]["Code"] != "NoSuchBucketPolicy":
raise
print("PASS: private S3 bucket ready")
finally:
store.client.close()
if __name__ == "__main__":
main()