31 lines
936 B
Python
31 lines
936 B
Python
"""Idempotent private bucket bootstrap; this process alone receives admin keys."""
|
|
|
|
import time
|
|
|
|
from botocore.exceptions import BotoCoreError, ClientError
|
|
|
|
from .storage import ObjectStorage
|
|
|
|
|
|
def main():
|
|
storage = ObjectStorage(admin=True)
|
|
for attempt in range(30):
|
|
try:
|
|
try:
|
|
storage.client.head_bucket(Bucket=storage.bucket)
|
|
except ClientError as exc:
|
|
if exc.response["Error"]["Code"] not in {"404", "NoSuchBucket", "NotFound"}:
|
|
raise
|
|
storage.client.create_bucket(Bucket=storage.bucket)
|
|
print("Private bucket ready; anonymous identity is not configured.")
|
|
storage.close()
|
|
return
|
|
except (ClientError, BotoCoreError):
|
|
if attempt == 29:
|
|
raise RuntimeError("S3 bootstrap timeout") from None
|
|
time.sleep(1)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|