Skip to content

Commit

Permalink
feat: support mautrix-messenger bridgev2 APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
ignyx committed Oct 7, 2024
1 parent c89c356 commit 6baa7ce
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions group_vars/matrix_servers
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,10 @@ matrix_mautrix_meta_messenger_container_labels_traefik_tls_certResolver: "{{ dev
matrix_mautrix_meta_messenger_container_labels_metrics_middleware_basic_auth_enabled: "{{ matrix_metrics_exposure_http_basic_auth_enabled }}"
matrix_mautrix_meta_messenger_container_labels_metrics_middleware_basic_auth_users: "{{ matrix_metrics_exposure_http_basic_auth_users }}"

matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_hostname: "{{ matrix_server_fqn_matrix }}"

matrix_mautrix_meta_messenger_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'mau.meta.fb.as', rounds=655555) | to_uuid }}"
matrix_mautrix_meta_messenger_appservice_bridgev2_enabled: false

matrix_mautrix_meta_messenger_homeserver_address: "{{ matrix_addons_homeserver_client_api_url }}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ matrix_mautrix_meta_messenger_container_labels_metrics_middleware_basic_auth_ena
# See: https://doc.traefik.io/traefik/middlewares/http/basicauth/#users
matrix_mautrix_meta_messenger_container_labels_metrics_middleware_basic_auth_users: ''

# Controls whether labels will be added that expose the bridge's bridgev2 API endpoints
matrix_mautrix_meta_messenger_container_labels_bridgev2_enabled: "{{ matrix_mautrix_meta_messenger_appservice_bridgev2_enabled }}"
matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_hostname: ""
# Following two variables should be RegEx-escaped, see https://doc.traefik.io/traefik/middlewares/http/replacepathregex/
matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_path_external: "/_matrix/{{ matrix_mautrix_meta_messenger_identifier }}/provision"
matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_path_internal: "/_matrix/provision"
matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_rule: "Host(`{{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_hostname }}`) && PathPrefix(`{{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_path_external }}`)"
matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_priority: 0
matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_entrypoints: "{{ matrix_mautrix_meta_messenger_container_labels_traefik_entrypoints }}"
matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_tls: "{{ matrix_mautrix_meta_messenger_container_labels_metrics_traefik_entrypoints != 'web' }}"
matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_tls_certResolver: "{{ matrix_mautrix_meta_messenger_container_labels_traefik_tls_certResolver }}" # noqa var-naming

Check failure on line 68 in roles/custom/matrix-bridge-mautrix-meta-messenger/defaults/main.yml

View workflow job for this annotation

GitHub Actions / ansible-lint

yaml[comments]

Too few spaces before comment

Check warning on line 68 in roles/custom/matrix-bridge-mautrix-meta-messenger/defaults/main.yml

View workflow job for this annotation

GitHub Actions / yamllint

too few spaces before comment

# matrix_mautrix_meta_messenger_container_labels_additional_labels contains a multiline string with additional labels to add to the container label file.
# See `../templates/labels.j2` for details.
#
Expand Down Expand Up @@ -144,6 +156,10 @@ matrix_mautrix_meta_messenger_appservice_database_uri: |-
matrix_mautrix_meta_messenger_appservice_token: ''

# Whether to make public the bridgev2 API endpoints.
# See https://spec.mau.fi/megabridge/
matrix_mautrix_meta_messenger_appservice_bridgev2_enabled: false

# Controls which service this bridge is for.
# Valid options:
# * facebook - connect to FB Messenger via facebook.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
with_items:
- {'name': 'matrix_mautrix_meta_messenger_metrics_proxying_hostname', when: "{{ matrix_mautrix_meta_messenger_metrics_proxying_enabled }}"}
- {'name': 'matrix_mautrix_meta_messenger_metrics_proxying_path_prefix', when: "{{ matrix_mautrix_meta_messenger_metrics_proxying_enabled }}"}
- {'name': 'matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_hostname', when: "{{ matrix_mautrix_meta_messenger_metrics_proxying_enabled }}"}
- {'name': 'matrix_mautrix_meta_messenger_appservice_token', when: true}
- {'name': 'matrix_mautrix_meta_messenger_homeserver_token', when: true}
- {'name': 'matrix_mautrix_meta_messenger_container_network', when: true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ traefik.http.routers.{{ matrix_mautrix_meta_messenger_identifier }}-metrics.tls.
{% endif %}


{% if matrix_mautrix_meta_messenger_container_labels_bridgev2_enabled %}
############################################################
# #
# Appservice Bridgev2 API #
# #
############################################################

traefik.http.middlewares.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2-replacepathregex.replacepathregex.regex=^{{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_path_external }}/(.*)
traefik.http.middlewares.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2-replacepathregex.replacepathregex.replacement={{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_path_internal }}/$1
traefik.http.routers.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2.middlewares={{ matrix_mautrix_meta_messenger_identifier }}-bridgev2-replacepathregex

traefik.http.routers.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2.rule={{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_rule }}

{% if matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_priority | int > 0 %}
traefik.http.routers.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2.priority={{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_priority }}
{% endif %}

traefik.http.routers.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2.service={{ matrix_mautrix_meta_messenger_identifier }}-appservice
traefik.http.routers.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2.entrypoints={{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_entrypoints }}

traefik.http.routers.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2.tls={{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_tls | to_json }}
{% if matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_tls %}
traefik.http.routers.{{ matrix_mautrix_meta_messenger_identifier }}-bridgev2.tls.certResolver={{ matrix_mautrix_meta_messenger_container_labels_bridgev2_traefik_tls_certResolver }}
{% endif %}

############################################################
# #
# /Appservice Bridgev2 API #
# #
############################################################
{% endif %}


{% endif %}

{{ matrix_mautrix_meta_messenger_container_labels_additional_labels }}

0 comments on commit 6baa7ce

Please sign in to comment.