Skip to content

cattle_grid.extensions.examples.webfinger_lookup

Puts performing a webfinger lookup in the processing chain. In a production setting, one can include this extension via

cattle_grid.toml
[[extensions]]
module = "cattle_grid.extensions.examples.webfinger_lookup"

lookup_order = 10

Where the higher the lookup_order, the earlier the conversion from acct to resolvable URI happens.

In a test setting, one can make webfinger use http via

cattle_grid.toml
[[extensions]]
module = "cattle_grid.extensions.examples.webfinger_lookup"

config = { protocol = "http" }

Protocol

Bases: StrEnum

Protocol to use for webfinger lookups

Source code in cattle_grid/extensions/examples/webfinger_lookup.py
class Protocol(StrEnum):
    """Protocol to use for webfinger lookups"""

    http = auto()
    https = auto()

WebfingerLookupConfig

Bases: BaseModel

Configuration for the webfinger lookup

Parameters:

Name Type Description Default
protocol Protocol

protocol to use, defaults to https

<Protocol.https: 'https'>
Source code in cattle_grid/extensions/examples/webfinger_lookup.py
class WebfingerLookupConfig(BaseModel):
    """Configuration for the webfinger lookup"""

    protocol: Protocol = Field(
        default=Protocol.https, description="""protocol to use, defaults to https"""
    )

build_domain

build_domain(
    config: WebfingerLookupConfig, acct_uri: str
) -> str

Builds the domain to use for webfinger lookups

>>> build_domain(WebfingerLookupConfig(protocol=Protocol.http),
...     "acct:alice@server.example")
'http://server.example'
Source code in cattle_grid/extensions/examples/webfinger_lookup.py
def build_domain(config: WebfingerLookupConfig, acct_uri: str) -> str:
    """Builds the domain to use for webfinger lookups

    ```pycon
    >>> build_domain(WebfingerLookupConfig(protocol=Protocol.http),
    ...     "acct:alice@server.example")
    'http://server.example'

    ```
    """
    return f"{config.protocol}://{acct_uri.split('@')[1]}"