Skip to content

Commit

Permalink
Add scripts for creating and deleting resources locally
Browse files Browse the repository at this point in the history
  • Loading branch information
jameshochadel committed Sep 10, 2024
1 parent ac1c88f commit b714f7f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
*.tfvars
*.brokerpak
# Configuration for the CSB CLI client.
clientconfig.yml
# Configuration for the CSB server.
secrets.env
zscaler.crt
2 changes: 2 additions & 0 deletions brokerpaks/cg-smtp/client/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
bindings.txt
bindings.txt.history
credentials.json
instances.txt
instances.txt.history
25 changes: 25 additions & 0 deletions brokerpaks/cg-smtp/client/bin/down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash
set -eo pipefail

# Work around the broker not having a command like `csb client list` by tracking the
# instances and bindings we've created.

if [ "$#" -lt 1 ]; then
printf "Usage:\n\n\t\$./down.sh /path/to/workdir\n\nWorking directory must match the directory passed to up.sh."
exit 1
fi

workdir=$1

cat "${workdir}/bindings.txt" | xargs -n 2 bash -c 'cloud-service-broker client unbind --config clientconfig.yml --planid 35ffb84b-a898-442e-b5f9-0a6a5229827d --serviceid 260f2ead-b9e9-48b5-9a01-6e3097208ad7 --instanceid $1 --bindingid $2' -
echo "\n\n$(date)" >> bindings.txt.history
cat ${workdir}/bindings.txt >> ${workdir}/bindings.txt.history
rm ${workdir}/bindings.txt

cat "${workdir}/instances.txt" | xargs -I % cloud-service-broker client deprovision --config clientconfig.yml --planid 35ffb84b-a898-442e-b5f9-0a6a5229827d --serviceid 260f2ead-b9e9-48b5-9a01-6e3097208ad7 --instanceid %
echo "\n$(date)" >> instances.txt.history
cat ${workdir}/instances.txt >> ${workdir}/instances.txt.history
rm ${workdir}/instances.txt

echo "Done. instances.txt and bindings.txt cleared. History recorded in instances.txt.history and bindings.txt.history."

44 changes: 44 additions & 0 deletions brokerpaks/cg-smtp/client/bin/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
set -eo pipefail

if [ "$#" -lt 2 ]; then
printf "Usage:\n\n\t\$./up.sh [email protected] /path/to/workdir\n\n"
exit 1
fi

recipient=$1
workdir=$2

csb=cloud-service-broker

# Instance IDs must be unique, so generate a new one
instanceid=$(uuidgen | tr "[A-Z]" "[a-z]")
echo "Instance ID: $instanceid"

# Start provisioning
$csb client provision --config clientconfig.yml --planid 35ffb84b-a898-442e-b5f9-0a6a5229827d --serviceid 260f2ead-b9e9-48b5-9a01-6e3097208ad7 --instanceid $instanceid --params "{\"dmarc_report_uri_aggregate\": \"mailto:${recipient}\", \"dmarc_report_uri_failure\": \"${recipient}\"}"

# Wait on provisioning to finish
state=""
while [[ "$state" != "succeeded" ]]; do
sleep 10
state=$($csb client --config clientconfig.yml last --instanceid $instanceid | jq -r '.response.state')
echo "State: $state"
done

touch "$workdir/instances.txt"
echo $instanceid >> "$workdir/instances.txt"

# Let the broker settle
sleep 1

# Binding IDs must be unique, so generate a new one
bindingid=$(uuidgen | tr "[A-Z]" "[a-z]")
echo "Binding ID: $bindingid"
touch "$workdir/bindings.txt"
echo "$instanceid $bindingid" >> "$workdir/bindings.txt"

# Update smtp-client with new credentials
$csb client bind --config clientconfig.yml --planid 35ffb84b-a898-442e-b5f9-0a6a5229827d --serviceid 260f2ead-b9e9-48b5-9a01-6e3097208ad7 --instanceid $instanceid --bindingid $bindingid | jq '.response.credentials' > "$workdir/credentials.json"

echo "Done. Credentials saved to credentials.json for use with the client. GUIDs saved to instances.txt and bindings.txt. Deprovision later with down.sh."

0 comments on commit b714f7f

Please sign in to comment.