Skip to content

Commit

Permalink
feat: add bash script to migrate pacts from one broker to another
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Jul 5, 2018
1 parent cec9af3 commit 7d587d9
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions script/prod/migrate-latest-pacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
#
# Usage: migrate-latest-pacts.sh SOURCE_BROKER_BASE_URL DEST_BROKER_BASE_URL
#

set -e

function cleanup() {
rm -rf /tmp/pact
}

trap cleanup EXIT

source_broker_base_url=${1:?Usage: ${BASH_SOURCE[0]} SOURCE_BROKER_BASE_URL DEST_BROKER_BASE_URL}
dest_broker_base_url=${2:?Usage: ${BASH_SOURCE[0]} SOURCE_BROKER_BASE_URL DEST_BROKER_BASE_URL}

latest_pacts=$(curl -s ${source_broker_base_url}/pacts/latest)
latest_pact_urls=$(echo "${latest_pacts}" | jq "[.pacts[]._links.self[1:][].href]" | jq 'join("\n")' --raw-output)

for url in ${latest_pact_urls}
do
source_pact_content=$(curl -s $url)
source_pact_url=$(echo ${source_pact_content} | jq "._links.self.href" --raw-output)
dest_pact_url=$(echo "${source_pact_url}" | sed "s~${source_broker_base_url}~${dest_broker_base_url}~")
dest_pact_content=$(echo "${source_pact_content}" | jq -r '{consumer: .consumer, provider: .provider, interactions: .interactions, metadata: .metadata}')
echo "${source_pact_content}" > /tmp/pact
echo "Migrating ${source_pact_url} to ${dest_pact_url}"
curl -s -XPUT "${dest_pact_url}" -d @/tmp/pact -H "Content-Type: application/json" -H "Accept: application/hal+json" > /dev/null
done

0 comments on commit 7d587d9

Please sign in to comment.