Skip to content

Commit

Permalink
feat: token
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Apr 28, 2024
1 parent 9b507ae commit e35b896
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 13 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ This is a shell script that can publish Pact JSON to a [Pactflow broker](https:/

You may want to use the shell script as is, or use it via `npx` and get it from `npm`.

Parameters:

```sh
--username The username, required if no token given
--password The password, required if no token given
--token The token, required if no username/password given
--pactflow-broker-url Base URL of Pactflow
--build-url The URL of the build that invoked this script
--pact-json-folder Folder containing Pact JSON files
--participant-version-number The version
```
## Example
You may get the version like this:
Expand Down Expand Up @@ -43,3 +55,8 @@ npx pactflow-publish-sh \
```
You can login to the broker at https://test.pactflow.io/ with username `dXfltyFMgNOFZAxr8io9wJ37iUpY42M` and password `O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1`.
## See also
- [Publish-contracts API](https://github.com/pact-foundation/pact_broker/blob/master/lib/pact_broker/doc/views/index/publish-contracts.markdown)
- [Authentication](https://docs.pactflow.io/docs/on-premises/authentication/)
38 changes: 25 additions & 13 deletions pactflow-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ while [ $# -gt 0 ]; do
--password=*)
password="${1#*=}"
;;
--token=*)
token="${1#*=}"
;;
--pactflow-broker-url=*)
pactflow_broker_url="${1#*=}"
;;
Expand All @@ -32,13 +35,15 @@ while [ $# -gt 0 ]; do
shift
done

if [[ -z "$username" ]]; then
echo "Must provide --username" 1>&2
exit 1
fi
if [[ -z "$password" ]]; then
echo "Must provide --password" 1>&2
exit 1
if [[ -z "$token" ]]; then
if [[ -z "$username" ]]; then
echo "Must provide --username or --token" 1>&2
exit 1
fi
if [[ -z "$password" ]]; then
echo "Must provide --password or --token" 1>&2
exit 1
fi
fi
if [[ -z "$pactflow_broker_url" ]]; then
echo "Must provide --pactflow-broker-url" 1>&2
Expand All @@ -57,7 +62,6 @@ if [[ -z "$participant_version_number" ]]; then
exit 1
fi


#
# Report to Pactflow
#
Expand Down Expand Up @@ -103,9 +107,17 @@ EndOfMessage
publish_content_file=$(mktemp)
echo $publish_content > $publish_content_file

curl -v -X POST \
-u "$username:$password" \
$pactflow_broker_url \
-H "Content-Type: application/json" \
--data-binary @$publish_content_file
if [ -n "$token" ]; then
curl -v \
-H "Authorization: Bearer $token" \
$pactflow_broker_url \
-H "Content-Type: application/json" \
--data-binary @$publish_content_file
else
curl -v \
-u "$username:$password" \
$pactflow_broker_url \
-H "Content-Type: application/json" \
--data-binary @$publish_content_file
fi
done

0 comments on commit e35b896

Please sign in to comment.