Matrix Docker Ansible eploy
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 

57 строки
1.8 KiB

  1. #!/bin/sh
  2. # Talks to Meowlnir's management API.
  3. #
  4. # The API is not published outside the container network, so requests are made from inside the container, which ships with curl.
  5. # The management secret is read out of the live configuration file, so that it lives in exactly one place.
  6. #
  7. # Usage: meowlnir-api <METHOD> <PATH> [JSON_BODY]
  8. # Example: meowlnir-api GET /_meowlnir/v1/bots
  9. #
  10. # Prints the response body, followed by the HTTP status code on its own final line.
  11. set -eu
  12. CONFIG_FILE='{{ matrix_bot_meowlnir_config_path }}/config.yaml'
  13. CONTAINER_NAME='matrix-bot-meowlnir'
  14. API_BASE='http://localhost:{{ matrix_bot_meowlnir_config_meowlnir_port }}'
  15. REQUEST_TIMEOUT='{{ matrix_bot_meowlnir_api_request_timeout_seconds }}'
  16. if [ $# -lt 2 ]; then
  17. echo "Usage: $(basename "$0") <METHOD> <PATH> [JSON_BODY]" >&2
  18. echo "Example: $(basename "$0") GET /_meowlnir/v1/bots" >&2
  19. exit 2
  20. fi
  21. method="$1"
  22. api_path="$2"
  23. body="${3:-}"
  24. # The configuration file is generated by Ansible, so its layout is predictable.
  25. secret="$(awk '$1 == "management_secret:" { print $2; exit }' "$CONFIG_FILE" | sed 's/^"//; s/"$//')"
  26. if [ -z "$secret" ]; then
  27. echo "Could not read management_secret from $CONFIG_FILE" >&2
  28. exit 1
  29. fi
  30. if [ "$secret" = 'disable' ]; then
  31. echo "Meowlnir's management API is disabled (management_secret is set to 'disable')" >&2
  32. exit 1
  33. fi
  34. if [ -n "$body" ]; then
  35. exec {{ devture_systemd_docker_base_host_command_docker }} exec "$CONTAINER_NAME" \
  36. curl -sS --max-time "$REQUEST_TIMEOUT" -X "$method" \
  37. -H "Authorization: Bearer $secret" \
  38. -H 'Content-Type: application/json' \
  39. -d "$body" \
  40. -w '\n%{http_code}' \
  41. "$API_BASE$api_path"
  42. fi
  43. exec {{ devture_systemd_docker_base_host_command_docker }} exec "$CONTAINER_NAME" \
  44. curl -sS --max-time "$REQUEST_TIMEOUT" -X "$method" \
  45. -H "Authorization: Bearer $secret" \
  46. -w '\n%{http_code}' \
  47. "$API_BASE$api_path"