You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB

  1. #!/bin/bash
  2. set -e
  3. host=$(relation-get host)
  4. port=$(relation-get port)
  5. connection_security=$(relation-get connection-security)
  6. auth_method=$(relation-get auth-method)
  7. declare -A ENV
  8. case "$connection_security" in
  9. "none")
  10. secure="false"
  11. ;;
  12. "starttls")
  13. secure="true"
  14. ENV[SMTP_TLS_ENABLED]="true"
  15. ;;
  16. "ssl/tls")
  17. secure="true"
  18. ENV[SMTP_SECURE]="true"
  19. ENV[SMTP_TLS_ENABLED]="true"
  20. ;;
  21. *)
  22. error "Unsupported connection security: $connection_security"
  23. exit 1
  24. ;;
  25. esac
  26. case "$auth_method" in
  27. "none")
  28. :
  29. ;;
  30. "password")
  31. login=$(relation-get login) || true
  32. password=$(relation-get password) || true
  33. ENV[SMTP_USER]="$login"
  34. ENV[SMTP_PWD]="$password"
  35. ;;
  36. *)
  37. error "Unsupported auth method: $auth_method"
  38. exit 1
  39. ;;
  40. esac
  41. config-add "\
  42. services:
  43. $MASTER_BASE_SERVICE_NAME:
  44. environment:
  45. SMTP_HOST: \"$host\"
  46. SMTP_PORT: \"$port\"
  47. $(for key in "${!ENV[@]}"; do echo " $key: \"${ENV[$key]//\$/\$\$}\""; done)
  48. "