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.

61 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. opts=()
  8. declare -A ENV
  9. case "$connection_security" in
  10. "none")
  11. url+="smtp://"
  12. opts+=(
  13. "ignoreTLS=true"
  14. "secure=false"
  15. )
  16. ;;
  17. "ssl/tls")
  18. url+="smtps://"
  19. ;;
  20. *)
  21. error "Unsupported connection security: $connection_security"
  22. exit 1
  23. ;;
  24. esac
  25. case "$auth_method" in
  26. "none")
  27. :
  28. ;;
  29. "password")
  30. login=$(relation-get login) || true
  31. password=$(relation-get password) || true
  32. url+="$login:$password@"
  33. ;;
  34. *)
  35. error "Unsupported auth method: $auth_method"
  36. exit 1
  37. ;;
  38. esac
  39. url+="$host:$port/"
  40. first=1
  41. for opt in "${opts[@]}"; do
  42. if [ $first -eq 1 ]; then
  43. url+="?"
  44. first=0
  45. else
  46. url+="&"
  47. fi
  48. url+="$opt"
  49. done
  50. config-add "\
  51. services:
  52. $MASTER_BASE_SERVICE_NAME:
  53. environment:
  54. PDS_EMAIL_SMTP_URL: \"$url\"
  55. "