Skip to content

Commit

Permalink
feat(retention): Add media retention (#336)
Browse files Browse the repository at this point in the history
* feat(retention): Add media retention

---------

Co-authored-by: arturo-seijas <[email protected]>
  • Loading branch information
merkata and arturo-seijas authored May 16, 2024
1 parent 5f3684a commit fea9f0d
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 760 deletions.
610 changes: 0 additions & 610 deletions src-docs/api.md

This file was deleted.

10 changes: 5 additions & 5 deletions src-docs/pebble.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ Change the configuration (main and worker).

---

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

## <kbd>function</kbd> `enable_redis`

Expand All @@ -294,7 +294,7 @@ Enable Redis while receiving on_redis_relation_updated event.

---

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

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

Expand All @@ -320,7 +320,7 @@ Enable SAML while receiving on_saml_data_available event.

---

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

## <kbd>function</kbd> `enable_smtp`

Expand All @@ -346,7 +346,7 @@ Enable SMTP while receiving on_smtp_data_available event.

---

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

## <kbd>function</kbd> `enable_media`

Expand All @@ -372,7 +372,7 @@ Enable S3 Media while receiving on_media_data_available event.

---

<a href="../src/pebble.py#L434"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/pebble.py#L436"><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
77 changes: 0 additions & 77 deletions src-docs/register_user.md

This file was deleted.

68 changes: 0 additions & 68 deletions src-docs/reset_instance.md

This file was deleted.

2 changes: 2 additions & 0 deletions src/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ def change_config( # noqa: C901 pylint: disable=too-many-branches,too-many-stat
current_synapse_config = _get_synapse_config(container)
synapse.enable_metrics(current_synapse_config)
synapse.enable_forgotten_room_retention(current_synapse_config)
synapse.enable_media_retention(current_synapse_config)
synapse.enable_stale_devices_deletion(current_synapse_config)
synapse.enable_serve_server_wellknown(current_synapse_config)
synapse.enable_replication(current_synapse_config)
if charm_state.instance_map_config is not None:
Expand Down
2 changes: 2 additions & 0 deletions src/synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@
enable_instance_map,
enable_ip_range_whitelist,
enable_media,
enable_media_retention,
enable_metrics,
enable_redis,
enable_replication,
enable_room_list_publication_rules,
enable_saml,
enable_serve_server_wellknown,
enable_smtp,
enable_stale_devices_deletion,
enable_stream_writers,
enable_trusted_key_servers,
execute_migrate_config,
Expand Down
21 changes: 21 additions & 0 deletions src/synapse/workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,27 @@ def enable_forgotten_room_retention(current_yaml: dict) -> None:
current_yaml["forgotten_room_retention_period"] = "28d"


def enable_media_retention(current_yaml: dict) -> None:
"""Change the Synapse configuration to enable media retention.
Args:
current_yaml: current configuration.
"""
current_yaml["media_retention"] = {
"remote_media_lifetime": "14d",
"local_media_lifetime": "28d",
}


def enable_stale_devices_deletion(current_yaml: dict) -> None:
"""Change the Synapse configuration to delete stale devices.
Args:
current_yaml: current configuration.
"""
current_yaml["delete_stale_devices_after"] = "1y"


def disable_password_config(current_yaml: dict) -> None:
"""Change the Synapse configuration to disable password config.
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ def test_enable_federation_domain_whitelist_is_called(
monkeypatch.setattr(synapse, "enable_forgotten_room_retention", MagicMock())
monkeypatch.setattr(synapse, "enable_serve_server_wellknown", MagicMock())
monkeypatch.setattr(synapse, "enable_instance_map", MagicMock())
monkeypatch.setattr(synapse, "enable_media_retention", MagicMock())
monkeypatch.setattr(synapse, "enable_stale_devices_deletion", MagicMock())
monkeypatch.setattr(synapse, "validate_config", MagicMock())
enable_federation_mock = MagicMock()
monkeypatch.setattr(synapse, "enable_federation_domain_whitelist", enable_federation_mock)
Expand Down Expand Up @@ -357,6 +359,8 @@ def test_disable_password_config_is_called(
monkeypatch.setattr(synapse, "enable_forgotten_room_retention", MagicMock())
monkeypatch.setattr(synapse, "enable_serve_server_wellknown", MagicMock())
monkeypatch.setattr(synapse, "enable_instance_map", MagicMock())
monkeypatch.setattr(synapse, "enable_media_retention", MagicMock())
monkeypatch.setattr(synapse, "enable_stale_devices_deletion", MagicMock())
monkeypatch.setattr(synapse, "validate_config", MagicMock())
disable_password_config_mock = MagicMock()
monkeypatch.setattr(synapse, "disable_password_config", disable_password_config_mock)
Expand Down

0 comments on commit fea9f0d

Please sign in to comment.