Skip to content

Commit

Permalink
feat: 38 add docker environment variable PACT_BROKER_WEBHOOK_HTTP_COD…
Browse files Browse the repository at this point in the history
…E_SUCCESS (#39)

* feat: 38 add docker environment variable PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS
feat: do not print database password, if present

* fix: move password masking from config.ru to docker_configuration.rb
fix: copy&paste issue in the test suite
  • Loading branch information
pitschr authored Feb 21, 2021
1 parent 4529156 commit 00b6c46
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Set the environment variable `PACT_BROKER_LOG_LEVEL` to one of `DEBUG`, `INFO`,
## Other webhook settings

* `PACT_BROKER_WEBHOOK_RETRY_SCHEDULE` - a space delimited list of integers specifying the number of seconds after which to retry webhook requests when they fail. Defaults to `10 60 120 300 600 1200`. This does not normally need to be changed.
* `PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS` - a space delimited list of successful http codes (e.g. `200 201 301`). Defaults to `200 201 202 203 204 205 206`. If webhook call returns the response with http code that is listed in the success codes then the operation is considered as a success, otherwise the webhook will be re-triggered based on `PACT_BROKER_WEBHOOK_RETRY_SCHEDULE` configuration.

## Other environment variables

Expand Down
1 change: 1 addition & 0 deletions pact_broker/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ app = PactBroker::App.new do | config |
config.webhook_http_method_whitelist = dc.webhook_http_method_whitelist
config.webhook_scheme_whitelist = dc.webhook_scheme_whitelist
config.webhook_retry_schedule = dc.webhook_retry_schedule
config.webhook_http_code_success = dc.webhook_http_code_success
config.base_equality_only_on_content_that_affects_verification_results = dc.base_equality_only_on_content_that_affects_verification_results
config.order_versions_by_date = dc.order_versions_by_date
config.disable_ssl_verification = dc.disable_ssl_verification
Expand Down
13 changes: 12 additions & 1 deletion pact_broker/docker_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ def initialize env, default_configuration

def pact_broker_environment_variables
pact_broker_environment_variable_names.sort.each_with_object({}) do | name, hash |
hash[name] = name =~ /password/i ? "*****" : @env[name]
value = @env[name]
# special case: suppress password of database connection string, if present
if name == "PACT_BROKER_DATABASE_URL" && value =~ /:\/\/[^:]+:[^@]+@/
hash[name] = value.sub(/(:\/\/[^:]+):[^@]+@/, '\1:*****@')
else
hash[name] = name =~ /password/i ? "*****" : value
end

end
end

Expand All @@ -30,6 +37,10 @@ def webhook_http_method_whitelist
space_delimited_string_list_or_default(:webhook_http_method_whitelist)
end

def webhook_http_code_success
space_delimited_integer_list_or_default(:webhook_http_code_success)
end

def webhook_retry_schedule
space_delimited_integer_list_or_default(:webhook_retry_schedule)
end
Expand Down
17 changes: 17 additions & 0 deletions spec/docker_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
{
"PACT_BROKER_WEBHOOK_HOST_WHITELIST" => host_whitelist,
"PACT_BROKER_WEBHOOK_RETRY_SCHEDULE" => retry_schedule,
"PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS" => http_code_success,
"PACT_BROKER_ORDER_VERSIONS_BY_DATE" => "false"
}
end
Expand All @@ -18,9 +19,12 @@

let(:retry_schedule) { "" }

let(:http_code_success) { "" }

let(:default_configuration) do
instance_double('default configuration',
webhook_host_whitelist: 'default',
webhook_http_code_success: 'default',
webhook_retry_schedule: 'default'
)
end
Expand Down Expand Up @@ -111,6 +115,7 @@
it { expect(subject.database_configuration[:database]).to eq "pactbroker" }
it { expect(subject.database_configuration[:encoding]).to eq "utf8" }
it { expect(subject.database_configuration[:port]).to eq 5432 }
it { expect(subject.pact_broker_environment_variables["PACT_BROKER_DATABASE_URL"]).to eq "postgresql://pactbrokeruser:*****@localhost:5432/pactbroker" }
end

context "using a configured environment variable name and an arbitrary env var" do
Expand Down Expand Up @@ -212,6 +217,18 @@
end
end

describe "webhook_http_code_success" do
context "when PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS is '200 202 301 302'" do
let(:http_code_success) { "200 202 301 302" }
its(:webhook_http_code_success) { is_expected.to eq [200, 202, 301, 302] }
end

context "when PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS is ''" do
let(:http_code_success) { "" }
its(:webhook_http_code_success) { is_expected.to eq 'default' }
end
end

describe "webhook_retry_schedule" do
context "when PACT_BROKER_WEBHOOK_RETRY_SCHEDULE is '1 2 3'" do
let(:retry_schedule) { "1 2 3" }
Expand Down

0 comments on commit 00b6c46

Please sign in to comment.