Skip to content

Commit

Permalink
Add SMTP configuration (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
amandahla authored Oct 4, 2023
1 parent 0f389c5 commit fce8bfb
Show file tree
Hide file tree
Showing 21 changed files with 604 additions and 430 deletions.
51 changes: 38 additions & 13 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,51 @@
# See LICENSE file for licensing details.

options:
server_name:
enable_mjolnir:
type: boolean
default: false
description: |
Configures whether to enable Mjolnir - moderation tool for Matrix.
Reference: https://github.com/matrix-org/mjolnir
public_baseurl:
type: string
description: |
Synapse server name. Must be set to deploy the charm. Corresponds to the
server_name option on Synapse configuration file and sets the
public-facing domain of the server.
The public-facing base URL that clients use to access this Homeserver.
Defaults to https://<server_name>/. Only used if there is integration with
SAML integrator charm.
report_stats:
description: |
Configures whether to report statistics.
default: false
type: boolean
public_baseurl:
server_name:
type: string
description: |
The public-facing base URL that clients use to access this Homeserver.
Defaults to https://<server_name>/. Only used if there is integration with
SAML integrator charm.
enable_mjolnir:
Synapse server name. Must be set to deploy the charm. Corresponds to the
server_name option on Synapse configuration file and sets the
public-facing domain of the server.
smtp_enable_tls:
type: boolean
default: false
description: |
Configures whether to enable Mjolnir - moderation tool for Matrix.
Reference: https://github.com/matrix-org/mjolnir
description: If enabled, STARTTLS will be used to use an encrypted SMTP
connection.
default: true
smtp_host:
type: string
description: The hostname of the SMTP host used for sending emails.
default: ''
smtp_notif_from:
type: string
description: defines the "From" address to use when sending emails.
It must be set if email sending is enabled. Defaults to server_name.
smtp_pass:
type: string
description: The password if the SMTP server requires authentication.
default: ''
smtp_port:
type: int
description: The port of the SMTP server used for sending emails.
default: 25
smtp_user:
type: string
description: The username if the SMTP server requires authentication.
default: ''
4 changes: 2 additions & 2 deletions src-docs/charm.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Unit that this execution is responsible for.

---

<a href="../src/charm.py#L85"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L89"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `change_config`

Expand All @@ -81,7 +81,7 @@ Change configuration.

---

<a href="../src/charm.py#L75"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L79"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `replan_nginx`

Expand Down
127 changes: 37 additions & 90 deletions src-docs/charm_state.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Exception raised when a charm configuration is found to be invalid.

Attrs: msg (str): Explanation of the error.

<a href="../src/charm_state.py#L40"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm_state.py#L45"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

Expand All @@ -42,143 +42,90 @@ Initialize a new instance of the CharmConfigInvalidError exception.
## <kbd>class</kbd> `CharmState`
State of the Charm.

Attrs: server_name: server_name config. report_stats: report_stats config. public_baseurl: public_baseurl config. enable_mjolnir: enable_mjolnir config. datasource: datasource information. saml_config: saml configuration.

<a href="../src/charm_state.py#L101"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `__init__`

```python
__init__(
synapse_config: SynapseConfig,
datasource: Optional[DatasourcePostgreSQL],
saml_config: Optional[SAMLConfiguration]
) → None
```

Construct.



**Args:**
**Attributes:**

- <b>`synapse_config`</b>: The value of the synapse_config charm configuration.
- <b>`datasource`</b>: Datasource information.
- <b>`saml_config`</b>: SAML configuration.


---
- <b>`synapse_config`</b>: synapse configuration.
- <b>`datasource`</b>: datasource information.
- <b>`saml_config`</b>: saml configuration.

#### <kbd>property</kbd> datasource

Return datasource.



**Returns:**
datasource or None.

---

#### <kbd>property</kbd> enable_mjolnir

Return enable_mjolnir config.
<a href="../src/charm_state.py#L139"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>classmethod</kbd> `from_charm`

```python
from_charm(
charm: CharmBase,
datasource: Optional[DatasourcePostgreSQL],
saml_config: Optional[SAMLConfiguration]
) → CharmState
```

**Returns:**

- <b>`bool`</b>: enable_mjolnir config.

---

#### <kbd>property</kbd> public_baseurl

Return public_baseurl config.
Initialize a new instance of the CharmState class from the associated charm.



**Returns:**
**Args:**

- <b>`str`</b>: public_baseurl config.

---

#### <kbd>property</kbd> report_stats
- <b>`charm`</b>: The charm instance associated with this state.
- <b>`datasource`</b>: datasource information to be used by Synapse.
- <b>`saml_config`</b>: saml configuration to be used by Synapse.

Return report_stats config.
Return: The CharmState instance created by the provided charm.



**Returns:**
**Raises:**

- <b>`str`</b>: report_stats config as yes or no.

---

#### <kbd>property</kbd> saml_config

Return SAML configuration.


- <b>`CharmConfigInvalidError`</b>: if the charm configuration is invalid.

**Returns:**
SAMLConfiguration or None.

---

#### <kbd>property</kbd> server_name

Return server_name config.

## <kbd>class</kbd> `SynapseConfig`
Represent Synapse builtin configuration values.

Attrs: server_name: server_name config. report_stats: report_stats config. public_baseurl: public_baseurl config. enable_mjolnir: enable_mjolnir config. smtp_enable_tls: enable tls while connecting to SMTP server. smtp_host: SMTP host. smtp_notif_from: defines the "From" address to use when sending emails. smtp_pass: password to authenticate to SMTP host. smtp_port: SMTP port. smtp_user: username to autehtncate to SMTP host.

**Returns:**

- <b>`str`</b>: server_name config.



---

<a href="../src/charm_state.py#L173"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm_state.py#L90"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>classmethod</kbd> `from_charm`
### <kbd>classmethod</kbd> `set_default_smtp_notif_from`

```python
from_charm(charm: 'SynapseCharm') → CharmState
set_default_smtp_notif_from(
smtp_notif_from: Optional[str],
values: dict
) → Optional[str]
```

Initialize a new instance of the CharmState class from the associated charm.
Set server_name as default value to smtp_notif_from.



**Args:**

- <b>`charm`</b>: The charm instance associated with this state.

Return: The CharmState instance created by the provided charm.



**Raises:**

- <b>`CharmConfigInvalidError`</b>: if the charm configuration is invalid.


---

## <kbd>class</kbd> `SynapseConfig`
Represent Synapse builtin configuration values.

Attrs: server_name: server_name config. report_stats: report_stats config. public_baseurl: public_baseurl config. enable_mjolnir: enable_mjolnir config.
- <b>`smtp_notif_from`</b>: the smtp_notif_from current value.
- <b>`values`</b>: values already defined.



**Returns:**
The default value for smtp_notif_from if not defined.

---

<a href="../src/charm_state.py#L73"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm_state.py#L109"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>classmethod</kbd> `to_yes_or_no`

Expand Down
6 changes: 3 additions & 3 deletions src-docs/pebble.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ Change the configuration.

---

<a href="../src/pebble.py#L96"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/pebble.py#L98"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `enable_saml`

```python
enable_saml(container: Container) → None
```

Enable SAML.
Enable SAML while receiving on_saml_data_available event.



Expand Down Expand Up @@ -117,7 +117,7 @@ Replan Synapse NGINX service.

---

<a href="../src/pebble.py#L112"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/pebble.py#L114"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `reset_instance`

Expand Down
14 changes: 9 additions & 5 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,14 @@ def __init__(self, *args: typing.Any) -> None:
args: class arguments.
"""
super().__init__(*args)
self.database = DatabaseObserver(self)
self.saml = SAMLObserver(self)
self._database = DatabaseObserver(self)
self._saml = SAMLObserver(self)
try:
self._charm_state = CharmState.from_charm(charm=self)
self._charm_state = CharmState.from_charm(
charm=self,
datasource=self._database.get_relation_as_datasource(),
saml_config=self._saml.get_relation_as_saml_conf(),
)
except CharmConfigInvalidError as exc:
self.model.unit.status = ops.BlockedStatus(exc.msg)
return
Expand All @@ -65,7 +69,7 @@ def __init__(self, *args: typing.Any) -> None:
self._observability = Observability(self)
# Mjolnir is a moderation tool for Matrix.
# See https://github.com/matrix-org/mjolnir/ for more details about it.
if self._charm_state.enable_mjolnir:
if self._charm_state.synapse_config.enable_mjolnir:
self._mjolnir = Mjolnir(self, charm_state=self._charm_state)
self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(self.on.reset_instance_action, self._on_reset_instance_action)
Expand Down Expand Up @@ -136,7 +140,7 @@ def _on_reset_instance_action(self, event: ActionEvent) -> None:
try:
self.model.unit.status = ops.MaintenanceStatus("Resetting Synapse instance")
self.pebble_service.reset_instance(container)
datasource = self.database.get_relation_as_datasource()
datasource = self._database.get_relation_as_datasource()
actions.reset_instance(
container=container, charm_state=self._charm_state, datasource=datasource
)
Expand Down
Loading

0 comments on commit fce8bfb

Please sign in to comment.