fork 0k-charms
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.

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