Synapse

  • By Canonical IS DevOps
Channel Revision Published Runs on
latest/stable 414 16 Sep 2024
Ubuntu 22.04
latest/edge 421 Today
Ubuntu 22.04
1/stable 303 30 Jul 2024
Ubuntu 22.04
1/edge 345 31 Jul 2024
Ubuntu 22.04
juju deploy synapse
Show information

Platform:

charms.synapse.v0.matrix_auth

Library to manage the plugin integrations with the Synapse charm.

This library contains the Requires and Provides classes for handling the integration between an application and a charm providing the matrix_plugin integration.

Requirer Charm

from charms.synapse.v0.matrix_auth import MatrixAuthRequires

class MatrixAuthRequirerCharm(ops.CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.plugin_auth = MatrixAuthRequires(self)
        self.framework.observe(self.matrix_auth.on.matrix_auth_request_processed, self._handler)
        ...

    def _handler(self, events: MatrixAuthRequestProcessed) -> None:
        ...

As shown above, the library provides a custom event to handle the scenario in which a matrix authentication (homeserver and shared secret) has been added or updated.

The MatrixAuthRequires provides an update_relation_data method to update the relation data by passing a MatrixAuthRequirerData data object, requesting a new authentication.

Provider Charm

Following the previous example, this is an example of the provider charm.

from charms.synapse.v0.matrix_auth import MatrixAuthProvides

class MatrixAuthProviderCharm(ops.CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.plugin_auth = MatrixAuthProvides(self)
        ...

The MatrixAuthProvides object wraps the list of relations into a relations property and provides an update_relation_data method to update the relation data by passing a MatrixAuthRelationData data object.

class MatrixAuthProviderCharm(ops.CharmBase):
    ...

    def _on_config_changed(self, _) -> None:
        for relation in self.model.relations[self.plugin_auth.relation_name]:
            self.plugin_auth.update_relation_data(relation, self._get_matrix_auth_data())


class MatrixAuthProviderData

Represent the MatrixAuth provider data.

Attributes

homeserver
the homeserver URL.
shared_secret
the Matrix shared secret.
shared_secret_id
the shared secret Juju secret ID.

Methods

MatrixAuthProviderData. set_shared_secret_id( self , model , relation )

Store the Matrix shared secret as a Juju secret.

Arguments

model

the Juju model

relation

relation to grant access to the secrets to.

MatrixAuthProviderData. get_shared_secret( cls , model , shared_secret_id )

Retrieve the shared secret corresponding to the shared_secret_id.

Arguments

model

the Juju model.

shared_secret_id

the secret ID for the shared secret.

Returns

the shared secret or None if not found.

MatrixAuthProviderData. to_relation_data( self , model , relation )

Convert an instance of MatrixAuthProviderData to the relation representation.

Arguments

model

the Juju model.

relation

relation to grant access to the secrets to.

Returns

Dict containing the representation.

MatrixAuthProviderData. from_relation( cls , model , relation )

Initialize a new instance of the MatrixAuthProviderData class from the relation.

Arguments

relation

the relation.

Returns

A MatrixAuthProviderData instance.

class MatrixAuthRequirerData

Represent the MatrixAuth requirer data.

Attributes

registration
a generated app registration file.
registration_id
the registration Juju secret ID.

Methods

MatrixAuthRequirerData. set_registration_id( self , model , relation )

Store the app registration as a Juju secret.

Arguments

model

the Juju model

relation

relation to grant access to the secrets to.

MatrixAuthRequirerData. get_registration( cls , model , registration_secret_id )

Retrieve the registration corresponding to the registration_secret_id.

Arguments

model

the Juju model.

registration_secret_id

the secret ID for the registration.

Returns

the registration or None if not found.

MatrixAuthRequirerData. to_relation_data( self , model , relation )

Convert an instance of MatrixAuthRequirerData to the relation representation.

Arguments

model

the Juju model.

relation

relation to grant access to the secrets to.

Returns

Dict containing the representation.

MatrixAuthRequirerData. from_relation( cls , model , relation )

Get a MatrixAuthRequirerData from the relation data.

Arguments

model

the Juju model.

relation

the relation.

Returns

the relation data and the processed entries for it.

class MatrixAuthRequestProcessed

Description

MatrixAuth event emitted when a new request is processed. None

Methods

MatrixAuthRequestProcessed. get_matrix_auth_provider_relation_data( self )

Get a MatrixAuthProviderData for the relation data.

Returns

the MatrixAuthProviderData for the relation data.

class MatrixAuthRequestReceived

Description

MatrixAuth event emitted when a new request is made. None

class MatrixAuthRequiresEvents

MatrixAuth requirer events.

Attributes

matrix_auth_request_processed
the MatrixAuthRequestProcessed.

Description

This class defines the events that a MatrixAuth requirer can emit.

class MatrixAuthProvidesEvents

MatrixAuth provider events.

Attributes

matrix_auth_request_received
the MatrixAuthRequestReceived.

Description

This class defines the events that a MatrixAuth provider can emit.

class MatrixAuthRequires

Requirer side of the MatrixAuth requires relation.

Attributes

on
events the provider can emit.

Methods

MatrixAuthRequires. __init__( self , charm , relation_name: str )

Construct.

Arguments

charm

the provider charm.

relation_name

the relation name.

MatrixAuthRequires. get_remote_relation_data( self )

Retrieve the remote relation data.

Returns

MatrixAuthProviderData

the relation data.

MatrixAuthRequires. update_relation_data( self , relation , matrix_auth_requirer_data: MatrixAuthRequirerData )

Update the relation data.

Arguments

relation

the relation for which to update the data.

matrix_auth_requirer_data

MatrixAuthRequirerData wrapping the data to be updated.

class MatrixAuthProvides

Provider side of the MatrixAuth relation.

Attributes

on
events the provider can emit.

Methods

MatrixAuthProvides. __init__( self , charm , relation_name: str )

Construct.

Arguments

charm

the provider charm.

relation_name

the relation name.

MatrixAuthProvides. get_remote_relation_data( self )

Retrieve the remote relation data.

Returns

MatrixAuthRequirerData

the relation data.

MatrixAuthProvides. update_relation_data( self , relation , matrix_auth_provider_data: MatrixAuthProviderData )

Update the relation data.

Arguments

relation

the relation for which to update the data.

matrix_auth_provider_data

a MatrixAuthProviderData instance wrapping the data to be updated.