Skip to content

cattle_grid.extensions.examples.simple_register

This extension is meant to create an endpoint, where people can register. It is deployed on dev.bovine.social, and can be seen as an opportunity to test cattle_grid’s public APIs.

Sample configuration, see RegisterConfiguration for details.

[[extensions]]
module = "cattle_grid.extensions.examples.simple_register"
api_prefix = "/simple_register"

[[extensions.config.registration_types]]
name = "dev"
permissions = ["dev"]
extra_parameters = ["fediverse"]
create_default_actor_on = "https://dev.bovine.social"

The parameter create_default_actor_on causes an actor to be created. It will

  • have the acct-uri acct:{name}@dev.bovine.social.
  • be linked to the account name with the name default.
  • automatically accept followers.

extension module-attribute

extension = Extension(
    "simple_register",
    __name__,
    config_class=RegisterConfiguration,
)

Definition of the extension

config

RegisterConfiguration

Bases: BaseModel

Configuration for the register endpoint

Parameters:

Name Type Description Default
registration_types list[RegistrationType]

List of registration types

required
Source code in cattle_grid/extensions/examples/simple_register/config.py
class RegisterConfiguration(BaseModel):
    """Configuration for the register endpoint"""

    registration_types: list[RegistrationType] = Field(
        examples=[
            RegistrationType(name="dev", permissions=["dev"]),
        ],
        description="List of registration types",
    )

RegistrationType

Bases: BaseModel

Configuration for one registration path

Parameters:

Name Type Description Default
name str

name of the registration. Will be part of the path, i.e. /register/{name}

required
permissions list[str]

List of permissions given to the registering account.

required
extra_parameters list[str]

Extra parameters that should be in the request, will be stored in the actors meta information

[]
create_default_actor_on str | None

Attempt to create an actor on the specified base_url. The actor will be given the acct-uri acct:{name}@{domain}, where domain is taken from the base_url

None
Source code in cattle_grid/extensions/examples/simple_register/config.py
class RegistrationType(BaseModel):
    """Configuration for one registration path"""

    name: str = Field(
        examples=["dev"],
        description="name of the registration. Will be part of the path, i.e. `/register/{name}`",
    )

    permissions: list[str] = Field(
        examples=["admin"],
        description="List of permissions given to the registering account.",
        min_length=1,
    )

    extra_parameters: list[str] = Field(
        default=[],
        description="Extra parameters that should be in the request, will be stored in the actors meta information",
        examples=["fediverse"],
    )

    create_default_actor_on: str | None = Field(
        default=None,
        examples=["http://domain.example"],
        description="Attempt to create an actor on the specified base_url. The actor will be given the acct-uri `acct:{name}@{domain}`, where domain is taken from the base_url",
    )

    @model_validator(mode="after")
    def check_default_actor_on_is_allowed(self) -> Self:
        if not self.create_default_actor_on:
            return self
        allowed_base_urls = base_urls_for_permissions(self.permissions)

        if self.create_default_actor_on not in allowed_base_urls:
            raise Exception("Base url is not allowed")

        return self