167 lines
7.1 KiB
Python
167 lines
7.1 KiB
Python
from os import getenv
|
|
from typing import Any
|
|
|
|
|
|
def build_postgres_config() -> dict[str, Any]:
|
|
"""
|
|
Build PostgreSQL database configuration from environment variables.
|
|
|
|
This function constructs a PostgreSQL configuration dictionary from
|
|
environment variables with sensible defaults for local development.
|
|
It handles connection pool configuration and security parameters.
|
|
|
|
Environment Variables:
|
|
POSTGRES_HOST: Database hostname (default: localhost)
|
|
POSTGRES_PORT: Database port (default: 5432)
|
|
POSTGRES_USER: Database username (default: sientia)
|
|
POSTGRES_PASSWORD: Database password (default: sientia)
|
|
POSTGRES_DBNAME: Database name (default: sientia)
|
|
POSTGRES_MIN_CONNECTIONS: Minimum connection pool size (default: 5)
|
|
POSTGRES_MAX_CONNECTIONS: Maximum connection pool size (default: 20)
|
|
|
|
Returns:
|
|
dict: PostgreSQL configuration dictionary with all required parameters
|
|
"""
|
|
return {
|
|
'host': getenv('POSTGRES_HOST', 'localhost'),
|
|
'port': int(getenv('POSTGRES_PORT', '5432')),
|
|
'user': getenv('POSTGRES_USER', 'sientia'),
|
|
'password': getenv('POSTGRES_PASSWORD', 'sientia'),
|
|
'dbname': getenv('POSTGRES_DBNAME', 'sientia'),
|
|
'min_connections': int(getenv('POSTGRES_MIN_CONNECTIONS', '5')),
|
|
'max_connections': int(getenv('POSTGRES_MAX_CONNECTIONS', '20')),
|
|
}
|
|
|
|
|
|
def build_mlflow_config() -> dict[str, Any]:
|
|
"""
|
|
Build MLFlow server configuration from environment variables.
|
|
|
|
This function constructs an MLFlow configuration dictionary from
|
|
environment variables with sensible defaults for local development.
|
|
It handles server connection and authentication parameters.
|
|
|
|
Environment Variables:
|
|
MLFLOW_URL: Full MLflow tracking URL including scheme, host, and port
|
|
(default: http://localhost:5080)
|
|
MLFLOW_USERNAME: MLFlow username (default: aignosi)
|
|
MLFLOW_PASSWORD: MLFlow password (default: aignosi)
|
|
|
|
Returns:
|
|
dict: MLFlow configuration dictionary with all required parameters
|
|
"""
|
|
return {
|
|
'url': getenv('MLFLOW_URL', 'http://localhost:5080'),
|
|
'username': getenv('MLFLOW_USERNAME', 'aignosi'),
|
|
'password': getenv('MLFLOW_PASSWORD', 'aignosi'),
|
|
}
|
|
|
|
|
|
def build_mongodb_config() -> dict[str, Any]:
|
|
"""
|
|
Build MongoDB configuration from environment variables.
|
|
|
|
This function constructs a MongoDB configuration dictionary from
|
|
environment variables with sensible defaults for local development.
|
|
It handles connection string and database name configuration.
|
|
|
|
Environment Variables:
|
|
MONGODB_USERNAME: MongoDB username (default: root)
|
|
MONGODB_PASSWORD: MongoDB password (default: wKZDbMNU1c)
|
|
MONGODB_URL: MongoDB connection URI (default: localhost:27018)
|
|
MONGODB_DATABASE: MongoDB database name (default: sientia)
|
|
MONGODB_TTL_INDEX_HOURS: TTL index duration in hours (default: 1)
|
|
|
|
Returns:
|
|
dict: MongoDB configuration dictionary with connection parameters
|
|
"""
|
|
username = getenv('MONGODB_USERNAME', 'root')
|
|
password = getenv('MONGODB_PASSWORD', 'wKZDbMNU1c')
|
|
uri = getenv('MONGODB_URL', 'localhost:27018')
|
|
|
|
connection_string = f'mongodb://{username}:{password}@{uri}'
|
|
|
|
return {
|
|
'connection_string': connection_string,
|
|
'database_name': getenv('MONGODB_DATABASE', 'sientia'),
|
|
'ttl_index_seconds': int(getenv('MONGODB_TTL_INDEX_HOURS', '1')) * 3600,
|
|
'uri': uri,
|
|
}
|
|
|
|
|
|
def build_minio_config() -> dict[str, Any]:
|
|
"""
|
|
Build MinIO (S3-compatible) configuration from environment variables.
|
|
|
|
This function constructs a MinIO configuration dictionary from
|
|
environment variables with sensible defaults for local development.
|
|
It handles endpoint URL, authentication, connection parameters, and retry policies.
|
|
|
|
Environment Variables:
|
|
MINIO_ENDPOINT_URL: MinIO server endpoint URL (default: http://localhost:9000)
|
|
MINIO_ACCESS_KEY: MinIO access key ID (default: minioadmin)
|
|
MINIO_SECRET_KEY: MinIO secret access key (default: minioadmin)
|
|
MINIO_REGION: MinIO region name (default: us-east-1)
|
|
MINIO_SECURE: Whether to use SSL/TLS (default: false)
|
|
MINIO_MAX_RETRY_ATTEMPTS: Maximum number of retry attempts (default: 3)
|
|
MINIO_RETRY_MODE: Retry mode - standard, legacy, or adaptive (default: adaptive)
|
|
MINIO_CONNECT_TIMEOUT: Connection timeout in seconds (default: 10)
|
|
MINIO_READ_TIMEOUT: Read timeout in seconds (default: 60)
|
|
MINIO_DEFAULT_BUCKET: Default S3 bucket for MinioRepository (default: model-training)
|
|
|
|
Returns:
|
|
dict: MinIO configuration dictionary with all required parameters
|
|
"""
|
|
return {
|
|
'endpoint_url': getenv('MINIO_ENDPOINT_URL', 'http://localhost:9000'),
|
|
'access_key': getenv('MINIO_ACCESS_KEY', 'minioadmin'),
|
|
'secret_key': getenv('MINIO_SECRET_KEY', 'minioadmin'),
|
|
'region': getenv('MINIO_REGION', 'us-east-1'),
|
|
'use_ssl': getenv('MINIO_SECURE', 'false').lower() == 'true',
|
|
'max_retry_attempts': int(getenv('MINIO_MAX_RETRY_ATTEMPTS', '3')),
|
|
'retry_mode': getenv('MINIO_RETRY_MODE', 'adaptive'),
|
|
'connect_timeout': int(getenv('MINIO_CONNECT_TIMEOUT', '10')),
|
|
'read_timeout': int(getenv('MINIO_READ_TIMEOUT', '60')),
|
|
'default_bucket': getenv('MINIO_DEFAULT_BUCKET', 'model-training'),
|
|
}
|
|
|
|
|
|
def build_plugin_store_config() -> dict[str, Any]:
|
|
"""
|
|
Build PluginStore configuration from environment variables.
|
|
|
|
This function constructs a configuration dictionary for the PluginStore
|
|
client using environment variables with sensible defaults for local
|
|
development.
|
|
|
|
Environment Variables:
|
|
STORE_BASE_URL: Base URL of the PluginStore backing Git server
|
|
(default: http://localhost:3000)
|
|
STORE_OWNER: Repository owner/organization (default: sientia)
|
|
STORE_REPO: Repository name (default: model-library-store)
|
|
STORE_BRANCH: Optional branch name
|
|
STORE_USERNAME: Optional username for Git HTTP authentication
|
|
STORE_PASSWORD: Optional password/token for Git HTTP authentication
|
|
PYPI_SERVER: Optional custom PyPI index URL for runtime installation
|
|
(default: http://localhost:5000)
|
|
PYPI_USERNAME: Optional username for PyPI authentication
|
|
PYPI_PASSWORD: Optional password/token for PyPI authentication
|
|
|
|
Returns:
|
|
dict: PluginStore configuration dictionary with all connector parameters
|
|
"""
|
|
|
|
cache_ttl_seconds = getenv('STORE_CACHE_TTL_SECONDS')
|
|
return {
|
|
'base_url': getenv('STORE_BASE_URL', 'http://localhost:3000'),
|
|
'owner': getenv('STORE_OWNER', 'sientia'),
|
|
'repo': getenv('STORE_REPO', 'model-library-store'),
|
|
'username': getenv('STORE_USERNAME'),
|
|
'password': getenv('STORE_PASSWORD'),
|
|
'branch': getenv('STORE_BRANCH'),
|
|
'cache_ttl_seconds': int(cache_ttl_seconds) if cache_ttl_seconds else None,
|
|
'pypi_index_url': getenv('PYPI_SERVER', 'http://localhost:5000'),
|
|
'pypi_username': getenv('PYPI_USERNAME'),
|
|
'pypi_password': getenv('PYPI_PASSWORD'),
|
|
}
|