Skip to content

Commit

Permalink
fix: set username from PACT_BROKER_USERNAME environment variable corr…
Browse files Browse the repository at this point in the history
…ectly when -u specified for create-or-update-webhook and create-webhook

Closes: pact-foundation/pact-ruby-cli#20
  • Loading branch information
bethesque committed Mar 10, 2021
1 parent 7a000d1 commit 2411396
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 20 deletions.
12 changes: 6 additions & 6 deletions lib/pact_broker/client/cli/broker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
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.
2 changes: 2 additions & 0 deletions lib/pact_broker/client/cli/create_webhook_long_desc.txt
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 2 additions & 5 deletions lib/pact_broker/client/cli/custom_thor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -117,4 +114,4 @@ def self.verbose_option
end
end
end
end
end
2 changes: 2 additions & 0 deletions spec/lib/pact_broker/client/cli/broker_can_i_deploy_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/client/cli/broker_publish_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions spec/lib/pact_broker/client/cli/custom_thor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,16 @@ 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

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
Expand Down

0 comments on commit 2411396

Please sign in to comment.