Skip to content

Commit 7d587d9

Browse files
committed
feat: add bash script to migrate pacts from one broker to another
1 parent cec9af3 commit 7d587d9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

script/prod/migrate-latest-pacts.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
#
3+
# Usage: migrate-latest-pacts.sh SOURCE_BROKER_BASE_URL DEST_BROKER_BASE_URL
4+
#
5+
6+
set -e
7+
8+
function cleanup() {
9+
rm -rf /tmp/pact
10+
}
11+
12+
trap cleanup EXIT
13+
14+
source_broker_base_url=${1:?Usage: ${BASH_SOURCE[0]} SOURCE_BROKER_BASE_URL DEST_BROKER_BASE_URL}
15+
dest_broker_base_url=${2:?Usage: ${BASH_SOURCE[0]} SOURCE_BROKER_BASE_URL DEST_BROKER_BASE_URL}
16+
17+
latest_pacts=$(curl -s ${source_broker_base_url}/pacts/latest)
18+
latest_pact_urls=$(echo "${latest_pacts}" | jq "[.pacts[]._links.self[1:][].href]" | jq 'join("\n")' --raw-output)
19+
20+
for url in ${latest_pact_urls}
21+
do
22+
source_pact_content=$(curl -s $url)
23+
source_pact_url=$(echo ${source_pact_content} | jq "._links.self.href" --raw-output)
24+
dest_pact_url=$(echo "${source_pact_url}" | sed "s~${source_broker_base_url}~${dest_broker_base_url}~")
25+
dest_pact_content=$(echo "${source_pact_content}" | jq -r '{consumer: .consumer, provider: .provider, interactions: .interactions, metadata: .metadata}')
26+
echo "${source_pact_content}" > /tmp/pact
27+
echo "Migrating ${source_pact_url} to ${dest_pact_url}"
28+
curl -s -XPUT "${dest_pact_url}" -d @/tmp/pact -H "Content-Type: application/json" -H "Accept: application/hal+json" > /dev/null
29+
done

0 commit comments

Comments
 (0)