-
Notifications
You must be signed in to change notification settings - Fork 1
/
init-postgres
executable file
·40 lines (33 loc) · 1.21 KB
/
init-postgres
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/env bash
set -e
PWD=$(dirname "$0")
. "$PWD/bin/functions.sh"
echo Will download postgres client certificate from aiven and generate client config..
echo
(prerequisites && login) || ( echo ..failed. ; exit 1 )
OUTDIR=$PWD/.pg
OUTFILE=$OUTDIR/client.properties
if [ -f "$OUTDIR/ca.pem" ]; then
echo -n "$OUTDIR/ca.pem already exists, will overwrite. " ; ask
rm -f "$OUTDIR/ca.pem"
fi
OOUT=$(avn service user-creds-download --username avnadmin pg-sink -d $OUTDIR 2>&1) || :
if [ -f "$OUTDIR/ca.pem" ]; then
echo ".. ca.pem done"
else
echo $OOUT
echo ..failed. ; exit 1
fi
echo
PG_SERVICE=$(avn service get pg-sink --json)
host=$(echo "$PG_SERVICE" | pyjson '["service_uri_params"]["host"]')
password=$(echo "$PG_SERVICE" | pyjson '["service_uri_params"]["password"]')
port=$(echo "$PG_SERVICE" | pyjson '["service_uri_params"]["port"]')
user=$(echo "$PG_SERVICE" | pyjson '["service_uri_params"]["user"]')
url="jdbc:postgresql://${host}:${port}/os-metrics-sink?ssl=true&sslrootcert=$OUTDIR/ca.pem&sslmode=verify-ca"
echo "url=$url" > $OUTFILE
echo "user=$user" >> $OUTFILE
echo "password=$password" >> $OUTFILE
echo "driver=org.postgresql.Driver" >> $OUTFILE
echo "..$OUTFILE generated"
echo "..init-postgres done."