SMTP Integrator

  • Canonical IS DevOps
Channel Revision Published Runs on
latest/stable 45 19 Aug 2024
Ubuntu 22.04
latest/edge 52 07 Oct 2024
Ubuntu 22.04
juju deploy smtp-integrator
Show information

Platform:

Ubuntu
22.04

charms.smtp_integrator.v0.smtp

Library to manage the integration with the SMTP Integrator charm.

This library contains the Requires and Provides classes for handling the integration between an application and a charm providing the smtp and smtp-legacy integrations. If the requirer charm supports secrets, the preferred approach is to use the smtp relation to leverage them. This library also contains a SmtpRelationData class to wrap the SMTP data that will be shared via the integration.

Requirer Charm

from charms.smtp_integrator.v0.smtp import SmtpDataAvailableEvent, SmtpRequires

class SmtpRequirerCharm(ops.CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.smtp = smtp.SmtpRequires(self)
        self.framework.observe(self.smtp.on.smtp_data_available, self._handler)
        ...

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

As shown above, the library provides a custom event to handle the scenario in which new SMTP data has been added or updated.

Provider Charm

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

from charms.smtp_integrator.v0.smtp import SmtpProvides

class SmtpProviderCharm(ops.CharmBase):
    def __init__(self, *args):
        super().__init__(*args)
        self.smtp = SmtpProvides(self)
        ...

The SmtpProvides 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 SmtpRelationData data object.

class SmtpProviderCharm(ops.CharmBase):
    ...

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


class TransportSecurity

Represent the transport security values.

Attributes

NONE
none
STARTTLS
starttls
TLS
tls

class AuthType

Represent the auth type values.

Attributes

NONE
none
NOT_PROVIDED
not_provided
PLAIN
plain

class SmtpRelationData

Represent the relation data.

Attributes

host
The hostname or IP address of the outgoing SMTP relay.
port
The port of the outgoing SMTP relay.
user
The SMTP AUTH user to use for the outgoing SMTP relay.
password
The SMTP AUTH password to use for the outgoing SMTP relay.
password_id
The secret ID where the SMTP AUTH password for the SMTP relay is stored.
auth_type
The type used to authenticate with the SMTP relay.
transport_security
The security protocol to use for the outgoing SMTP relay.
domain
The domain used by the emails sent from SMTP relay.
skip_ssl_verify
Specifies if certificate trust verification is skipped in the SMTP relay.

Methods

SmtpRelationData. to_relation_data( self )

Convert an instance of SmtpRelationData to the relation representation.

Returns

Dict containing the representation.

class SmtpDataAvailableEvent

Smtp event emitted when relation data has changed.

Attributes

host
The hostname or IP address of the outgoing SMTP relay.
port
The port of the outgoing SMTP relay.
user
The SMTP AUTH user to use for the outgoing SMTP relay.
password
The SMTP AUTH password to use for the outgoing SMTP relay.
password_id
The secret ID where the SMTP AUTH password for the SMTP relay is stored.
auth_type
The type used to authenticate with the SMTP relay.
transport_security
The security protocol to use for the outgoing SMTP relay.
domain
The domain used by the emails sent from SMTP relay.
skip_ssl_verify
Specifies if certificate trust verification is skipped in the SMTP relay.

Methods

SmtpDataAvailableEvent. host( self )

Description

Fetch the SMTP host from the relation. None

SmtpDataAvailableEvent. port( self )

Description

Fetch the SMTP port from the relation. None

SmtpDataAvailableEvent. user( self )

Description

Fetch the SMTP user from the relation. None

SmtpDataAvailableEvent. password( self )

Description

Fetch the SMTP password from the relation. None

SmtpDataAvailableEvent. password_id( self )

Description

Fetch the SMTP password from the relation. None

SmtpDataAvailableEvent. auth_type( self )

Description

Fetch the SMTP auth type from the relation. None

SmtpDataAvailableEvent. transport_security( self )

Description

Fetch the SMTP transport security protocol from the relation. None

SmtpDataAvailableEvent. domain( self )

Description

Fetch the SMTP domain from the relation. None

SmtpDataAvailableEvent. skip_ssl_verify( self )

Description

Fetch the skip_ssl_verify flag from the relation. None

class SmtpRequiresEvents

SMTP events.

Attributes

smtp_data_available
the SmtpDataAvailableEvent.

Description

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

class SmtpRequires

Requirer side of the SMTP relation.

Attributes

on
events the provider can emit.

Methods

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

Construct.

Arguments

charm

the provider charm.

relation_name

the relation name.

SmtpRequires. get_relation_data( self )

Retrieve the relation data.

Returns

SmtpRelationData

the relation data.

class SmtpProvides

Description

Provider side of the SMTP relation. None

Methods

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

Construct.

Arguments

charm

the provider charm.

relation_name

the relation name.

SmtpProvides. update_relation_data( self , relation , smtp_data: SmtpRelationData )

Update the relation data.

Arguments

relation

the relation for which to update the data.

smtp_data

a SmtpRelationData instance wrapping the data to be updated.