How can I configure a webhook in Pact broker that ...
# pact-broker
c
How can I configure a webhook in Pact broker that ends up with athorization in the header like this:
Copy code
{
  "uuid": "xxxxxxxxxxxxxxxxxxxxxxx",
  "description": "Trigger Azure DevOps pipeline on pact change",
  "enabled": true,
  "request": {
    "method": "POST",
    "url": "<https://dev.azure.com/xxxxxxx/xxxxxxx/_apis/build/builds?api-version=6.0>",
    "headers": {
      "Content-Type": "application/json",
      "Accept": "application/json",
      "Authorization": "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
    "body": {
      "definition": {
        "id": 124
      },
      "sourceBranch": "refs/heads/xxxxxxxxxxxxxxxxxxx"
    }
  },
  "events": [
    {
      "name": "contract_content_changed"
    }
  ],
  "updatedAt": "2024-08-22T07:35:01+00:00",
  "createdAt": "2024-08-22T07:33:25+00:00"
}
Rather than with username/password properties configured like this:
Copy code
{
  "uuid": "xxxxxxxxxxxxxxxxxxxxxxxxx",
  "description": "Trigger Azure DevOps pipeline on pact change",
  "enabled": true,
  "request": {
    "method": "POST",
    "url": "<https://dev.azure.com/xxxxxxxxxx/xxxxxxxxxxxx/_apis/build/builds?api-version=6.0>",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "definition": {
        "id": 124
      },
      "sourceBranch": "refs/heads/xxxxxxxxxxxxxxxxxx"
    },
    "username": "xxxxxxxxxx",
    "password": "**********"
  },
  "events": [
    {
      "name": "contract_content_changed"
    }
  ],
  "updatedAt": "2024-08-22T07:38:46+00:00",
  "createdAt": "2024-08-21T17:09:42+00:00"
}
I'm asking this because I was successful with the former type of requests against Azure DevOps API but not with the latter type of requests.
m
Don't use the username/password options in the webhook and instead, manually add the authorisation header?
c
Not manually but via API request using pact CLI tool. Is it possible? Because using the Pactflow GUI it seems to be possible to configure a webhook that ends up with that Authorization property in the header but using the Pact Brokers API request to create or update a webhook that is sent by the docker based pact CLI tool, its not clear to me how to create a webhook like that. To be more clear I mean how to create/update a webhook with the Authorization part in the header using this pact tool:
Copy code
docker pull pactfoundation/pact-cli:latest
docker run pactfoundation/pact-cli:latest pact-broker create-or-update-webhook <https://dev.azure.com/xxxxxxxx/xxxxxxxx/_apis/build/builds?api-version=7.0> --description "Trigger Build-Service-CIRS.API pipeline whenever ConsumerX to ProviderX pact changes" --request POST --header "Content-Type: application/json Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" --data '{"definition": {"id": 124}, "sourceBranch": "${pactbroker.consumerVersionBranch}", "parameters":  "{\"pact_url\":  \"${pactbroker.pactUrl}\"}"}' --consumer="ConsumerX" --provider="ProviderX" --user=Username:$AzureToken --contract-content-changed --broker-base-url=$PactBrokerBaseUrl --broker-username=$PactBrokerUsername --broker-password=$PactBrokerPassword --uuid=xxxxxxxxxxxxx
The command above for example creates a webhook like this for example:
Copy code
...
   "headers": {
      "Content-Type": "application/json Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    },
...
As opposed to a header like the following that I could successfully test against Azure DevOps API:
Copy code
...
"headers": {
      "Content-Type": "application/json",
      "Accept": "application/json",
      "Authorization": "Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    }
...
But in the meantime this is no longer an issue for me, because I was successful to authenticate against Azure DevOps API with a webhook request looking like this:
Copy code
{
  "uuid": "xxxxxxxxxxxxxxxxxxxxxxx",
  "description": "Trigger Providerx pipeline whenever ConusmerX to ProviderX pact changes",
  "consumer": {
    "name": "ConsumerX"
  },
  "provider": {
    "name": "ProviderX"
  },
  "enabled": true,
  "request": {
    "method": "POST",
    "url": "<https://dev.azure.com/xxxxxxx/xxxxxxx/_apis/build/builds?api-version=7.0>",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "definition": {
        "id": 124
      },
      "sourceBranch": "${pactbroker.consumerVersionBranch}",
      "parameters": "{\"pact_url\":  \"${pactbroker.pactUrl}\"}"
    },
    "username": "Username",
    "password": "**********"
  },
  "events": [
    {
      "name": "contract_content_changed"
    }
  ],
  "createdAt": "2024-08-22T17:29:29+00:00"
}