Skip to content

config

cattle_grid.config

AuthConfig

Bases: BaseModel

Configures the Authorization layer

Source code in cattle_grid/config/__init__.py
class AuthConfig(BaseModel):
    """Configures the Authorization layer"""

    enabled: bool = False
    """Enables the auth router"""

    actor_id: str | None = None
    """actor_id for the Application actor used to fetch public keys"""
    actor_acct_id: str | None = None
    """acct uri of the Application Actor used to fetch public keys"""
    public_key: str | None = None
    """Public key of the Application actor"""
    private_key: str | None = None
    """Private key of the Application actor"""

    domain_blocks: set = Field(default_factory=set)
    """Set of blocked domains"""

    @field_serializer("domain_blocks")
    def serialize_domain_blocks(self, domain_blocks: set, _info):
        return list(domain_blocks)

    def model_post_init(self, __context):
        if self.private_key is None:
            self.public_key, self.private_key = generate_rsa_public_private_key()

actor_acct_id: str | None = None class-attribute instance-attribute

acct uri of the Application Actor used to fetch public keys

actor_id: str | None = None class-attribute instance-attribute

actor_id for the Application actor used to fetch public keys

domain_blocks: set = Field(default_factory=set) class-attribute instance-attribute

Set of blocked domains

enabled: bool = False class-attribute instance-attribute

Enables the auth router

private_key: str | None = None class-attribute instance-attribute

Private key of the Application actor

public_key: str | None = None class-attribute instance-attribute

Public key of the Application actor

Config

Bases: BaseModel

Configuration of CattleGrid

>>> import tomli_w
>>> config = Config()
>>> print(tomli_w.dumps(config.model_dump(exclude_none=True)))
version = 2
amqp_uri = "amqp://guest:guest@rabbitmq:5672/"
db_uri = "sqlite://cattle_grid.db"
enable_reporting = false
<BLANKLINE>
[auth]
enabled = false
public_key = "..."
private_key = "..."
domain_blocks = []
<BLANKLINE>
[gateway]
enable = false
enable_authentication = true
<BLANKLINE>
[gateway.admin]
enable_reset = false
enable = false
<BLANKLINE>
[manage]
enable = false
exchange = "manage"
<BLANKLINE>
Source code in cattle_grid/config/__init__.py
class Config(BaseModel):
    """Configuration of CattleGrid

    ```pycon
    >>> import tomli_w
    >>> config = Config()
    >>> print(tomli_w.dumps(config.model_dump(exclude_none=True)))
    version = 2
    amqp_uri = "amqp://guest:guest@rabbitmq:5672/"
    db_uri = "sqlite://cattle_grid.db"
    enable_reporting = false
    <BLANKLINE>
    [auth]
    enabled = false
    public_key = "..."
    private_key = "..."
    domain_blocks = []
    <BLANKLINE>
    [gateway]
    enable = false
    enable_authentication = true
    <BLANKLINE>
    [gateway.admin]
    enable_reset = false
    enable = false
    <BLANKLINE>
    [manage]
    enable = false
    exchange = "manage"
    <BLANKLINE>

    ```
    """

    version: int = 2
    amqp_uri: str = "amqp://guest:guest@rabbitmq:5672/"
    db_uri: str = "sqlite://cattle_grid.db"
    enable_reporting: bool = False
    """Set to true to enable [reporting](./reporting.md)"""

    auth: AuthConfig = Field(default_factory=AuthConfig)
    gateway: GatewayConfig = Field(default_factory=GatewayConfig)
    manage: ManageConfig = Field(default_factory=ManageConfig)

enable_reporting: bool = False class-attribute instance-attribute

Set to true to enable reporting

GatewayAdminConfig

Bases: BaseModel

Controls the Admin features of the Gateway

Source code in cattle_grid/config/__init__.py
class GatewayAdminConfig(BaseModel):
    """Controls the Admin features of the Gateway"""

    enable_reset: bool = False
    """Enables deleting all users and actors, useful for testing"""
    enable: bool = False
    """Enables the gateway"""

enable: bool = False class-attribute instance-attribute

Enables the gateway

enable_reset: bool = False class-attribute instance-attribute

Enables deleting all users and actors, useful for testing

GatewayConfig

Bases: BaseModel

Controls the Gateway

Source code in cattle_grid/config/__init__.py
class GatewayConfig(BaseModel):
    """Controls the Gateway"""

    enable: bool = False
    """enables the gateway"""

    admin: GatewayAdminConfig = Field(default_factory=GatewayAdminConfig)
    """admin configuration"""

    enable_authentication: bool = True
    """Enable the endpoints provided by [rabbit_blueprint][cattle_grid.gateway.auth.rabbit_blueprint] to be used with rabbitmq http authentication"""

admin: GatewayAdminConfig = Field(default_factory=GatewayAdminConfig) class-attribute instance-attribute

admin configuration

enable: bool = False class-attribute instance-attribute

enables the gateway

enable_authentication: bool = True class-attribute instance-attribute

Enable the endpoints provided by [rabbit_blueprint][cattle_grid.gateway.auth.rabbit_blueprint] to be used with rabbitmq http authentication

ManageConfig

Bases: BaseModel

Configures managing

Source code in cattle_grid/config/__init__.py
class ManageConfig(BaseModel):
    """Configures managing"""

    enable: bool = False
    """Set to true to enable"""
    exchange: str = "manage"
    """RabbitMQ exchange name"""

enable: bool = False class-attribute instance-attribute

Set to true to enable

exchange: str = 'manage' class-attribute instance-attribute

RabbitMQ exchange name

load_config(filename='cattle_grid.toml')

loads the configuration from file

Parameters:

Name Type Description Default
filename
'cattle_grid.toml'

Returns:

Type Description
Config
Source code in cattle_grid/config/__init__.py
def load_config(filename="cattle_grid.toml") -> Config:
    """loads the configuration from file

    :param filename:
    :returns:
    """

    if os.path.exists(filename):
        with open(filename, "rb") as fp:
            return Config.model_validate(tomllib.load(fp))

    return Config()