class Pact::ProviderVerifier::App
Constants
- PROXY_PACT_HELPER
Attributes
options[R]
pact_urls[R]
Public Class Methods
call(pact_urls, options)
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 29 def self.call pact_urls, options new(pact_urls, options).call end
new(pact_urls, options = {})
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 22 def initialize pact_urls, options = {} @pact_urls = pact_urls @options = options @consumer_version_tags = options[:consumer_version_tag] || [] @provider_version_tags = options[:provider_version_tag] || [] end
Public Instance Methods
call()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 33 def call setup pact_urls = all_pact_urls wait_until_provider_available exit_statuses = pact_urls.collect do |pact_uri| verify_pact pact_uri end exit_statuses.all?{ | status | status == 0 } end
Private Instance Methods
all_pact_urls()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 175 def all_pact_urls http_client_options = { username: options.broker_username, password: options.broker_password, token: options.broker_token, verbose: options.verbose } AggregatePactConfigs.call(pact_urls, options.provider, consumer_version_tags, provider_version_tags, options.pact_broker_base_url, http_client_options) end
apply_custom_middleware(app)
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 134 def apply_custom_middleware app CustomMiddleware.descendants.inject(app) do | app, clazz | Pact.configuration.output_stream.puts "INFO: Adding custom middleware #{clazz}" clazz.new(app) end end
configure_custom_header_middleware(rack_reverse_proxy)
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 101 def configure_custom_header_middleware rack_reverse_proxy if options.custom_provider_header Pact::ProviderVerifier::AddHeaderMiddlware.new(rack_reverse_proxy, parse_header) else rack_reverse_proxy end end
configure_custom_middleware(app)
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 109 def configure_custom_middleware app if options.custom_middleware && options.custom_middleware.any? require_custom_middlware apply_custom_middleware(app) else app end end
configure_provider_states_header_removal_middleware(app)
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 118 def configure_provider_states_header_removal_middleware app ProviderStates::RemoveProviderStatesHeaderMiddleware.new(app) end
configure_reverse_proxy()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 89 def configure_reverse_proxy provider_base_url = options.provider_base_url Rack::ReverseProxy.new do reverse_proxy_options( verify_mode: OpenSSL::SSL::VERIFY_NONE, preserve_host: true, x_forwarded_headers: false ) reverse_proxy %r{(.*)}, "#{provider_base_url}$1" end end
configure_service_provider()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 63 def configure_service_provider # Have to declare these locally as the class scope gets lost within the block application = configure_reverse_proxy application = configure_provider_states_header_removal_middleware(application) application = configure_custom_middleware(application) application = configure_custom_header_middleware(application) this = self Pact.service_provider "Running Provider Application" do app do application end if this.options.provider_app_version app_version this.options.provider_app_version end if this.provider_version_tags.any? app_version_tags this.provider_version_tags end publish_verification_results this.options.publish_verification_results end end
custom_provider_headers_for_env_var()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 190 def custom_provider_headers_for_env_var if options.custom_provider_header && options.custom_provider_header.any? options.custom_provider_header.join("\n") end end
parse_header()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 196 def parse_header options.custom_provider_header.each_with_object({}) do | custom_provider_header, header_hash | header_name, header_value = custom_provider_header.split(":", 2).collect(&:strip) header_hash[header_name] = header_value end end
print_deprecation_note()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 203 def print_deprecation_note if options.provider_states_url $stderr.puts "WARN: The --provider-states-url option is deprecated and the URL endpoint can be removed from the application" end end
require_custom_middlware()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 122 def require_custom_middlware options.custom_middleware.each do |file| $stdout.puts "DEBUG: Requiring custom middleware file #{file}" if options.verbose begin require file rescue LoadError => e $stderr.puts "ERROR: #{e.class} - #{e.message}. Please specify an absolute path." exit(1) end end end
require_pact_project_pact_helper()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 180 def require_pact_project_pact_helper require ENV['PACT_PROJECT_PACT_HELPER'] if ENV.fetch('PACT_PROJECT_PACT_HELPER','') != '' end
require_rspec_monkeypatch_for_jsonl()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 184 def require_rspec_monkeypatch_for_jsonl if options.format == 'json' require 'pact/provider_verifier/rspec_json_formatter_monkeypatch' end end
reset_pact_configuration()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 165 def reset_pact_configuration require 'pact/configuration' require 'pact/consumer/world' require 'pact/provider/world' Pact.clear_configuration Pact.clear_consumer_world Pact.clear_provider_world configure_service_provider end
set_broker_token_env_var()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 222 def set_broker_token_env_var if options.broker_token && !ENV['PACT_BROKER_TOKEN'] ENV['PACT_BROKER_TOKEN'] = options.broker_token end end
set_environment_variables()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 56 def set_environment_variables ENV['PROVIDER_STATES_SETUP_URL'] = options.provider_states_setup_url ENV['VERBOSE_LOGGING'] = options.verbose if options.verbose ENV['CUSTOM_PROVIDER_HEADER'] = custom_provider_headers_for_env_var if custom_provider_headers_for_env_var ENV['MONKEYPATCH'] = options.monkeypatch.join("\n") if options.monkeypatch && options.monkeypatch.any? end
setup()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 48 def setup print_deprecation_note set_environment_variables require_rspec_monkeypatch_for_jsonl require_pact_project_pact_helper # Beth: not sure if this is needed, hangover from pact-provider-proxy? set_broker_token_env_var end
verify_pact(pact_uri)
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 141 def verify_pact(pact_uri) begin verify_options = { pact_helper: PROXY_PACT_HELPER, pact_uri: pact_uri, backtrace: ENV['BACKTRACE'] == 'true', pact_broker_username: options.broker_username, pact_broker_password: options.broker_password, pact_broker_token: options.broker_token, format: options.format, out: options.out, request_customizer: ProviderStates::AddProviderStatesHeader } verify_options[:description] = ENV['PACT_DESCRIPTION'] if ENV['PACT_DESCRIPTION'] verify_options[:provider_state] = ENV['PACT_PROVIDER_STATE'] if ENV['PACT_PROVIDER_STATE'] reset_pact_configuration # Really, this should call the PactSpecRunner directly, rather than using the CLI class. Cli::RunPactVerification.call(verify_options) rescue SystemExit => e e.status end end
wait_until_provider_available()
click to toggle source
# File lib/pact/provider_verifier/app.rb, line 209 def wait_until_provider_available if options.wait && options.wait != 0 uri = URI(options.provider_base_url) $stderr.puts "INFO: Polling for up to #{options.wait} seconds for provider to become available at #{uri.host}:#{uri.port}..." up = wait_until_server_available(uri.host, uri.port, options.wait) if up $stderr.puts "INFO: Provider available, proceeding with verifications" else $stderr.puts "WARN: Provider does not appear to be up on #{uri.host}:#{uri.port}... proceeding with verifications anyway" end end end