#!/bin/bash

set -e

PEERTUBE_CONFIG_DIR=/etc/peertube

HOST_CONFIG_DIR=$SERVICE_CONFIGSTORE/$PEERTUBE_CONFIG_DIR

password=$(relation-get password) || {
    err "Can't get password for '$SERVICE_NAME' from '$TARGET_SERVICE_NAME'."
    exit 1
}

cat <<EOF >> "$HOST_CONFIG_DIR/local.yaml"

## XXXvlab: to be added by redis relation
redis:
  hostname: '$TARGET_SERVICE_NAME'
  port: 6379
  auth: $password

EOF

info "Configured $SERVICE_NAME code for $TARGET_SERVICE_NAME access."