#!/bin/bash

set -eu

# replace secrets in test config
VARS_STORE=${PWD}/vars-store/environments/${ENVIRONMENT_NAME}/vars-store.yml
pushd test-config/environments/${ENVIRONMENT_NAME}
  cf_admin_password=`grep cf_admin_password ${VARS_STORE} | cut -d' ' -f2`
  ssh_proxy_private_key=`bbl ssh-key`
  bosh_client_secret=`bbl director-password`
  bosh_ca_cert=`bbl director-ca-cert`
popd

JUMPBOX_VARS=${PWD}/vars-store/environments/${ENVIRONMENT_NAME}/vars/jumpbox-vars-file.yml
pushd test-config/environments/${ENVIRONMENT_NAME}/vars
  ssh_proxy_host=`grep external_ip ${JUMPBOX_VARS} | cut -d' ' -f2`
popd

configs=( cf_admin_password
          bosh_client_secret
          bosh_ca_cert
          ssh_proxy_host
          ssh_proxy_private_key )

integration_config=`cat test-config/environments/${ENVIRONMENT_NAME}/drats_integration_config.json`

for config in "${configs[@]}"
do
  integration_config=$(echo ${integration_config} | jq ".${config}=\"${!config}\"")
done

echo "${integration_config}" > drats-integration-config/drats_integration_config.json
