Skip to content

fl_server.settings.production

Functions:

Name Description
get_redis_location
get_secret

Get secret value from an environment variable or a file.

Attributes:

Name Type Description
ADMIN_MEDIA_PREFIX
ALLOWED_HOSTS
AUTH_PASSWORD_VALIDATORS
AUTH_USER_MODEL
BASE_DIR
CACHES
CELERY_ACCEPT_CONTENT
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP
CELERY_RESULT_SERIALIZER
CELERY_TASK_ALWAYS_EAGER
CELERY_TASK_SERIALIZER
CELERY_TASK_TIME_LIMIT
CELERY_TASK_TRACK_STARTED
CELERY_TIMEZONE
CORS_ALLOWED_ORIGIN_REGEXES
CORS_ALLOW_ALL_ORIGINS
CORS_ORIGIN_WHITELIST
CSRF_COOKIE_SECURE
DATABASES
DEBUG
DEFAULT_AUTO_FIELD
INSTALLED_APPS
LANGUAGE_CODE
LOGGING
MAX_RUNNING_CHILD_PROCESSES
MIDDLEWARE
REST_FRAMEWORK
ROOT_URLCONF
SECRET_KEY str
SECRET_KEY_FALLBACKS
SESSION_COOKIE_SECURE
SPECTACULAR_SETTINGS
SSL_FORCE
STATIC_ROOT
STATIC_URL
TEMPLATES
TIME_ZONE
USE_I18N
USE_TZ
WSGI_APPLICATION

Attributes

ADMIN_MEDIA_PREFIX module-attribute

ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/'

ALLOWED_HOSTS module-attribute

ALLOWED_HOSTS = splitlines()

AUTH_PASSWORD_VALIDATORS module-attribute

AUTH_PASSWORD_VALIDATORS = [{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'}, {'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'}, {'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'}, {'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'}]

AUTH_USER_MODEL module-attribute

AUTH_USER_MODEL = 'fl_server_core.User'

BASE_DIR module-attribute

BASE_DIR = parent

CACHES module-attribute

CACHES = {'redis': {'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': get_redis_location(), 'OPTIONS': {'CLIENT_CLASS': 'django_redis.client.DefaultClient'}}}

CELERY_ACCEPT_CONTENT module-attribute

CELERY_ACCEPT_CONTENT = ['pickle']

CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP module-attribute

CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True

CELERY_RESULT_SERIALIZER module-attribute

CELERY_RESULT_SERIALIZER = 'pickle'

CELERY_TASK_ALWAYS_EAGER module-attribute

CELERY_TASK_ALWAYS_EAGER = False

CELERY_TASK_SERIALIZER module-attribute

CELERY_TASK_SERIALIZER = 'pickle'

CELERY_TASK_TIME_LIMIT module-attribute

CELERY_TASK_TIME_LIMIT = 30 * 60

CELERY_TASK_TRACK_STARTED module-attribute

CELERY_TASK_TRACK_STARTED = True

CELERY_TIMEZONE module-attribute

CELERY_TIMEZONE = TIME_ZONE

CORS_ALLOWED_ORIGIN_REGEXES module-attribute

CORS_ALLOWED_ORIGIN_REGEXES = splitlines()

CORS_ALLOW_ALL_ORIGINS module-attribute

CORS_ALLOW_ALL_ORIGINS = str2bool(get('CORS_ALLOW_ALL_ORIGINS', 'False'))

CORS_ORIGIN_WHITELIST module-attribute

CORS_ORIGIN_WHITELIST = splitlines()
CSRF_COOKIE_SECURE = True

DATABASES module-attribute

DATABASES = {'postgresql': {'ENGINE': 'django.db.backends.postgresql', 'HOST': get('FL_POSTGRES_HOST', 'db'), 'PORT': get('FL_POSTGRES_PORT', '5432'), 'NAME': get('FL_POSTGRES_DBNAME', 'demo'), 'USER': get('FL_POSTGRES_USER', 'demo'), 'PASSWORD': get('FL_POSTGRES_PASSWD', 'example')}}

DEBUG module-attribute

DEBUG = False

DEFAULT_AUTO_FIELD module-attribute

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

INSTALLED_APPS module-attribute

INSTALLED_APPS = ['django.contrib.admin', 'django.contrib.auth', 'polymorphic', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'corsheaders', 'rest_framework', 'rest_framework.authtoken', 'fl_server_core', 'fl_server_ai', 'fl_server_api', 'drf_spectacular', 'django.contrib.postgres']

LANGUAGE_CODE module-attribute

LANGUAGE_CODE = 'en-us'

LOGGING module-attribute

LOGGING = get_default_logging_dict(str(BASE_DIR / 'logs' / 'server.log'))

MAX_RUNNING_CHILD_PROCESSES module-attribute

MAX_RUNNING_CHILD_PROCESSES = int(get('FL_MAX_CHILD_PROCESSES', 8))

MIDDLEWARE module-attribute

MIDDLEWARE = ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']

REST_FRAMEWORK module-attribute

REST_FRAMEWORK = {'DEFAULT_SCHEMA_CLASS': 'fl_server_api.openapi.CustomAutoSchema'}

ROOT_URLCONF module-attribute

ROOT_URLCONF = 'fl_server.urls'

SECRET_KEY module-attribute

SECRET_KEY: str = get_secret('FL_DJANGO_SECRET_KEY', ensure=True)

SECRET_KEY_FALLBACKS module-attribute

SECRET_KEY_FALLBACKS = splitlines()
SESSION_COOKIE_SECURE = True

SPECTACULAR_SETTINGS module-attribute

SPECTACULAR_SETTINGS = {'TITLE': 'Federated Learning Demonstrator Server API', 'DESCRIPTION': '\nThis OpenAPI Specification describes the server component of the Federated Learning Demonstrator,\na sophisticated suite of tools designed for machine learning applications within a federated context.\nThis server component plays a crucial role by orchestrating and notifying all training participants to ensure seamless\nand efficient operation.\n\nThe complete Federated Learning (FL) demonstation platform acts as a proof of concept within the\n[Catena-X](https://catena-x.net/en) project.\nThe primary goal is to demonstrate the feasibility and effectiveness of federated learning in real-world scenarios.\n\nFor a comprehensive understanding and further details about the Federated Learning (FL) platform,\nplease refer to the official [FL platform documentation](https://dlr-ki.github.io/fl-documentation).\n\nUse this OpenAPI Specification to explore and interact with the various endpoints provided by the server component\nof the Federated Learning Demonstrator.\nThis specification will help developers, researchers, and data scientists to integrate, extend, and utilize\nfederated learning capabilities effectively.\n', 'VERSION': version('fl-demonstrator'), 'SERVE_AUTHENTICATION': [], 'PREPROCESSING_HOOKS': ['fl_server_api.openapi.custom_preprocessing_hook']}

SSL_FORCE module-attribute

SSL_FORCE = str2bool(get('FL_SSL_FORCE_REQUESTS'), 'test' not in argv)

STATIC_ROOT module-attribute

STATIC_ROOT = BASE_DIR / 'static'

STATIC_URL module-attribute

STATIC_URL = 'static/'

TEMPLATES module-attribute

TEMPLATES = [{'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': {'context_processors': ['django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages']}}]

TIME_ZONE module-attribute

TIME_ZONE = 'Europe/Berlin'

USE_I18N module-attribute

USE_I18N = True

USE_TZ module-attribute

USE_TZ = True

WSGI_APPLICATION module-attribute

WSGI_APPLICATION = 'fl_server.wsgi.application'

Functions

get_redis_location

get_redis_location(*, fallback_host: str = 'redis') -> str
Source code in fl_server/settings/base.py
def get_redis_location(*, fallback_host: str = "redis") -> str:
    if (location := environ.get("FL_REDIS_LOCATION")) is not None:
        return location
    host = environ.get("FL_REDIS_HOST", fallback_host)
    post = environ.get("FL_REDIS_PORT", "6379")
    return f"redis://{host}:{post}/1"

get_secret

get_secret(env_key: str, *, ensure: bool = False) -> str | None

Get secret value from an environment variable or a file.

This function first checks if there is an environment variable named "{env_key}_FILE". If such a variable exists, the function reads the secret value from the file specified by this variable. If the variable does not exist, the function retrieves the secret value from the environment variable passed by the parameter env_key.

Parameters:

Name Type Description Default

env_key

str

The name of the environment variable to retrieve the secret value from.

required

ensure

bool

If True, the function will raise a KeyError if neither "{env_key}_FILE" nor "{env_key}" is set. If False, the function will return None in this case. Defaults to False.

False

Returns:

Type Description
str | None

str | None: The secret value, or None if neither "{env_key}_FILE" nor "{env_key}" is set and ensure is False.

Raises:

Type Description
KeyError

If neither "{env_key}_FILE" nor "{env_key}" is set and ensure is True.

Source code in fl_server/settings/production.py
def get_secret(env_key: str, *, ensure: bool = False) -> str | None:
    """
    Get secret value from an environment variable or a file.

    This function first checks if there is an environment variable named "{env_key}_FILE".
    If such a variable exists, the function reads the secret value from the file specified by this variable.
    If the variable does not exist, the function retrieves the secret value from the environment variable
    passed by the parameter `env_key`.

    Args:
        env_key (str): The name of the environment variable to retrieve the secret value from.
        ensure (bool, optional): If `True`, the function will raise a `KeyError` if neither "{env_key}_FILE"
                                 nor "{env_key}" is set.
                                 If `False`, the function will return `None` in this case. Defaults to `False`.

    Returns:
        str | None: The secret value, or None if neither "{env_key}_FILE" nor "{env_key}" is set and ensure is `False`.

    Raises:
        KeyError: If neither "{env_key}_FILE" nor "{env_key}" is set and ensure is True.
    """
    if (secret_file := environ.get(f"{env_key}_FILE")) is not None:
        with open(secret_file) as f:
            return f.read().strip()

    if ensure:
        # let this throw an exception if neither SECRET_KEY_FILE nor SECRET_KEY is set
        return environ[env_key]

    return environ.get(env_key)