forked from spantaleev/matrix-docker-ansible-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46b73b5
commit ae6ee4a
Showing
6 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
roles/custom/matrix-synapse/tasks/ext/audit-registrations/setup_install.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
|
||
- name: Install audit registrations module | ||
ansible.builtin.copy: | ||
dest: "{{ matrix_synapse_ext_path }}/audit_registrations.py" | ||
owner: "{{ matrix_synapse_uid }}" | ||
group: "{{ matrix_synapse_gid }}" | ||
mode: 0440 | ||
content: | | ||
import logging | ||
from synapse.module_api.errors import SynapseError | ||
logger = logging.getLogger(__name__) | ||
class AuditRegistrations: | ||
def __init__(self, config, api): | ||
self._api = api | ||
self._room_alias = config["room_alias"] | ||
self._user_id = config["user_id"] | ||
self._api.register_account_validity_callbacks( | ||
on_user_registration=self.on_user_registration | ||
) | ||
async def on_user_registration(self, user_id): | ||
try: | ||
(room_id, _) = await self._api.lookup_room_alias(self._room_alias) | ||
await self._api.create_and_send_event_into_room( | ||
{ | ||
"sender": self._user_id, | ||
"room_id": room_id, | ||
"type": "m.room.message", | ||
"content": { | ||
"msgtype": "m.notice", | ||
"body": f"User registration: {user_id}", | ||
}, | ||
} | ||
) | ||
except SynapseError as e: | ||
logger.error("Failed to report user registration %s: %s", user_id, e) | ||
- ansible.builtin.set_fact: | ||
matrix_synapse_modules: | | ||
{{ | ||
matrix_synapse_modules | default([]) | ||
+ | ||
[ | ||
{ | ||
"module": "audit_registrations.AuditRegistrations", | ||
"config": matrix_synapse_ext_audit_registrations_config | ||
} | ||
] | ||
}} | ||
matrix_synapse_container_extra_arguments: > | ||
{{ | ||
matrix_synapse_container_extra_arguments | default([]) | ||
+ | ||
["--mount type=bind,src={{ matrix_synapse_ext_path }}/audit_registrations.py,dst={{ matrix_synapse_in_container_python_packages_path }}/audit_registrations.py,ro"] | ||
}} | ||
matrix_synapse_additional_loggers_auto: > | ||
{{ | ||
matrix_synapse_additional_loggers_auto | ||
+ | ||
[{'name': 'audit_registrations', 'level': 'INFO'}] | ||
}} |
6 changes: 6 additions & 0 deletions
6
roles/custom/matrix-synapse/tasks/ext/audit-registrations/setup_uninstall.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
|
||
- name: Uninstall audit registrations module | ||
ansible.builtin.file: | ||
path: "{{ matrix_synapse_ext_path }}/audit_registrations.py" | ||
state: absent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters