-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: expose webhook whitelist configuration as environment variables
- Loading branch information
Showing
13 changed files
with
252 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pact_broker/pact_broker.sqlite | ||
pact_broker.sqlite | ||
pact_broker/log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--format documentation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
require 'conventional_changelog' | ||
require 'rspec/core' | ||
require 'rspec/core/rake_task' | ||
|
||
task :generate_changelog do | ||
ConventionalChangelog::Generator.new.generate! version: ENV.fetch('TAG') | ||
end | ||
|
||
RSpec::Core::RakeTask.new(:spec) | ||
|
||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# @private - do not rely on these classes as a public interface | ||
|
||
module PactBroker | ||
class DockerConfiguration | ||
def initialize env, default_configuration | ||
@env = env | ||
@default_configuration = default_configuration | ||
end | ||
|
||
def pact_broker_environment_variables | ||
@env.each_with_object({}) do | (key, value), hash | | ||
if key.start_with?("PACT_BROKER_") | ||
hash[key] = key =~ /password/i ? "*****" : value | ||
end | ||
end | ||
end | ||
|
||
def webhook_host_whitelist | ||
space_delimited_string_list_or_default(:webhook_host_whitelist) | ||
end | ||
|
||
def webhook_scheme_whitelist | ||
space_delimited_string_list_or_default(:webhook_scheme_whitelist) | ||
end | ||
|
||
def webhook_http_method_whitelist | ||
space_delimited_string_list_or_default(:webhook_http_method_whitelist) | ||
end | ||
|
||
def base_equality_only_on_content_that_affects_verification_results | ||
if env_populated?(:base_equality_only_on_content_that_affects_verification_results) | ||
env(:base_equality_only_on_content_that_affects_verification_results) == 'true' | ||
else | ||
default(:base_equality_only_on_content_that_affects_verification_results) | ||
end | ||
end | ||
|
||
def env name | ||
@env["PACT_BROKER_#{name.to_s.upcase}"] | ||
end | ||
|
||
def env_populated? name | ||
(env(name) || "").size > 0 | ||
end | ||
|
||
def default property_name | ||
@default_configuration.send(property_name) | ||
end | ||
|
||
def space_delimited_string_list_or_default property_name | ||
if env_populated?(property_name) | ||
SpaceDelimitedStringList.parse(env(property_name)) | ||
else | ||
default(property_name) | ||
end | ||
end | ||
|
||
class SpaceDelimitedStringList < Array | ||
|
||
def initialize list | ||
super(list) | ||
end | ||
|
||
def self.parse(string) | ||
array = (string || '').split(' ').collect do | word | | ||
if word[0] == '/' and word[-1] == '/' | ||
Regexp.new(word[1..-2]) | ||
else | ||
word | ||
end | ||
end | ||
SpaceDelimitedStringList.new(array) | ||
end | ||
|
||
def to_s | ||
collect do | word | | ||
if word.is_a?(Regexp) | ||
"/#{word.source}/" | ||
else | ||
word | ||
end | ||
end.join(' ') | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
$: << "." | ||
require "pact_broker/docker_configuration" | ||
require 'rspec/its' | ||
|
||
RSpec.describe PactBroker::DockerConfiguration do | ||
|
||
subject { PactBroker::DockerConfiguration.new(env, default_configuration) } | ||
|
||
let(:env) do | ||
{ | ||
"PACT_BROKER_WEBHOOK_HOST_WHITELIST" => host_whitelist | ||
} | ||
end | ||
|
||
let(:default_configuration) do | ||
instance_double('default configuration', | ||
webhook_host_whitelist: 'default' | ||
) | ||
end | ||
|
||
describe "pact_broker_environment_variables" do | ||
let(:env) do | ||
{ | ||
"PACT_BROKER_FOO" => "foo", | ||
"PACT_BROKER_PASSWORD" => "bar", | ||
"SOMETHING" => "foo" | ||
} | ||
end | ||
|
||
let(:expected_environment_variables) do | ||
{ | ||
"PACT_BROKER_FOO" => "foo", | ||
"PACT_BROKER_PASSWORD" => "*****" | ||
} | ||
end | ||
|
||
its(:pact_broker_environment_variables) { is_expected.to eq expected_environment_variables } | ||
end | ||
|
||
describe "webhook_host_whitelist" do | ||
context "when PACT_BROKER_WEBHOOK_HOST_WHITELIST is 'foo bar'" do | ||
let(:host_whitelist) { "foo bar" } | ||
its(:webhook_host_whitelist) { is_expected.to eq ["foo", "bar"] } | ||
end | ||
|
||
context "when PACT_BROKER_WEBHOOK_HOST_WHITELIST is ''" do | ||
let(:host_whitelist) { "" } | ||
its(:webhook_host_whitelist) { is_expected.to eq 'default' } | ||
end | ||
end | ||
end | ||
|
||
class PactBroker::DockerConfiguration | ||
describe SpaceDelimitedStringList do | ||
describe "parse" do | ||
subject { SpaceDelimitedStringList.parse(input) } | ||
|
||
context "when input is ''" do | ||
let(:input) { "" } | ||
|
||
it { is_expected.to eq [] } | ||
|
||
its(:to_s) { is_expected.to eq input } | ||
end | ||
|
||
context "when input is 'foo bar'" do | ||
let(:input) { "foo bar" } | ||
|
||
it { is_expected.to eq ["foo", "bar"] } | ||
|
||
it { is_expected.to be_a SpaceDelimitedStringList } | ||
|
||
its(:to_s) { is_expected.to eq input } | ||
end | ||
|
||
context "when input is '/foo.*/'" do | ||
let(:input) { "/foo.*/" } | ||
|
||
it { is_expected.to eq [/foo.*/] } | ||
|
||
its(:to_s) { is_expected.to eq input } | ||
end | ||
|
||
context "when input is '/foo\\.*/' (note double backslash)" do | ||
let(:input) { "/foo\\.*/" } | ||
|
||
it { is_expected.to eq [/foo\.*/] } | ||
|
||
its(:to_s) { is_expected.to eq input } | ||
end | ||
end | ||
end | ||
end |