Просмотр исходного кода

matrix-appservice-irc: derive Traefik path prefix from publicUrl pathPrefix

Instead of hardcoding '/irc' in two places, the Traefik path prefix is now
derived from the mediaProxy publicUrl_pathPrefix variable by stripping the
trailing slash (Traefik paths must not end with a slash, except for '/').

Added validation to ensure:
- publicUrl_pathPrefix starts and ends with a slash (required by the service)
- Traefik path prefix doesn't end with a slash (consistent with other roles)
pull/3512/head
Slavi Pantaleev 1 месяц назад
Родитель
Сommit
0b429d3fdd
2 измененных файлов: 25 добавлений и 1 удалений
  1. +2
    -1
      roles/custom/matrix-bridge-appservice-irc/defaults/main.yml
  2. +23
    -0
      roles/custom/matrix-bridge-appservice-irc/tasks/validate_config.yml

+ 2
- 1
roles/custom/matrix-bridge-appservice-irc/defaults/main.yml Просмотреть файл

@@ -497,7 +497,8 @@ matrix_appservice_irc_container_labels_traefik_tls_certResolver: default # noqa

# Controls whether Traefik labels for the media proxy will be applied
matrix_appservice_irc_container_labels_media_proxy_enabled: true
matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix: "/irc"
# Derived from publicUrl_pathPrefix, stripping any trailing slash (unless it's just "/")
matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix: "{{ '/' if matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix == '/' else matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix.rstrip('/') }}"
matrix_appservice_irc_container_labels_media_proxy_traefik_rule: "Host(`{{ matrix_appservice_irc_ircService_mediaProxy_publicUrl_hostname }}`) && PathPrefix(`{{ matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix }}`)"
matrix_appservice_irc_container_labels_media_proxy_traefik_priority: 2000
matrix_appservice_irc_container_labels_media_proxy_traefik_entrypoints: "{{ matrix_appservice_irc_container_labels_traefik_entrypoints }}"


+ 23
- 0
roles/custom/matrix-bridge-appservice-irc/tasks/validate_config.yml Просмотреть файл

@@ -44,3 +44,26 @@
- {'old': 'matrix_appservice_irc_container_expose_client_server_api_port', 'new': '<superseded by matrix_appservice_irc_container_http_host_bind_port>'}
- {'old': 'matrix_appservice_irc_container_self_build', 'new': 'matrix_appservice_irc_container_image_self_build'}
- {'old': 'matrix_appservice_irc_docker_image_name_prefix', 'new': 'matrix_appservice_irc_docker_image_registry_prefix'}

- name: Fail if matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix does not start with a slash
ansible.builtin.fail:
msg: >-
matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix (`{{ matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix }}`) must start with a slash (e.g. `/` or `/irc/`).
when: "matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix[0] != '/'"

- name: Fail if matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix does not end with a slash
ansible.builtin.fail:
msg: >-
matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix (`{{ matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix }}`) must end with a slash (e.g. `/` or `/irc/`).
when: "matrix_appservice_irc_ircService_mediaProxy_publicUrl_pathPrefix[-1] != '/'"

- when: matrix_appservice_irc_container_labels_traefik_enabled | bool
block:
# We ensure it doesn't end with a slash, because we handle both (slash and no-slash).
# Knowing that the path_prefix does not end with a slash ensures we know how to set these routes up
# without having to do "does it end with a slash" checks elsewhere.
- name: Fail if matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix ends with a slash
ansible.builtin.fail:
msg: >-
matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix (`{{ matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix }}`) must either be `/` or not end with a slash (e.g. `/irc`).
when: "matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix != '/' and matrix_appservice_irc_container_labels_media_proxy_traefik_path_prefix[-1] == '/'"

Загрузка…
Отмена
Сохранить