completed grade 5 track 1

This commit is contained in:
2026-11-27 08:57:51 +03:00
parent e0263ba902
commit 43949458a6
11 changed files with 672 additions and 9 deletions
+13 -6
View File
@@ -1,5 +1,6 @@
"""Идемпотентный private bucket и отдельная ограниченная учётная запись API."""
from contextlib import contextmanager
import json
import os
from pathlib import Path
@@ -18,13 +19,10 @@ def secret(name):
return value
def main():
@contextmanager
def operator():
endpoint = os.environ["S3_ENDPOINT"]
bucket = os.environ["S3_BUCKET"]
root_user, root_password = secret("minio_root_user"), secret("minio_root_password")
access, password = secret("s3_access_key_id"), secret("s3_secret_access_key")
if access == root_user:
raise ValueError("API не должен использовать root credentials")
ca = Path("/run/tls/ca.crt")
context = ssl.create_default_context(cafile=str(ca))
deadline = time.monotonic() + 60
@@ -71,9 +69,18 @@ def main():
)
if result.returncode:
raise RuntimeError(
"Ошибка bootstrap MinIO; значения credentials скрыты"
f"Ошибка операции MinIO {args[0]}; значения credentials скрыты"
)
yield mc, config
def main():
bucket = os.environ["S3_BUCKET"]
access, password = secret("s3_access_key_id"), secret("s3_secret_access_key")
if access == secret("minio_root_user"):
raise ValueError("API не должен использовать root credentials")
with operator() as (mc, config):
mc("mb", "--ignore-existing", "storage/" + bucket)
mc("anonymous", "set", "none", "storage/" + bucket)
policy = {