Skip to content
Beth Skurrie edited this page Oct 15, 2017 · 36 revisions

Default configuration values

Change them to your desired values in the config.ru

app = PactBroker::App.new do | config |
  config.log_dir = File.expand_path("./log")
  config.auto_migrate_db = true
  config.use_hal_browser = true
  config.validate_database_connection_config = true
  config.enable_diagnostic_endpoints = true
  config.use_case_sensitive_resource_names = true
  config.html_pact_renderer = default_html_pact_render
  config.version_parser = PactBroker::Versions::ParseSemanticVersion
  config.shields_io_base_url = "https://img.shields.io"
  config.order_versions_by_date = false
  config.check_for_potential_duplicate_pacticipant_names = true
end

Badges

Behind the scenes, the Pact Broker uses img.shields.io to dynamically create the text on the badges. If the shields.io server cannot be made available to your Pact Broker installation, set config.shields_io_base_url to nil, and you will get badges with the hardcoded title "pact" instead of "foo/bar pact".

If you cannot allow access to the public shields server because of Network Security, then you could run your own local docker one.

NOTE: If you have added your own authentication on top of the broker, you'll need to add a rule to allow public access to the badge URLs.

Version parser

Configure version_parser with a lambda or an object/class that responds to call. It should accept a string, and return a sortable object if the version is valid, and nil if the version is not valid.

class MyCustomVersionParser
  def self.call string_version
    ....
  end
end

PactBroker::App.new do | config |
  config.version_parser = MyCustomVersionParser
end

If you want to customise the error messages to indicate what sort of version format is expected, create a yml file with the following:

en:
  pact_broker:
    errors:
      validation:
        consumer_version_number_header_invalid: "Custom message"
        consumer_version_number_invalid: "Custom message"
# In config.ru, after configuring the Pact Broker app
I18n.config.load_path << "./path/to/your/custom/messages/file.yml"

Ordering versions by date

By default, pacticipant versions (and hence their related pacts) are sorted according to semantic version rules. If you would like to use a non semantic version label (eg. git sha), you will need to configure the versions to be sorted by date instead. To do this, set config.order_versions_by_date = true in the app configuration block, and restart the app. After you have restarted, you will need to publish a new pact to trigger a resort, as the ordering is done on insertion.

Checking for potential duplicate pacticipant names

When a pact is published normally (via a PUT to /pacts/provider/PROVIDER/consumer/CONSUMER/version/CONSUMER_APP_VERSION) the consumer, provider and consumer version resources are automatically created.

To prevent a pacticipant (consumer or provider) being created multiple times with slightly different name variants (eg. FooBar/foo-bar/foo bar/Foo Bar Service), if a new pacticipant name is deemed similar enough to an existing name, a 409 will be returned. The response body will contain instructions indicating that the pacticipant name should be corrected if it was intended to be an existing one, or that the pacticipant should be created manually if it was intended to be a new one.

To turn this feature off, set check_for_potential_duplicate_pacticipant_names = false, and make sure everyone is very careful with their naming! The usefulness of the broker depends on the integrity of the data, which in turn depends on the correctness of the pacticipant names.