Реализовать лабораторную 4 на оценку 5
Добавить приватное S3-хранилище, вложения, presigned upload, reconciler и доказательства.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"""One-shot, idempotent private-bucket bootstrap.
|
||||
|
||||
Runs in the dedicated ``s3-init`` Compose service with the administrative S3
|
||||
identity. The API replicas start only after this service exits successfully,
|
||||
and they use a different, restricted identity.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
import time
|
||||
|
||||
from . import s3
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s")
|
||||
log = logging.getLogger("messenger.s3-bootstrap")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
deadline = time.monotonic() + 90.0
|
||||
backoff = 0.5
|
||||
while True:
|
||||
try:
|
||||
s3.ensure_bucket()
|
||||
if not s3.check_ready():
|
||||
raise RuntimeError("restricted identity cannot see the bucket")
|
||||
log.info("private bucket is present and visible to the API identity")
|
||||
return 0
|
||||
except Exception as error:
|
||||
if time.monotonic() >= deadline:
|
||||
log.error("bucket bootstrap failed: %s", type(error).__name__)
|
||||
return 1
|
||||
log.warning("bucket bootstrap is not ready yet: %s", type(error).__name__)
|
||||
time.sleep(backoff)
|
||||
backoff = min(backoff * 2, 5.0)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user