Skip to content

Commit 00b6c46

Browse files
authored
feat: 38 add docker environment variable PACT_BROKER_WEBHOOK_HTTP_CODE_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
1 parent 4529156 commit 00b6c46

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Set the environment variable `PACT_BROKER_LOG_LEVEL` to one of `DEBUG`, `INFO`,
113113
## Other webhook settings
114114

115115
* `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.
116+
* `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.
116117

117118
## Other environment variables
118119

Diff for: pact_broker/config.ru

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ app = PactBroker::App.new do | config |
2121
config.webhook_http_method_whitelist = dc.webhook_http_method_whitelist
2222
config.webhook_scheme_whitelist = dc.webhook_scheme_whitelist
2323
config.webhook_retry_schedule = dc.webhook_retry_schedule
24+
config.webhook_http_code_success = dc.webhook_http_code_success
2425
config.base_equality_only_on_content_that_affects_verification_results = dc.base_equality_only_on_content_that_affects_verification_results
2526
config.order_versions_by_date = dc.order_versions_by_date
2627
config.disable_ssl_verification = dc.disable_ssl_verification

Diff for: pact_broker/docker_configuration.rb

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,14 @@ def initialize env, default_configuration
99

1010
def pact_broker_environment_variables
1111
pact_broker_environment_variable_names.sort.each_with_object({}) do | name, hash |
12-
hash[name] = name =~ /password/i ? "*****" : @env[name]
12+
value = @env[name]
13+
# special case: suppress password of database connection string, if present
14+
if name == "PACT_BROKER_DATABASE_URL" && value =~ /:\/\/[^:]+:[^@]+@/
15+
hash[name] = value.sub(/(:\/\/[^:]+):[^@]+@/, '\1:*****@')
16+
else
17+
hash[name] = name =~ /password/i ? "*****" : value
18+
end
19+
1320
end
1421
end
1522

@@ -30,6 +37,10 @@ def webhook_http_method_whitelist
3037
space_delimited_string_list_or_default(:webhook_http_method_whitelist)
3138
end
3239

40+
def webhook_http_code_success
41+
space_delimited_integer_list_or_default(:webhook_http_code_success)
42+
end
43+
3344
def webhook_retry_schedule
3445
space_delimited_integer_list_or_default(:webhook_retry_schedule)
3546
end

Diff for: spec/docker_configuration_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
{
1111
"PACT_BROKER_WEBHOOK_HOST_WHITELIST" => host_whitelist,
1212
"PACT_BROKER_WEBHOOK_RETRY_SCHEDULE" => retry_schedule,
13+
"PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS" => http_code_success,
1314
"PACT_BROKER_ORDER_VERSIONS_BY_DATE" => "false"
1415
}
1516
end
@@ -18,9 +19,12 @@
1819

1920
let(:retry_schedule) { "" }
2021

22+
let(:http_code_success) { "" }
23+
2124
let(:default_configuration) do
2225
instance_double('default configuration',
2326
webhook_host_whitelist: 'default',
27+
webhook_http_code_success: 'default',
2428
webhook_retry_schedule: 'default'
2529
)
2630
end
@@ -111,6 +115,7 @@
111115
it { expect(subject.database_configuration[:database]).to eq "pactbroker" }
112116
it { expect(subject.database_configuration[:encoding]).to eq "utf8" }
113117
it { expect(subject.database_configuration[:port]).to eq 5432 }
118+
it { expect(subject.pact_broker_environment_variables["PACT_BROKER_DATABASE_URL"]).to eq "postgresql://pactbrokeruser:*****@localhost:5432/pactbroker" }
114119
end
115120

116121
context "using a configured environment variable name and an arbitrary env var" do
@@ -212,6 +217,18 @@
212217
end
213218
end
214219

220+
describe "webhook_http_code_success" do
221+
context "when PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS is '200 202 301 302'" do
222+
let(:http_code_success) { "200 202 301 302" }
223+
its(:webhook_http_code_success) { is_expected.to eq [200, 202, 301, 302] }
224+
end
225+
226+
context "when PACT_BROKER_WEBHOOK_HTTP_CODE_SUCCESS is ''" do
227+
let(:http_code_success) { "" }
228+
its(:webhook_http_code_success) { is_expected.to eq 'default' }
229+
end
230+
end
231+
215232
describe "webhook_retry_schedule" do
216233
context "when PACT_BROKER_WEBHOOK_RETRY_SCHEDULE is '1 2 3'" do
217234
let(:retry_schedule) { "1 2 3" }

0 commit comments

Comments
 (0)