pact-provider-verifier 1.27.1 → 1.31.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6aa619044ae521e7f472fcb86c62389dd908d4799a509bb3a1b7b688947960b2
4
- data.tar.gz: beedd9e10ca307512db6306c6888c15075caa3878c6db7cb998d377421aef5e1
3
+ metadata.gz: 44c17f0743c806ca23c26957d6011ed92fa7374cf25c2077e2d8fac967695d97
4
+ data.tar.gz: edd33bd8d49c5a74fb5ddac57f71cd9639963d207a24efe52638d0242a567c2c
5
5
  SHA512:
6
- metadata.gz: 549f619ce02b6367a97a4e18534861ee13f3a3f9e3e3dea527d3f4e035d253061fe46e637ec6355ce19fae14e18389e70f51c90bb21d13253ffc926199a13429
7
- data.tar.gz: fdd5bb10143752116f9a5446d2c96e258aacf30fc19684e90bbf431d68104c3c2d428ce9e9a21ac4ba5cb92a5720d721e4f7a39f47e282a1a6dbfd2a98837706
6
+ metadata.gz: 5e651daba957e5270412987777d03b253b54e662ee2205085f62a090eaaa405ab8fa6ecfc50db986365cbf35146c5f6568c4abb7d923f4146d9614e172eece82
7
+ data.tar.gz: d325e9aca5995fe88bba89b7fc6cd10e4a858a3c5cd3d540ae5e9b03b78454ad80d5ea6b46142cfbaa797c5ce7a59e77863e64773719b4a173ffad2bc2ab6031
@@ -1,3 +1,53 @@
1
+ <a name="v1.31.0-1"></a>
2
+ ### v1.31.0-1 (2020-06-23)
3
+
4
+
5
+ #### Features
6
+
7
+ * add --log-dir and --log-level to CLI ([1cf71bb](/../../commit/1cf71bb))
8
+
9
+
10
+ <a name="v1.30.1-1"></a>
11
+ ### v1.30.1-1 (2020-04-22)
12
+
13
+
14
+ #### Bug Fixes
15
+
16
+ * use symbol names for consumer version selectors ([c2c986b](/../../commit/c2c986b))
17
+ * correctly handle multiple parameters specified in the format --name=value ([c0852d0](/../../commit/c0852d0))
18
+
19
+
20
+ <a name="v1.30.0-1"></a>
21
+ ### v1.30.0-1 (2020-02-19)
22
+
23
+
24
+ #### Features
25
+
26
+ * **cli**
27
+ * add --include-wip-pacts-since (hidden until publicly released) ([3109ce2](/../../commit/3109ce2))
28
+
29
+
30
+ <a name="v1.29.0-1"></a>
31
+ ### v1.29.0-1 (2020-02-18)
32
+
33
+
34
+ #### Features
35
+
36
+ * **cli**
37
+ * raise an error when basic auth credentials and bearer token are set at the same time ([7f4507e](/../../commit/7f4507e))
38
+
39
+
40
+ <a name="v1.28.0-1"></a>
41
+ ### v1.28.0-1 (2020-01-22)
42
+
43
+
44
+ #### Features
45
+
46
+ * allow Pact Broker URL and credentials to be set via environment variables ([c257abf](/../../commit/c257abf))
47
+ * ensure output stream is configured to point to the error stream before fetching the pacts so the JSON and XML parsing don't get corrupted ([d816980](/../../commit/d816980))
48
+ * use `lib/pact/provider_verifier/git.rb` to get git sha ([2dd3591](/../../commit/2dd3591))
49
+
50
+
1
51
  <a name="v1.27.1-1"></a>
2
52
  ### v1.27.1-1 (2020-01-16)
3
53
 
data/README.md CHANGED
@@ -17,7 +17,7 @@ binary-like CLI tool.
17
17
 
18
18
  ### Docker
19
19
 
20
- Take a look at https://github.com/DiUS/pact-provider-verifier-docker or https://github.com/pact-foundation/pact-ruby-cli
20
+ Take a look at https://hub.docker.com/r/pactfoundation/pact-cli
21
21
 
22
22
  ### Native Installation
23
23
 
@@ -41,55 +41,53 @@ Usage:
41
41
 
42
42
  Options:
43
43
  -h, --provider-base-url=PROVIDER_BASE_URL
44
- # Provider host URL
44
+ # Provider host URL
45
45
  -c, [--provider-states-setup-url=PROVIDER_STATES_SETUP_URL]
46
- # Base URL to setup the provider states at
46
+ # Base URL to setup the provider states at
47
47
  [--pact-broker-base-url=PACT_BROKER_BASE_URL]
48
- # Base URL of the Pact Broker from which to retrieve the pacts.
48
+ # Base URL of the Pact Broker from which to retrieve the pacts. Can also be set using the environment variable PACT_BROKER_BASE_URL.
49
49
  -n, [--broker-username=BROKER_USERNAME]
50
- # Pact Broker basic auth username
50
+ # Pact Broker basic auth username. Can also be set using the environment variable PACT_BROKER_USERNAME.
51
51
  -p, [--broker-password=BROKER_PASSWORD]
52
- # Pact Broker basic auth password
52
+ # Pact Broker basic auth password. Can also be set using the environment variable PACT_BROKER_PASSWORD.
53
53
  -k, [--broker-token=BROKER_TOKEN]
54
- # Pact Broker bearer token
54
+ # Pact Broker bearer token. Can also be set using the environment variable PACT_BROKER_TOKEN.
55
55
  [--provider=PROVIDER]
56
56
  [--consumer-version-tag=TAG]
57
- # Retrieve the latest pacts with this consumer version tag. Used in conjunction with --provider. May be specified multiple times.
58
- [--consumer-version-selector=SELECTOR]
59
- # JSON string specifying a selector that identifies which pacts to verify. May be specified multiple times. See below for further documentation.
57
+ # Retrieve the latest pacts with this consumer version tag. Used in conjunction with --provider. May be specified multiple times.
60
58
  [--provider-version-tag=TAG]
61
- # Tag to apply to the provider application version. May be specified multiple times.
59
+ # Tag to apply to the provider application version. May be specified multiple times.
60
+ -g, [--tag-with-git-branch], [--no-tag-with-git-branch]
61
+ # Tag provider version with the name of the current git branch. Default: false
62
62
  -a, [--provider-app-version=PROVIDER_APP_VERSION]
63
- # Provider application version, required when publishing verification results
63
+ # Provider application version, required when publishing verification results
64
64
  -r, [--publish-verification-results], [--no-publish-verification-results]
65
- # Publish verification results to the broker. This can also be enabled by setting the environment variable PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true
66
- [--enable-pending], [--no-enable-pending]
67
- # Allow pacts which are in pending state to be verified without causing the overall task to fail. For more information, see https://pact.io/pending
65
+ # Publish verification results to the broker. This can also be enabled by setting the environment variable PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true
68
66
  [--custom-provider-header=CUSTOM_PROVIDER_HEADER]
69
- # Header to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'. May be specified multiple times.
67
+ # Header to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'. May be specified multiple times.
70
68
  [--custom-middleware=FILE]
71
- # Ruby file containing a class implementing Pact::ProviderVerifier::CustomMiddleware. This allows the response to be modified before replaying. Use with caution!
69
+ # Ruby file containing a class implementing Pact::ProviderVerifier::CustomMiddleware. This allows the response to be modified before replaying. Use with caution!
72
70
  -v, [--verbose=VERBOSE]
73
- # Verbose output
71
+ # Verbose output
74
72
  -f, [--format=FORMATTER]
75
- # RSpec formatter. Defaults to custom Pact formatter. Other options are json and RspecJunitFormatter (which outputs xml).
73
+ # RSpec formatter. Defaults to custom Pact formatter. Other options are json and RspecJunitFormatter (which outputs xml).
76
74
  -o, [--out=FILE]
77
- # Write output to a file instead of $stdout.
75
+ # Write output to a file instead of $stdout.
78
76
  [--wait=SECONDS]
79
- # The number of seconds to poll for the provider to become available before running the verification
77
+ # The number of seconds to poll for the provider to become available before running the verification
80
78
 
81
- # Default: 0
79
+ # Default: 0
82
80
 
83
81
  Description:
84
- To verify a pact from a known URL, specify one or more PACT_URL arguments. If the pact is
85
- hosted in a Pact Broker that uses authentication, specify the relevant
86
- --broker-username/--broker-password or --broker-token fields. To dynamically fetch pacts
87
- from a Pact Broker based on the provider name, specify the --pact-broker-base-url,
88
- --provider and relevant authentication fields.
89
-
90
- Selectors: These are specified using JSON strings. The keys are 'tag' (the name of the consumer
91
- version tag) and 'latest' (true|false). For example '{"tag": "master", "latest": true}'.
92
- For a detailed explanation of selectors, see https://pact.io/selectors
82
+ To verify a pact from a known URL, specify one or more PACT_URL arguments. If the
83
+ pact is hosted in a Pact Broker that uses authentication, specify the relevant
84
+ --broker-username/--broker-password or --broker-token fields. To dynamically fetch
85
+ pacts from a Pact Broker based on the provider name, specify the
86
+ --pact-broker-base-url, --provider and relevant authentication fields.
87
+
88
+ Selectors: These are specified using JSON strings. The keys are 'tag' (the name of the
89
+ consumer version tag) and 'latest' (true|false). For example '{"tag": "master",
90
+ "latest": true}'. For a detailed explanation of selectors, see
93
91
  ```
94
92
 
95
93
  ## Examples
@@ -57,7 +57,10 @@ module Pact
57
57
  end
58
58
 
59
59
  def pact_options
60
- { include_pending_status: options[:enable_pending] }
60
+ {
61
+ include_pending_status: options[:enable_pending],
62
+ include_wip_pacts_since: options[:include_wip_pacts_since]
63
+ }
61
64
  end
62
65
  end
63
66
  end
@@ -50,6 +50,7 @@ module Pact
50
50
 
51
51
 
52
52
  def setup
53
+ configure_output
53
54
  print_deprecation_note
54
55
  set_environment_variables
55
56
  require_rspec_monkeypatch_for_jsonl
@@ -90,6 +91,16 @@ module Pact
90
91
  end
91
92
  end
92
93
 
94
+ def configure_output
95
+ if options[:format] && !options[:out]
96
+ # Don't want to mess up the JSON parsing with messages to stdout, so send it to stderr
97
+ require 'pact/configuration'
98
+ Pact.configuration.output_stream = Pact.configuration.error_stream
99
+ end
100
+ Pact.configuration.log_dir = options.log_dir if options.log_dir
101
+ Pact.configuration.logger.level = Kernel.const_get('Logger').const_get(options.log_level.upcase) if options.log_level
102
+ end
103
+
93
104
  def configure_reverse_proxy
94
105
  provider_base_url = options.provider_base_url
95
106
  Rack::ReverseProxy.new do
@@ -148,9 +159,6 @@ module Pact
148
159
  pact_helper: PROXY_PACT_HELPER,
149
160
  pact_uri: pact_uri,
150
161
  backtrace: ENV['BACKTRACE'] == 'true',
151
- pact_broker_username: options.broker_username,
152
- pact_broker_password: options.broker_password,
153
- pact_broker_token: options.broker_token,
154
162
  format: options.format,
155
163
  out: options.out,
156
164
  request_customizer: ProviderStates::AddProviderStatesHeader
@@ -173,21 +181,30 @@ module Pact
173
181
  Pact.clear_configuration
174
182
  Pact.clear_consumer_world
175
183
  Pact.clear_provider_world
184
+ configure_output
176
185
  configure_service_provider
177
186
  end
178
187
 
179
188
  def all_pact_urls
180
- http_client_options = { username: options.broker_username, password: options.broker_password, token: options.broker_token, verbose: options.verbose }
189
+ http_client_options = {
190
+ username: options.broker_username || ENV['PACT_BROKER_USERNAME'],
191
+ password: options.broker_password || ENV['PACT_BROKER_PASSWORD'],
192
+ token: options.broker_token || ENV['PACT_BROKER_TOKEN'],
193
+ verbose: options.verbose
194
+ }
195
+ opts = {
196
+ enable_pending: options.enable_pending,
197
+ include_wip_pacts_since: options.include_wip_pacts_since
198
+ }
181
199
  AggregatePactConfigs.call(
182
200
  pact_urls,
183
201
  options.provider,
184
202
  consumer_version_tags,
185
203
  consumer_version_selectors,
186
204
  provider_version_tags,
187
- options.pact_broker_base_url,
205
+ options.pact_broker_base_url || ENV['PACT_BROKER_BASE_URL'],
188
206
  http_client_options,
189
- { enable_pending: options.enable_pending }
190
- )
207
+ opts)
191
208
  end
192
209
 
193
210
  def require_pact_project_pact_helper
@@ -214,7 +231,7 @@ module Pact
214
231
  end
215
232
 
216
233
  def parse_consumer_version_selectors consumer_version_selectors
217
- consumer_version_selectors.collect{ | string | JSON.parse(string) }
234
+ consumer_version_selectors.collect{ | string | JSON.parse(string, symbolize_names: true) }
218
235
  end
219
236
 
220
237
  def merge_provider_version_tags(options)
@@ -45,20 +45,31 @@ module Pact
45
45
  def self.turn_muliple_tag_options_into_array argv
46
46
  new_argv = []
47
47
  opt_name = nil
48
- argv.each_with_index do | arg, i |
49
- if arg.start_with?('-')
50
- opt_name = arg
51
- existing = new_argv.find { | a | a.first == opt_name }
52
- if !existing
53
- new_argv << [arg]
48
+ argv.each_with_index do | word, i |
49
+ if word.start_with?('-')
50
+ if word.include?('=')
51
+ opt_name, opt_value = word.split('=', 2)
52
+
53
+ existing = new_argv.find { | a | a.first == opt_name }
54
+ if existing
55
+ existing << opt_value
56
+ else
57
+ new_argv << [opt_name, opt_value]
58
+ end
59
+ else
60
+ opt_name = word
61
+ existing = new_argv.find { | a | a.first == opt_name }
62
+ if !existing
63
+ new_argv << [word]
64
+ end
54
65
  end
55
66
  else
56
67
  if opt_name
57
68
  existing = new_argv.find { | a | a.first == opt_name }
58
- existing << arg
69
+ existing << word
59
70
  opt_name = nil
60
71
  else
61
- new_argv << [arg]
72
+ new_argv << [word]
62
73
  end
63
74
  end
64
75
  end
@@ -15,6 +15,7 @@ module Pact
15
15
  class Verify < CustomThor
16
16
 
17
17
  class InvalidArgumentsError < ::Thor::Error; end
18
+ class AuthError < ::Thor::Error; end
18
19
 
19
20
  SELECTOR_DOCS = "Selectors: These are specified using JSON strings. The keys are 'tag' (the name of the consumer version tag) and 'latest' (true|false). " +
20
21
  "For example '{\"tag\": \"master\", \"latest\": true}'. For a detailed explanation of selectors, see https://pact.io/selectors"
@@ -25,18 +26,19 @@ module Pact
25
26
  "\n\n" + SELECTOR_DOCS
26
27
  method_option :provider_base_url, aliases: "-h", desc: "Provider host URL", :required => true
27
28
  method_option :provider_states_setup_url, aliases: "-c", desc: "Base URL to setup the provider states at", :required => false
28
- method_option :pact_broker_base_url, desc: "Base URL of the Pact Broker from which to retrieve the pacts.", :required => false
29
- method_option :broker_username, aliases: "-n", desc: "Pact Broker basic auth username", :required => false
30
- method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password", :required => false
31
- method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token", :required => false
29
+ method_option :pact_broker_base_url, desc: "Base URL of the Pact Broker from which to retrieve the pacts. Can also be set using the environment variable PACT_BROKER_BASE_URL.", :required => false
30
+ method_option :broker_username, aliases: "-n", desc: "Pact Broker basic auth username. Can also be set using the environment variable PACT_BROKER_USERNAME.", :required => false
31
+ method_option :broker_password, aliases: "-p", desc: "Pact Broker basic auth password. Can also be set using the environment variable PACT_BROKER_PASSWORD.", :required => false
32
+ method_option :broker_token, aliases: "-k", desc: "Pact Broker bearer token. Can also be set using the environment variable PACT_BROKER_TOKEN.", :required => false
32
33
  method_option :provider, required: false
33
34
  method_option :consumer_version_tag, type: :array, banner: "TAG", desc: "Retrieve the latest pacts with this consumer version tag. Used in conjunction with --provider. May be specified multiple times.", :required => false
34
- method_option :consumer_version_selector, type: :array, banner: "SELECTOR", desc: "JSON string specifying a selector that identifies which pacts to verify. May be specified multiple times. See below for further documentation.", :required => false
35
+ method_option :consumer_version_selector, hide: true, type: :array, banner: "SELECTOR", desc: "JSON string specifying a selector that identifies which pacts to verify. May be specified multiple times. See below for further documentation.", :required => false
35
36
  method_option :provider_version_tag, type: :array, banner: "TAG", desc: "Tag to apply to the provider application version. May be specified multiple times.", :required => false
36
37
  method_option :tag_with_git_branch, aliases: "-g", type: :boolean, default: false, required: false, desc: "Tag provider version with the name of the current git branch. Default: false"
37
38
  method_option :provider_app_version, aliases: "-a", desc: "Provider application version, required when publishing verification results", :required => false
38
39
  method_option :publish_verification_results, aliases: "-r", desc: "Publish verification results to the broker. This can also be enabled by setting the environment variable PACT_BROKER_PUBLISH_VERIFICATION_RESULTS=true", required: false, type: :boolean, default: false
39
- method_option :enable_pending, desc: "Allow pacts which are in pending state to be verified without causing the overall task to fail. For more information, see https://pact.io/pending", required: false, type: :boolean, default: false
40
+ method_option :enable_pending, hide: true, desc: "Allow pacts which are in pending state to be verified without causing the overall task to fail. For more information, see https://pact.io/pending", required: false, type: :boolean, default: false
41
+ method_option :include_wip_pacts_since, desc: "", hide: true
40
42
  method_option :custom_provider_header, type: :array, banner: 'CUSTOM_PROVIDER_HEADER', desc: "Header to add to provider state set up and pact verification requests. eg 'Authorization: Basic cGFjdDpwYWN0'. May be specified multiple times.", :required => false
41
43
  method_option :custom_middleware, type: :array, banner: 'FILE', desc: "Ruby file containing a class implementing Pact::ProviderVerifier::CustomMiddleware. This allows the response to be modified before replaying. Use with caution!", :required => false
42
44
  method_option :monkeypatch, hide: true, type: :array, :required => false
@@ -47,6 +49,8 @@ module Pact
47
49
  method_option :ignore_failures, type: :boolean, default: false, desc: "If specified, process will always exit with exit code 0", hide: true
48
50
  method_option :pact_urls, aliases: "-u", hide: true, :required => false
49
51
  method_option :wait, banner: "SECONDS", required: false, type: :numeric, desc: "The number of seconds to poll for the provider to become available before running the verification", default: 0
52
+ method_option :log_dir, desc: "The directory for the pact.log file"
53
+ method_option :log_level, desc: "The log level", default: "debug"
50
54
 
51
55
  def verify(*pact_urls)
52
56
  validate_verify
@@ -80,6 +84,27 @@ module Pact
80
84
  raise InvalidArgumentsError, "No value provided for required option '--provider'"
81
85
  end
82
86
  validate_consumer_version_selectors
87
+ validate_wip_since_date
88
+ validate_credentials
89
+ validate_log_level
90
+ end
91
+
92
+ def validate_credentials
93
+ if (options.broker_username || ENV['PACT_BROKER_USERNAME']) && (options.broker_token || ENV['PACT_BROKER_TOKEN'])
94
+ raise AuthError, "You cannot provide both a username/password and a bearer token. If your Pact Broker uses a bearer token, please remove the username and password configuration."
95
+ end
96
+ end
97
+
98
+ def validate_wip_since_date
99
+ require 'date'
100
+
101
+ if options.include_wip_pacts_since
102
+ begin
103
+ DateTime.parse(options.include_wip_pacts_since)
104
+ rescue ArgumentError
105
+ raise InvalidArgumentsError, "The value provided for --include-wip-pacts-since could not be parsed to a DateTime. Please provide a value in the format %Y-%m-%d or %Y-%m-%dT%H:%M:%S.000%:z"
106
+ end
107
+ end
83
108
  end
84
109
 
85
110
  def validate_consumer_version_selectors
@@ -97,6 +122,15 @@ module Pact
97
122
  end
98
123
  end
99
124
 
125
+ def validate_log_level
126
+ if options.log_level
127
+ valid_log_levels = %w{debug info warn error fatal}
128
+ if !valid_log_levels.include?(options.log_level.downcase)
129
+ raise InvalidArgumentsError, "Invalid log level '#{options.log_level}'. Must be one of: #{valid_log_levels.join(", ")}."
130
+ end
131
+ end
132
+ end
133
+
100
134
  def exit_with_non_zero_status
101
135
  exit 1
102
136
  end
@@ -5,7 +5,7 @@ require 'pact/provider_verifier/error'
5
5
  module Pact
6
6
  module ProviderVerifier
7
7
  module Git
8
- COMMAND = 'git name-rev --name-only HEAD'.freeze
8
+ COMMAND = 'git rev-parse --abbrev-ref HEAD'.freeze
9
9
  BRANCH_ENV_VAR_NAMES = %w{BUILDKITE_BRANCH CIRCLE_BRANCH TRAVIS_BRANCH GIT_BRANCH GIT_LOCAL_BRANCH APPVEYOR_REPO_BRANCH CI_COMMIT_REF_NAME}.freeze
10
10
 
11
11
  def self.branch
@@ -1,5 +1,5 @@
1
1
  module Pact
2
2
  module ProviderVerifier
3
- VERSION = "1.27.1"
3
+ VERSION = "1.31.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pact-provider-verifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.27.1
4
+ version: 1.31.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Fellows
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-01-17 00:00:00.000000000 Z
12
+ date: 2020-06-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -31,14 +31,14 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.43'
34
+ version: '1.49'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.43'
41
+ version: '1.49'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: pact-message
44
44
  requirement: !ruby/object:Gem::Requirement