diff --git a/lib/pact_broker/client/cli/broker.rb b/lib/pact_broker/client/cli/broker.rb index ceeaff47..44b1aca2 100644 --- a/lib/pact_broker/client/cli/broker.rb +++ b/lib/pact_broker/client/cli/broker.rb @@ -287,15 +287,15 @@ def explict_auto_detect_version_properties def pact_broker_client_options client_options = { verbose: options.verbose } - client_options[:token] = options.broker_token if options.broker_token - if options.broker_username + client_options[:token] = options.broker_token || ENV['PACT_BROKER_TOKEN'] + if options.broker_username || ENV['PACT_BROKER_USERNAME'] client_options[:basic_auth] = { - username: options.broker_username, - password: options.broker_password - } + username: options.broker_username || ENV['PACT_BROKER_USERNAME'], + password: options.broker_password || ENV['PACT_BROKER_PASSWORD'] + }.compact end - client_options + client_options.compact end def parse_webhook_events diff --git a/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt b/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt index a1b2eae7..aff29c88 100644 --- a/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt +++ b/lib/pact_broker/client/cli/create_or_update_webhook_long_desc.txt @@ -1 +1,3 @@ -Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid must also be provided. You can generate a valid UUID by using the `generate-uuid` command. \ No newline at end of file +Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-or-update-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-or-update-webhook and a uuid must also be provided. You can generate a valid UUID by using the `generate-uuid` command. + +Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl option. Please use the --broker-username or environment variable for the Pact Broker username. \ No newline at end of file diff --git a/lib/pact_broker/client/cli/create_webhook_long_desc.txt b/lib/pact_broker/client/cli/create_webhook_long_desc.txt index 9f8dac75..c60625b5 100644 --- a/lib/pact_broker/client/cli/create_webhook_long_desc.txt +++ b/lib/pact_broker/client/cli/create_webhook_long_desc.txt @@ -1 +1,3 @@ Create a curl command that executes the request that you want your webhook to execute, then replace "curl" with "pact-broker create-webhook" and add the consumer, provider, event types and broker details. Note that the URL must be the first parameter when executing create-webhook. + +Note that the -u option from the curl command clashes with the -u option from the pact-broker CLI. When used in this command, the -u will be used as a curl option. Please use the --broker-username or environment variable for the Pact Broker username. diff --git a/lib/pact_broker/client/cli/custom_thor.rb b/lib/pact_broker/client/cli/custom_thor.rb index d5d4794b..3cfef70a 100644 --- a/lib/pact_broker/client/cli/custom_thor.rb +++ b/lib/pact_broker/client/cli/custom_thor.rb @@ -22,10 +22,7 @@ def self.massage_args argv def self.add_broker_config_from_environment_variables argv return argv if argv[0] == 'help' || argv.empty? - new_argv = add_option_from_environment_variable(argv, 'broker-base-url', 'b', 'PACT_BROKER_BASE_URL') - new_argv = add_option_from_environment_variable(new_argv, 'broker-username', 'u', 'PACT_BROKER_USERNAME') - new_argv = add_option_from_environment_variable(new_argv, 'broker-token', 'k', 'PACT_BROKER_TOKEN') - add_option_from_environment_variable(new_argv, 'broker-password', 'p', 'PACT_BROKER_PASSWORD') + add_option_from_environment_variable(argv, 'broker-base-url', 'b', 'PACT_BROKER_BASE_URL') end def self.add_option_from_environment_variable argv, long_name, short_name, environment_variable_name @@ -117,4 +114,4 @@ def self.verbose_option end end end -end \ No newline at end of file +end diff --git a/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb b/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb index 77468eb7..3630cc17 100644 --- a/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb +++ b/spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb @@ -1,4 +1,6 @@ require 'pact_broker/client/cli/broker' +require 'pact_broker/client/cli/version_selector_options_parser' +require 'pact_broker/client/can_i_deploy' module PactBroker module Client diff --git a/spec/lib/pact_broker/client/cli/broker_publish_spec.rb b/spec/lib/pact_broker/client/cli/broker_publish_spec.rb index 5d2bd1ce..bee53730 100644 --- a/spec/lib/pact_broker/client/cli/broker_publish_spec.rb +++ b/spec/lib/pact_broker/client/cli/broker_publish_spec.rb @@ -28,7 +28,7 @@ module PactBroker::Client::CLI "http://pact-broker", ["spec/support/cli_test_pacts/foo.json"], { number: "1.2.3", tags: [], version_required: false }, - { verbose: nil } + { } ) invoke_broker end diff --git a/spec/lib/pact_broker/client/cli/custom_thor_spec.rb b/spec/lib/pact_broker/client/cli/custom_thor_spec.rb index 74407ce2..6e69bcc1 100644 --- a/spec/lib/pact_broker/client/cli/custom_thor_spec.rb +++ b/spec/lib/pact_broker/client/cli/custom_thor_spec.rb @@ -52,12 +52,9 @@ def test_without_parameters ENV['PACT_BROKER_TOKEN'] = 'token' end - it "populates the options from the environment variables" do + it "populates the base URL from the environment variables" do expect(Delegate).to receive(:call) do | options | expect(options.broker_base_url).to eq 'http://foo' - expect(options.broker_username).to eq 'username' - expect(options.broker_password).to eq 'password' - expect(options.broker_token).to eq 'token' end TestThor.start(%w{test_using_env_vars}) end @@ -65,9 +62,6 @@ def test_without_parameters it "does not override a value specifed on the command line" do expect(Delegate).to receive(:call) do | options | expect(options.broker_base_url).to eq 'http://bar' - expect(options.broker_username).to eq 'username' - expect(options.broker_password).to eq 'password' - expect(options.broker_token).to eq 'token' end TestThor.start(%w{test_using_env_vars --broker-base-url http://bar}) end