config#

Configuration handler for the API. The philosophies for how Rootski handles configuration come from the “12-Factor App”.

All configuration values can come from the following sources, and will be prioritized in the following order:

  1. CLI arguments (unused in this app)

  2. Environment variables

  3. Config file

  4. Default values

Note

If the name of a config value in the YAML file is “name”, then the environment variable equivalent will be ROOTSKI__NAME.




Module Attributes#

DEFAULT_PORT

default port for the FastAPI server to listen on

DEFAULT_HOST

default host for the FastAPI server to listen on

DEFAULT_DOMAIN

default domain for the API (used for CORS and may be for other things)

DEFAULT_S3_STATIC_SITE_DOMAIN

// URL of the S3 bucket containing the static frontend files

YAML_CONFIG_PATH_ENV_VAR

environment variable where the rootski API config file should be found

rootski.config.config.DEFAULT_PORT: int = 3333#

default port for the FastAPI server to listen on

rootski.config.config.DEFAULT_HOST: str = '0.0.0.0'#

default host for the FastAPI server to listen on

rootski.config.config.DEFAULT_DOMAIN: str = 'www.rootski.io'#

default domain for the API (used for CORS and may be for other things)

rootski.config.config.DEFAULT_S3_STATIC_SITE_DOMAIN = 'http://io.rootski.www.s3-website-us-west-2.amazonaws.com'#

// URL of the S3 bucket containing the static frontend files

Type

default http

rootski.config.config.YAML_CONFIG_PATH_ENV_VAR: str = 'ROOTSKI__CONFIG_FILE_PATH'#

environment variable where the rootski API config file should be found




Functions#

aws_parameter_store_settings_source

Fetch app settings from AWS SSM Parameter Store.

default_settings

Default values for certain app settings.

get_environ_name

Get the environment variable name for a given config value.

load_config_from_yaml

Read config from a YAML file.

yaml_config_settings_source

App settings from the yaml config file.

aws_parameter_store_settings_source()#

rootski.config.config.aws_parameter_store_settings_source(settings: rootski.config.config.Config) Dict[str, Any][source]#

Fetch app settings from AWS SSM Parameter Store.

If a previous settings provider has set the fetch_values_from_ssm value to False, this function will not attempt to fetch values from SSM.

default_settings()#

rootski.config.config.default_settings(settings: rootski.config.config.Config) Dict[str, Any][source]#

Default values for certain app settings.

get_environ_name()#

rootski.config.config.get_environ_name(name: str) str[source]#

Get the environment variable name for a given config value.

load_config_from_yaml()#

rootski.config.config.load_config_from_yaml(config_fpath: str) Dict[str, str][source]#

Read config from a YAML file.

yaml_config_settings_source()#

rootski.config.config.yaml_config_settings_source(settings: rootski.config.config.Config) Dict[str, Any][source]#

App settings from the yaml config file.




Classes#

Config

A configuration manager for the app.

LogLevel

Logging levels.

class Config#

class rootski.config.config.Config(*, log_level: rootski.config.config.LogLevel = 'INFO', host: str = '0.0.0.0', port: int = 3333, domain: str = 'www.rootski.io', s3_static_site_origin: str = 'http://io.rootski.www.s3-website-us-west-2.amazonaws.com', cognito_aws_region: str, cognito_user_pool_id: str, cognito_web_client_id: str, static_assets_dir: str = '/rootski/rootski_api/static', extra_allowed_cors_origins: List[pydantic.networks.AnyHttpUrl] = [], dynamo_table_name: str = 'rootski-table')[source]#

Bases: pydantic.env_settings.BaseSettings

A configuration manager for the app.

Configuration values are discovered and kept in the following order of priority:

  1. Init arguments (could be used to give CLI arguments highest priority)

  2. Environment variables of the form <ENVIRON_PREFIX>UPPER_CASE_ATTRIBUTE

  3. Config yaml file, whose location is at <ENVIRON_PREFIX>CONFIG_FILE_PATH

  4. Default values set in this dataclass

Note

When using environment variables, values should be JSON formatted strings. For example, "link1,link2,link3" would fail for extra_allowed_cors_origins, but '["link1", "link2", "link3"]' would work.

Note

This __init__() method only exists so that there is a class-level docstring in the sphinx documentation.

classmethod assemble_cors_origins(v: Union[str, List[str]]) Union[List[str], str][source]#

Ensure extra_allowed_cors_origins is a valid list of strings. Parse it from a str to a List[str] if needed.

property cognito_public_keys_url: str#

URL of Cognito public keys used to validate cognito issued JWT tokens for the Rootski user pool.

classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) Model#

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) Model#

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns

new model instance

dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny#

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) unicode#

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None#

Try to update ForwardRefs on fields based on this Model, globalns and localns.

class LogLevel#

class rootski.config.config.LogLevel(value)[source]#

Bases: str, enum.Enum

Logging levels.