.exchange
cattle_grid.exchange
create_router(main_exchange=exchange())
Creates a router to be used to manage users
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
|
required |
Returns:
| Type | Description |
|---|---|
RabbitRouter
|
|
Source code in cattle_grid/exchange/__init__.py
actor_handlers
create_actor(msg)
async
Creates a user. Routing_key create_user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
CreateActorMessage
|
|
required |
Returns:
| Type | Description |
|---|---|
CreateActorResult
|
|
Source code in cattle_grid/exchange/actor_handlers.py
delete_actor(msg)
async
update_actor(msg)
async
Should be used asynchronously
Source code in cattle_grid/exchange/actor_handlers.py
data_types
ActivityMessage
Bases: BaseModel
Message that contains an Activity. Activity is used as the name for the ‘data object’ being exchanged, as is common in the Fediverse
Source code in cattle_grid/exchange/data_types.py
actor: str = Field(description='\n actor_id of the actor that received the message\n ', examples=['http://local.example/actor'])
class-attribute
instance-attribute
data: Activity = Field(description='\n Activity.\n ')
class-attribute
instance-attribute
DeleteActorMessage
Bases: BaseModel
Allows one to delete the actor object
Source code in cattle_grid/exchange/data_types.py
UpdateActorMessage
Bases: BaseModel
Allows one to update the actor object
Source code in cattle_grid/exchange/data_types.py
gateway
The exchanges used by cattle_grid are using routing keys to make processing easier. The cattle_grid gateway takes these messages and readdresses them with routing keys based on an user. Here an user can have multiple actors.
Furthermore, convenience methods are provided to manage users and actors through a HTTP Api. This is in difference to interacting with the Fediverse, which is done through a message queue.
create_gateway_router()
Creates a router that moves messages to be routed by user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
|
required |
Returns:
| Type | Description |
|---|---|
RabbitRouter
|
|
Source code in cattle_grid/exchange/gateway/__init__.py
data_types
Action
Action to be taken by the gateway
Source code in cattle_grid/exchange/gateway/data_types.py
Action1
GatewayMessage
Bases: BaseModel
Message send to the gateway then forwarded to cattle_grid
Source code in cattle_grid/exchange/gateway/data_types.py
action: Action
instance-attribute
Action to be taken by the gateway
actor: str
instance-attribute
actor_id of the actor that is performing the action. Actor must belong to the user
data: Dict[str, Any]
instance-attribute
Activity to be send or object to fetch/delete etc … not sure yet. this seems awkward
GatewayMessageResult
Bases: BaseModel
Message send from the gateway
Source code in cattle_grid/exchange/gateway/data_types.py
action: Action1
instance-attribute
Action taken by the gateway
actor: str
instance-attribute
actor_id of the actor that is receiving the message.
data: Dict[str, Any]
instance-attribute
Received data.
router
handle_manage_actor(msg, actor=Depends(actor), broker=Context())
async
Updates the actor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker
|
RabbitBroker
|
|
Context()
|
actor
|
Actor
|
|
Depends(actor)
|
msg
|
GatewayMessage
|
|
required |
Source code in cattle_grid/exchange/gateway/router.py
name_from_routing_key(routing_key)
message_handlers
send_message(msg, broker=Context())
async
Takes a message and ensure it is distributed appropriatelty
Source code in cattle_grid/exchange/message_handlers.py
server
gateway_auth_router = APIRouter(prefix='/admin')
module-attribute
Blueprint to be included to provide the endpoints for authentication with rabbitmq
create_exchange_api_router(config)
Creates a blueprint for HTTP methods of the gateway. One should note that these mostly exist to fulfill secondary concerns of the gateway. Most of the work is done by the router.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
LazySettings
|
|
required |
Returns:
| Type | Description |
|---|---|
APIRouter
|
|
Source code in cattle_grid/exchange/server/__init__.py
rabbit
Implementation of a HTTP auth backend for rabbitmq.
A possible configuration can be in the form of
auth_backends.1 = internal
auth_backends.2 = http
auth_http.http_method = post
auth_http.user_path = http://cattle_grid_app/admin/rabbitmq/user
auth_http.vhost_path = http://cattle_grid_app/admin/rabbitmq/vhost
auth_http.resource_path = http://cattle_grid_app/admin/rabbitmq/resource
auth_http.topic_path = http://cattle_grid_app/admin/rabbitmq/topic
topic_auth(username, name, routing_key)
async
Checks if topic is allowed. Currently allowed are
and the routing keys send.username and receive.username
Source code in cattle_grid/exchange/server/rabbit.py
user_auth(username, password)
async
Checks login with username/password
Source code in cattle_grid/exchange/server/rabbit.py
vhost_auth(username, vhost)
async
Authentication for vhosts, currently only “/” is allowed
Source code in cattle_grid/exchange/server/rabbit.py
shovel
incoming_shovel(msg, broker=Context(), routing_key=Context('message.raw_message.routing_key'))
async
Transforms and resends the incoming activity