more before level3 changes
This commit is contained in:
@@ -5,6 +5,15 @@ from pathlib import Path
|
||||
from urllib.parse import quote
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ObjectSettings:
|
||||
endpoint: str
|
||||
region: str
|
||||
bucket: str
|
||||
access_key: str
|
||||
secret_key: str
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Settings:
|
||||
host: str
|
||||
@@ -59,6 +68,32 @@ def _database_url() -> str:
|
||||
)
|
||||
|
||||
|
||||
def load_object_settings() -> ObjectSettings:
|
||||
"""S3 credentials come from files. The values are not logged."""
|
||||
endpoint = os.getenv('S3_ENDPOINT', '').strip()
|
||||
region = os.getenv('S3_REGION', 'us-east-1').strip() or 'us-east-1'
|
||||
bucket = os.getenv('S3_BUCKET', '').strip()
|
||||
key_file = os.getenv('S3_ACCESS_KEY_ID_FILE', '').strip()
|
||||
secret_file = os.getenv('S3_SECRET_ACCESS_KEY_FILE', '').strip()
|
||||
missing = [
|
||||
name for name, value in (
|
||||
('S3_ENDPOINT', endpoint),
|
||||
('S3_BUCKET', bucket),
|
||||
('S3_ACCESS_KEY_ID_FILE', key_file),
|
||||
('S3_SECRET_ACCESS_KEY_FILE', secret_file),
|
||||
) if not value
|
||||
]
|
||||
if missing:
|
||||
raise RuntimeError('%s is required' % ', '.join(missing))
|
||||
return ObjectSettings(
|
||||
endpoint,
|
||||
region,
|
||||
bucket,
|
||||
_read_secret_file('S3_ACCESS_KEY_ID_FILE', key_file),
|
||||
_read_secret_file('S3_SECRET_ACCESS_KEY_FILE', secret_file),
|
||||
)
|
||||
|
||||
|
||||
def load_settings() -> Settings:
|
||||
return Settings(
|
||||
host=os.getenv('APP_HOST', '0.0.0.0'),
|
||||
|
||||
Reference in New Issue
Block a user