Skip to content

Managing

The managing module enables managing actors through the message queue. Through this application relying on cattle_grid to handle ActivityPub traffic, can create and update user.

cattle_grid.manage

router_configuration = [RoutingKeyConfig('create_actor', create_actor), RoutingKeyConfig('update_actor', update_actor)] module-attribute

Router configuration

RoutingKeyConfig dataclass

Describes a routingkey to coroutine relation

>>> config = RoutingKeyConfig("create_actor", create_actor)
Source code in cattle_grid/manage/__init__.py
@dataclass
class RoutingKeyConfig:
    """Describes a routingkey to coroutine relation

    ```pycon
    >>> config = RoutingKeyConfig("create_actor", create_actor)

    ```
    """

    routing_key: str
    """The routing key to be used"""

    handler: Coroutine
    """The coroutine that handles the message"""

handler: Coroutine instance-attribute

The coroutine that handles the message

routing_key: str instance-attribute

The routing key to be used

create_router(config)

Creates a router to be used to manage users

Parameters:

Name Type Description Default
config ManageConfig
required

Returns:

Type Description
RabbitRouter
Source code in cattle_grid/manage/__init__.py
def create_router(config: ManageConfig) -> RabbitRouter:
    """Creates a router to be used to manage users

    :param config:
    :returns:
    """

    router = RabbitRouter()
    if config.enable is False:
        return router

    exchange = RabbitExchange(config.exchange, type=ExchangeType.TOPIC)

    for routing_key_config in router_configuration:
        queue = RabbitQueue(
            routing_key_config.routing_key, routing_key=routing_key_config.routing_key
        )
        router.subscriber(queue, exchange)(routing_key_config.handler)

    return router

cattle_grid.config.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

cattle_grid.manage.models

CreateActorMessage

Bases: BaseModel

Source code in cattle_grid/manage/models.py
class CreateActorMessage(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    baseUrl: str
    """
    base url used to create the user on. Can contain a path
    """
    preferredUsername: Optional[str] = None
    """
    Add a preferred username. This name will be used in acct:username@domain and supplied to webfinger. Here domain is determine from baseUrl.
    """
    profile: Optional[Dict[str, Any]] = {}
    """
    New profile object for the actor. The fields.
    """
    autoFollow: Optional[bool] = None
    """
    Enables setting actors to automatically accept follow requests
    """

autoFollow: Optional[bool] = None class-attribute instance-attribute

Enables setting actors to automatically accept follow requests

baseUrl: str instance-attribute

base url used to create the user on. Can contain a path

preferredUsername: Optional[str] = None class-attribute instance-attribute

Add a preferred username. This name will be used in acct:username@domain and supplied to webfinger. Here domain is determine from baseUrl.

profile: Optional[Dict[str, Any]] = {} class-attribute instance-attribute

New profile object for the actor. The fields.

CreateActorResult

Bases: BaseModel

Source code in cattle_grid/manage/models.py
class CreateActorResult(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    actor: Dict[str, Any]
    """
    The actor that was created
    """

actor: Dict[str, Any] instance-attribute

The actor that was created

UpdateActorMessage

Bases: BaseModel

Allows one to update the actor object

Source code in cattle_grid/manage/models.py
class UpdateActorMessage(BaseModel):
    """
    Allows one to update the actor object
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    actor: str
    """
    The URI of the actor being updated. Must be managed by cattle_grid
    """
    profile: Optional[Dict[str, Any]] = None
    """
    New profile object for the actor. The fields.
    """
    autoFollow: Optional[bool] = None
    """
    Enables setting actors to automatically accept follow requests
    """

actor: str instance-attribute

The URI of the actor being updated. Must be managed by cattle_grid

autoFollow: Optional[bool] = None class-attribute instance-attribute

Enables setting actors to automatically accept follow requests

profile: Optional[Dict[str, Any]] = None class-attribute instance-attribute

New profile object for the actor. The fields.

Json Schema

activity_message.schema.json
{
  "$schema": "http://json-schema.org/draft-06/schema#",
  "definitions": {
    "CreateActorMessage": {
      "type": "object",
      "additionalProperties": false,
      "title": "Create Actor Message",
      "description": "",
      "properties": {
        "baseUrl": {
          "type": "string",
          "description": "base url used to create the user on. Can contain a path"
        },
        "preferredUsername": {
          "type": "string",
          "description": "Add a preferred username. This name will be used in acct:username@domain and supplied to webfinger. Here domain is determine from baseUrl."
        },
        "profile": {
          "type": "object",
          "description": "New profile object for the actor. The fields.",
          "default": {}
        },
        "autoFollow": {
          "type": "boolean",
          "description": "Enables setting actors to automatically accept follow requests"
        }
      },
      "required": ["baseUrl"]
    },
    "CreateActorResult": {
      "type": "object",
      "additionalProperties": false,
      "title": "Create Actor Result",
      "description": "",
      "properties": {
        "actor": {
          "type": "object",
          "description": "The actor that was created"
        }
      },
      "required": ["actor"]
    },
    "UpdateActorMessage": {
      "type": "object",
      "additionalProperties": false,
      "title": "Update Actor Message",
      "description": "Allows one to update the actor object",
      "properties": {
        "actor": {
          "type": "string",
          "description": "The URI of the actor being updated. Must be managed by cattle_grid"
        },
        "profile": {
          "type": "object",
          "description": "New profile object for the actor. The fields."
        },
        "autoFollow": {
          "type": "boolean",
          "description": "Enables setting actors to automatically accept follow requests"
        }
      },
      "required": ["actor"]
    }
  }
}