Hi team, is there a way to download all provider c...
# pactflow
t
Hi team, is there a way to download all provider contracts for a service from Pactflow?
1
m
Not via the UI, but probably via APIs. What’s the objective/goal here?
t
The goal is to download contracts and verify them
if it’s possible to do via APIs, can you please share docs?
b
What does "verify" mean in this context?
t
download contracts and run provider verification against these contracts
y
Why are you not able to use the provider verifier CLI or a provider verifier in your codes native language?
☝️ 1
you could easily script something up this will get you the list of
pacticipants
Copy code
curl -H "Authorization: Bearer $PACT_BROKER_TOKEN" "<https://test.pactflow.io/pacticipants>" | jq .
but you could also avoid also that jazz, by just using the verifier cli https://docs.pact.io/implementation_guides/cli#provider-verifier
the verifier cli accepts consumer version selectors for pact retrieval https://docs.pact.io/pact_broker/advanced_topics/consumer_version_selectors
k
Following up on this from Tatiana: Our usecase is that when receiving a new consumer contract for a service that I develop and that is the provider, I do get these new contracts usually as files. When updating the provider-states in this service then locally I want to ensure that it works against the new contract and all the existing published contracts. What has been very helpful in the past (with pact-broker) was to download all contracts for this provider service locally to a folder, add the new contract-file and be able to debug with that (i.e. include, exclude, change) any of the contracts. How do you recommend to achieve this with pactflow?
this up arrow 1
iiuc pactflow also internally still uses pact-broker to some degree or is at least compatible with its API, so I guess we could just use the same approach as before to achieve this? Let me know though if there is generally a better approach to achieve the same.
m
Yep, PactFlow is a superset of the Pact Broker APIs. So you can carry on doing it just as you were
It sounds like the primary problem statement is making it easier for local development/debugging?
Perhaps a CLI command that allows you to download the contracts based on consumer selectors could be the way to go?
1
basically, if you ran
pact-provider-verifier
CLI with the
--verbose
flag, you could follow the API calls there and use that to download the contracts you needed
k
Yeah I've did it with that
Copy code
import json
import os
from pathlib import Path

import httpx
Path("provider_pacts").mkdir(parents=True, exist_ok=True)

headers = {"Authorization": f'Bearer {os.getenv("PACTFLOW_API_TOKEN")}'}

with httpx.Client(headers=headers) as client:
    for pact in client.get(
        "<https://codility.pactflow.io/pacts/provider/task-service/latest>",
    ).json()["_links"]["pb:pacts"]:
        Path(f"provider_pacts/{pact['name']}_contract.json").write_text(
            json.dumps(client.get(pact["href"]).json(), indent=4),
        )
👍 1