Skip to content

Commit 29cfb23

Browse files
committed
Fix bugs in the update-templates.sh script
1 parent 99a55b7 commit 29cfb23

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

.github/update-templates.sh

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,42 @@ update() {
3939
echo "Creating template: $dir via POST to $wiremock_cloud_url/v1/api-templates/public"
4040

4141
local apiTemplate; apiTemplate="$( \
42-
curl -sS --fail-with-body \
43-
-u "$wiremock_cloud_username:$wiremock_cloud_api_token" \
42+
curl_auth \
43+
"$wiremock_cloud_username" \
44+
"$wiremock_cloud_api_token" \
4445
-H 'Content-Type: application/json' \
4546
-d "$data" \
4647
"$wiremock_cloud_url/v1/api-templates/public" \
4748
)"
4849

49-
echo "Created apiTemplate $apiTemplate"
50-
5150
local apiTemplateId; apiTemplateId="$(echo "$apiTemplate" | jq -r .apiTemplate.id)"
51+
local apiTemplateDetails; apiTemplateDetails="$(echo "$apiTemplate" | jq -c '{ { apiTemplate: { id: .apiTemplate.id, slug: .apiTemplate.slug, name: .apiTemplate.name, description: .apiTemplate.description, tags: .apiTemplate.tags } }')"
52+
53+
echo "Created $apiTemplateDetails"
5254

53-
local stubsFile; stubsFile=$(jq -r '.stubs' < "$metadata")
55+
local stubsFile; stubsFile="../$dir/$(jq -r '.stubs' < "$metadata")"
5456

5557
echo "Setting stubs: $stubsFile for template $dir via PUT to $wiremock_cloud_url/v1/api-templates/$apiTemplateId/stubs"
5658

57-
curl -sS --fail-with-body \
58-
-u "$wiremock_cloud_username:$wiremock_cloud_api_token" \
59+
curl_auth \
60+
"$wiremock_cloud_username" \
61+
"$wiremock_cloud_api_token" \
5962
-H 'Content-Type: application/json' \
6063
-X PUT \
6164
-d "@$stubsFile" \
62-
"$wiremock_cloud_url/v1/api-templates/$apiTemplateId/stubs"
65+
"$wiremock_cloud_url/v1/api-templates/$apiTemplateId/stubs" >/dev/null
66+
}
67+
68+
curl_auth() {
69+
local wiremock_cloud_username=$1
70+
local wiremock_cloud_api_token=$2
71+
72+
shift
73+
shift
74+
75+
curl -sS --fail-with-body \
76+
-u "$wiremock_cloud_username:$wiremock_cloud_api_token" \
77+
"$@"
6378
}
6479

6580
update "$@"

0 commit comments

Comments
 (0)