#!/bin/bash

set -e

URL=$(relation-get url) || exit 1
PROTO="${URL%%://*}"

ssl_enable=true
case "$PROTO" in
    http)
        ssl_enable=false
        ;;
    https)
        ssl_enable=true
        ;;
    *)
        err "Invalid protocol '$PROTO'."
        exit 1
        ;;
esac


config-add "\
services:
  $MASTER_BASE_SERVICE_NAME:
    environment:
      server_name: \"$URL\"
      extra_params: \"--o:ssl.enable=false --o:ssl.termination=${ssl_enable} \"
"