Config#

class gafaelfawr.config.Config(**data)#

Bases: EnvFirstSettings

Configuration for Gafaelfawr.

Parameters:

data (Any)

Attributes Summary

add_user_group

Whether to add a synthetic private user group.

base_hostname

Realm to use for HTTP authentication.

cookie_parameters

Parameters to pass to fastapi.Response.set_cookie.

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

redis_rate_limit_url

Redis DSN to use for rate limiting.

Methods Summary

configure_logging()

Configure logging based on the Gafaelfawr configuration.

from_file(path)

Construct a Config object from a configuration file.

get_scopes_for_group(group)

Return the scopes granted by a given group membership.

is_hostname_allowed(hostname)

Check whether a hostname is within the Gafaelfawr domain.

model_post_init(context, /)

This function is meant to behave like a BaseModel method to initialise private attributes.

Attributes Documentation

add_user_group#

Whether to add a synthetic private user group.

base_hostname#

Realm to use for HTTP authentication.

cookie_parameters#

Parameters to pass to fastapi.Response.set_cookie.

model_config: ClassVar[SettingsConfigDict] = {'alias_generator': <function to_camel>, 'arbitrary_types_allowed': True, 'case_sensitive': False, 'cli_avoid_json': False, 'cli_enforce_required': False, 'cli_exit_on_error': True, 'cli_flag_prefix_char': '-', 'cli_hide_none_type': False, 'cli_ignore_unknown_args': False, 'cli_implicit_flags': False, 'cli_kebab_case': False, 'cli_parse_args': None, 'cli_parse_none_str': None, 'cli_prefix': '', 'cli_prog_name': None, 'cli_shortcuts': None, 'cli_use_class_docs_for_groups': False, 'enable_decoding': True, 'env_file': None, 'env_file_encoding': None, 'env_ignore_empty': False, 'env_nested_delimiter': None, 'env_nested_max_split': None, 'env_parse_enums': None, 'env_parse_none_str': None, 'env_prefix': '', 'extra': 'forbid', 'json_file': None, 'json_file_encoding': None, 'nested_model_default_partial_update': False, 'populate_by_name': True, 'protected_namespaces': ('model_validate', 'model_dump', 'settings_customise_sources'), 'secrets_dir': None, 'toml_file': None, 'validate_by_alias': True, 'validate_by_name': True, 'validate_default': True, 'yaml_config_section': None, 'yaml_file': None, 'yaml_file_encoding': None}#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

redis_rate_limit_url#

Redis DSN to use for rate limiting.

The limits package requires the Redis DSN in a specific format with the password already included.

Methods Documentation

configure_logging()#

Configure logging based on the Gafaelfawr configuration.

Return type:

None

classmethod from_file(path)#

Construct a Config object from a configuration file.

Parameters:

path (Path) – Path to the configuration file in YAML.

Returns:

The corresponding Config object.

Return type:

Config

get_scopes_for_group(group)#

Return the scopes granted by a given group membership.

Parameters:

group (str) – Name of the group.

Returns:

Scopes granted by that group membership. This will be the empty set if the group was not recognized.

Return type:

frozenset of str

is_hostname_allowed(hostname)#

Check whether a hostname is within the Gafaelfawr domain.

Numerous places in Gafaelfawr want to allow only hostnames that fall within the base domain of Gafaelfawr. If subdomains are disabled, the hostname must match the base hostname exactly. If subdomains are allowed, the hostname must be a subdomain of that base domain.

Parameters:

hostname (str | None) – Hostname to check. None is allowed for typing convenience but is always rejected.

Returns:

Whether that hostname is allowed for this Gafaelfawr instance.

Return type:

bool

model_post_init(context, /)#

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.

Parameters:
  • self (BaseModel)

  • context (Any)

Return type:

None