forked from 0k/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
65 lines
1.2 KiB
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
host=$(relation-get host)
|
|
port=$(relation-get port)
|
|
connection_security=$(relation-get connection-security)
|
|
auth_method=$(relation-get auth-method)
|
|
|
|
## We are creating a URL that looks like this:
|
|
## smtp://[login:password@]host:port/?ignoreTLS=true&secure=false
|
|
## ref: https://nodemailer.com/smtp/
|
|
|
|
opts=()
|
|
declare -A ENV
|
|
case "$connection_security" in
|
|
"none")
|
|
url+="smtp://"
|
|
opts+=(
|
|
"ignoreTLS=true"
|
|
"secure=false"
|
|
)
|
|
;;
|
|
"ssl/tls")
|
|
url+="smtps://"
|
|
;;
|
|
*)
|
|
error "Unsupported connection security: $connection_security"
|
|
exit 1
|
|
;;
|
|
esac
|
|
case "$auth_method" in
|
|
"none")
|
|
:
|
|
;;
|
|
"password")
|
|
login=$(relation-get login) || true
|
|
password=$(relation-get password) || true
|
|
url+="$login:${password//\$/\$\$}@"
|
|
;;
|
|
*)
|
|
error "Unsupported auth method: $auth_method"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
url+="$host:$port/"
|
|
|
|
first=1
|
|
for opt in "${opts[@]}"; do
|
|
if [ $first -eq 1 ]; then
|
|
url+="?"
|
|
first=0
|
|
else
|
|
url+="&"
|
|
fi
|
|
url+="$opt"
|
|
done
|
|
|
|
config-add "\
|
|
services:
|
|
$MASTER_BASE_SERVICE_NAME:
|
|
environment:
|
|
PDS_EMAIL_SMTP_URL: \"$url\"
|
|
"
|