pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

Verifier CLI: configure provider from environment variables #419

Closed mjpieters closed 1 month ago

mjpieters commented 1 month ago

Currently, the verifier CLI takes the provider configuration from CLI switches:

Provider options:
  -h, --hostname <hostname>
          Provider hostname (defaults to localhost)
  -p, --port <port>
          Provider port (defaults to protocol default 80/443)
      --transport <transport>
          Provider protocol transport to use (http, https, grpc, etc.) [default: http]
      --transports <transports>
          Allows multiple protocol transports to be configured (http, https, grpc, etc.) with their associated port numbers separated by a colon. For example, use --transports http:8080 grpc:5555 to configure both.
  -n, --provider-name <provider-name>
          Provider name (defaults to provider)
      --base-path <base-path>
          Base path to add to all requests
      --request-timeout <request-timeout>
          Sets the HTTP request timeout in milliseconds for requests to the target API and for state change requests.
  -H, --header <custom-header>
          Add a custom header to be included in the calls to the provider. Values must be in the form KEY=VALUE, where KEY and VALUE contain ASCII characters (32-127) only. Can be repeated.
      --disable-ssl-verification
          Disables validation of SSL certificates

We have a docker-compose setup with the (instrumented) provider running in a container, and want to use the pactfoundation/pact-ref-verifier docker container to run the verification. Ideally, the pact broker configuration for this setup would come from environment variables, so I can just specify these in the docker-compose service.

E.g. the docker-compose could look like this:

services:
  # An instrumented version of the application API for Pact verification
  pact_provider:
     # service configuration ...
     # service accepts connections on port 5000 

  pact_verifier:
    image: pactfoundation/pact-ref-verifier:latest
    depends_on:
      pact_provider:
        condition: service_healthy
    environment:
      # these are hypothetical environment names, to configure how to access the pact broker
      PACT_PROVIDER_HOSTNAME: pact_provider
      PACT_PROVIDER_PORT: 5000
      PACT_PROVIDER_NAME: SomeProviderName
      PACT_PROVIDER_STATE_CHANGE_URL: http://pact_provider:5000/_pact/provider_states
      PACT_PROVIDER_STATE_CHANGE_TEARDOWN: yes

The advantage is that this configuration now lives right next to the provider configuration that dictates these settings.

YOU54F commented 1 month ago

That is easily do-able

https://github.com/pact-foundation/pact-reference/blob/master/rust/pact_verifier_cli/src/args.rs#L151

here the envs are read in for the token, password or username

would you be up for a PR.

mjpieters commented 1 month ago

Yup, I can put up a PR for this. I'll model them on the Ruby verifier.

YOU54F commented 1 month ago

awesome! thank you very much