pact_broker 2.61.0 → 2.62.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -0
- data/db/migrations/20200922_add_event_to_triggered_webhook.rb +5 -0
- data/lib/pact_broker/api/decorators/triggered_webhook_decorator.rb +1 -0
- data/lib/pact_broker/api/pact_broker_urls.rb +9 -2
- data/lib/pact_broker/configuration.rb +12 -1
- data/lib/pact_broker/db.rb +14 -0
- data/lib/pact_broker/db/table_dependency_calculator.rb +45 -0
- data/lib/pact_broker/domain/webhook_request.rb +3 -1
- data/lib/pact_broker/test/test_data_builder.rb +1 -1
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/webhooks/repository.rb +3 -2
- data/lib/pact_broker/webhooks/service.rb +1 -1
- data/lib/pact_broker/webhooks/triggered_webhook.rb +1 -3
- data/lib/pact_broker/webhooks/webhook_event.rb +1 -2
- data/spec/lib/pact_broker/api/decorators/pact_webhooks_status_decorator_spec.rb +2 -1
- data/spec/lib/pact_broker/api/decorators/triggered_webhook_decorator_spec.rb +3 -1
- data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +15 -0
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +3 -2
- data/tasks/database.rb +1 -0
- data/tasks/database/table_dependency_calculator.rb +4 -41
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d90410ba82c9f6ee8681073d1a9435660abf73045fa4ea08658294512771106
|
4
|
+
data.tar.gz: ff2c697fa385d574c26225ebf3aa6bb93276a749bfc6851685dc17728aa18fb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95c87ab86bd54c472362e678a8fd6307637ad34059beb390baf59fa33456014ed47bd725940fe792ffd7151c80201baf9c063d670b7ed4c857708c22e60e352a
|
7
|
+
data.tar.gz: 3c101564948c497f80d286eccfd70cc92734c5a94b280825bd437c3a6ab4141caf7e98fefb6594b230d0021bba732c44704e9338df081c630d752f0bbb3140cc
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
<a name="v2.62.0"></a>
|
2
|
+
### v2.62.0 (2020-09-23)
|
3
|
+
|
4
|
+
#### Features
|
5
|
+
|
6
|
+
* **webhooks**
|
7
|
+
* remove user-agent and accept-encoding headers which the Ruby HTTP library adds by default ([ef25b88c](/../../commit/ef25b88c))
|
8
|
+
|
9
|
+
* add event name to triggered webhook ([ecce16fd](/../../commit/ecce16fd))
|
10
|
+
|
11
|
+
#### Bug Fixes
|
12
|
+
|
13
|
+
* **webhooks**
|
14
|
+
* use path to initialise http request, rather than full URL ([ecbac9a6](/../../commit/ecbac9a6))
|
15
|
+
|
16
|
+
* gracefully handle corrupt webhook metadata in pact URL ([ba94c355](/../../commit/ba94c355))
|
17
|
+
|
1
18
|
<a name="v2.61.0"></a>
|
2
19
|
### v2.61.0 (2020-09-12)
|
3
20
|
|
@@ -9,6 +9,7 @@ module PactBroker
|
|
9
9
|
property :number_of_attempts_made, as: :attemptsMade
|
10
10
|
property :number_of_attempts_remaining, as: :attemptsRemaining
|
11
11
|
property :trigger_type, as: :triggerType
|
12
|
+
property :event_name, as: :eventName
|
12
13
|
|
13
14
|
property :created_at, as: :triggeredAt
|
14
15
|
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'erb'
|
2
2
|
require 'pact_broker/pacts/metadata'
|
3
|
+
require 'pact_broker/logging'
|
3
4
|
|
4
5
|
module PactBroker
|
5
6
|
module Api
|
6
7
|
module PactBrokerUrls
|
7
8
|
|
8
9
|
include PactBroker::Pacts::Metadata
|
10
|
+
include PactBroker::Logging
|
9
11
|
# TODO make base_url the last and optional argument for all methods, defaulting to ''
|
10
12
|
|
11
13
|
extend self
|
@@ -70,8 +72,13 @@ module PactBroker
|
|
70
72
|
|
71
73
|
def decode_webhook_metadata(metadata)
|
72
74
|
if metadata
|
73
|
-
|
74
|
-
|
75
|
+
begin
|
76
|
+
Rack::Utils.parse_nested_query(Base64.strict_decode64(metadata)).each_with_object({}) do | (k, v), new_hash |
|
77
|
+
new_hash[k.to_sym] = v
|
78
|
+
end
|
79
|
+
rescue StandardError => e
|
80
|
+
logger.warn("Exception parsing webhook metadata: #{metadata}", e)
|
81
|
+
{}
|
75
82
|
end
|
76
83
|
else
|
77
84
|
{}
|
@@ -32,7 +32,12 @@ module PactBroker
|
|
32
32
|
:base_equality_only_on_content_that_affects_verification_results,
|
33
33
|
:seed_example_data,
|
34
34
|
:badge_provider_mode,
|
35
|
-
:warning_error_class_names
|
35
|
+
:warning_error_class_names,
|
36
|
+
:base_url,
|
37
|
+
:log_dir,
|
38
|
+
:allow_missing_migration_files,
|
39
|
+
:auto_migrate_db_data,
|
40
|
+
:use_rack_protection
|
36
41
|
]
|
37
42
|
|
38
43
|
attr_accessor :base_url, :log_dir, :database_connection, :auto_migrate_db, :auto_migrate_db_data, :allow_missing_migration_files, :example_data_seeder, :seed_example_data, :use_hal_browser, :html_pact_renderer, :use_rack_protection
|
@@ -129,6 +134,12 @@ module PactBroker
|
|
129
134
|
@custom_logger = logger
|
130
135
|
end
|
131
136
|
|
137
|
+
def log_configuration
|
138
|
+
SAVABLE_SETTING_NAMES.sort.each do | setting |
|
139
|
+
logger.info "PactBroker.configuration.#{setting}=#{PactBroker.configuration.send(setting).inspect}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
132
143
|
def self.default_html_pact_render
|
133
144
|
lambda { |pact, options|
|
134
145
|
require 'pact_broker/api/renderers/html_pact_renderer'
|
data/lib/pact_broker/db.rb
CHANGED
@@ -3,6 +3,7 @@ require 'pact_broker/db/validate_encoding'
|
|
3
3
|
require 'pact_broker/db/migrate'
|
4
4
|
require 'pact_broker/db/migrate_data'
|
5
5
|
require 'pact_broker/db/version'
|
6
|
+
require 'pact_broker/db/table_dependency_calculator'
|
6
7
|
|
7
8
|
Sequel.datetime_class = DateTime
|
8
9
|
|
@@ -31,6 +32,19 @@ module PactBroker
|
|
31
32
|
Sequel::TimestampMigrator.is_current?(database_connection, PactBroker::DB::MIGRATIONS_DIR, options)
|
32
33
|
end
|
33
34
|
|
35
|
+
def self.truncate database_connection, options = {}
|
36
|
+
exceptions = options[:except] || []
|
37
|
+
TableDependencyCalculator.call(database_connection).each do | table_name |
|
38
|
+
if !exceptions.include?(table_name)
|
39
|
+
begin
|
40
|
+
database_connection[table_name].truncate
|
41
|
+
rescue StandardError => e
|
42
|
+
puts "Could not truncate table #{table_name}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
34
48
|
def self.version database_connection
|
35
49
|
PactBroker::DB::Version.call(database_connection)
|
36
50
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module PactBroker
|
2
|
+
module DB
|
3
|
+
|
4
|
+
# Returns a list of the tables in the database in the order in which
|
5
|
+
# they can be truncated or dropped
|
6
|
+
class TableDependencyCalculator
|
7
|
+
|
8
|
+
def self.call connection
|
9
|
+
new(connection).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize connection
|
13
|
+
@connection = connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def call
|
17
|
+
ordered_table_names = []
|
18
|
+
dependencies = @connection
|
19
|
+
.tables
|
20
|
+
.collect{|it| @connection.foreign_key_list(it)
|
21
|
+
.collect{|fk| {from: it, to: fk[:table]} } }
|
22
|
+
.flatten
|
23
|
+
.uniq
|
24
|
+
table_names = @connection.tables - [:schema_migrations, :schema_info]
|
25
|
+
check(table_names, dependencies, ordered_table_names)
|
26
|
+
ordered_table_names
|
27
|
+
end
|
28
|
+
|
29
|
+
def deps_on table_name, deps
|
30
|
+
deps.select{ | d| d[:to] == table_name }.collect{ |d| d[:from] }
|
31
|
+
end
|
32
|
+
|
33
|
+
def check table_names, deps, ordered_table_names
|
34
|
+
return if table_names.size == 0
|
35
|
+
remaining_dependencies = deps_on(table_names.first, deps) - ordered_table_names
|
36
|
+
if remaining_dependencies.size == 0
|
37
|
+
ordered_table_names << table_names.first
|
38
|
+
check(table_names[1..-1], deps, ordered_table_names)
|
39
|
+
else
|
40
|
+
check((remaining_dependencies + table_names).uniq, deps, ordered_table_names)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -59,7 +59,9 @@ module PactBroker
|
|
59
59
|
|
60
60
|
def http_request
|
61
61
|
@http_request ||= begin
|
62
|
-
req = Net::HTTP.const_get(method.capitalize).new(
|
62
|
+
req = Net::HTTP.const_get(method.capitalize).new(uri.request_uri)
|
63
|
+
req.delete("accept-encoding")
|
64
|
+
req.delete("user-agent")
|
63
65
|
headers.each_pair { | name, value | req[name] = value }
|
64
66
|
req.basic_auth(username, password) if username && username.size > 0
|
65
67
|
req.body = body unless body.nil?
|
@@ -294,7 +294,7 @@ module PactBroker
|
|
294
294
|
params.delete(:comment)
|
295
295
|
trigger_uuid = params[:trigger_uuid] || webhook_service.next_uuid
|
296
296
|
verification = @webhook.trigger_on_provider_verification_published? ? @verification : nil
|
297
|
-
@triggered_webhook = webhook_repository.create_triggered_webhook trigger_uuid, @webhook, @pact, verification, PactBroker::Webhooks::Service::RESOURCE_CREATION
|
297
|
+
@triggered_webhook = webhook_repository.create_triggered_webhook trigger_uuid, @webhook, @pact, verification, PactBroker::Webhooks::Service::RESOURCE_CREATION, @webhook.events.first.name
|
298
298
|
@triggered_webhook.update(status: params[:status]) if params[:status]
|
299
299
|
set_created_at_if_set params[:created_at], :triggered_webhooks, {id: @triggered_webhook.id}
|
300
300
|
self
|
data/lib/pact_broker/version.rb
CHANGED
@@ -101,7 +101,7 @@ module PactBroker
|
|
101
101
|
.collect(&:to_domain)
|
102
102
|
end
|
103
103
|
|
104
|
-
def create_triggered_webhook trigger_uuid, webhook, pact, verification, trigger_type
|
104
|
+
def create_triggered_webhook trigger_uuid, webhook, pact, verification, trigger_type, event_name
|
105
105
|
db_webhook = Webhook.where(uuid: webhook.uuid).single_record
|
106
106
|
TriggeredWebhook.create(
|
107
107
|
status: TriggeredWebhook::STATUS_NOT_RUN,
|
@@ -112,7 +112,8 @@ module PactBroker
|
|
112
112
|
trigger_uuid: trigger_uuid,
|
113
113
|
trigger_type: trigger_type,
|
114
114
|
consumer: pact.consumer,
|
115
|
-
provider: pact.provider
|
115
|
+
provider: pact.provider,
|
116
|
+
event_name: event_name
|
116
117
|
)
|
117
118
|
end
|
118
119
|
|
@@ -136,7 +136,7 @@ module PactBroker
|
|
136
136
|
trigger_uuid = next_uuid
|
137
137
|
webhooks.each do | webhook |
|
138
138
|
begin
|
139
|
-
triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION)
|
139
|
+
triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION, event_name)
|
140
140
|
logger.info "Scheduling job for webhook with uuid #{webhook.uuid}"
|
141
141
|
logger.debug "Schedule webhook with options #{options}"
|
142
142
|
job_data = { triggered_webhook: triggered_webhook }.deep_merge(options)
|
@@ -8,6 +8,7 @@ require 'pact_broker/webhooks/execution'
|
|
8
8
|
module PactBroker
|
9
9
|
module Webhooks
|
10
10
|
class TriggeredWebhook < Sequel::Model(:triggered_webhooks)
|
11
|
+
plugin :timestamps, update_on_create: true
|
11
12
|
|
12
13
|
TRIGGER_TYPE_RESOURCE_CREATION = 'resource_creation'
|
13
14
|
TRIGGER_TYPE_USER = 'user'
|
@@ -95,9 +96,6 @@ module PactBroker
|
|
95
96
|
end
|
96
97
|
end
|
97
98
|
end
|
98
|
-
|
99
|
-
TriggeredWebhook.plugin :timestamps, update_on_create: true
|
100
|
-
|
101
99
|
end
|
102
100
|
end
|
103
101
|
|
@@ -4,6 +4,7 @@ require 'pact_broker/repositories/helpers'
|
|
4
4
|
module PactBroker
|
5
5
|
module Webhooks
|
6
6
|
class WebhookEvent < Sequel::Model
|
7
|
+
plugin :timestamps, update_on_create: true
|
7
8
|
|
8
9
|
CONTRACT_PUBLISHED = 'contract_published'
|
9
10
|
CONTRACT_CONTENT_CHANGED = 'contract_content_changed'
|
@@ -38,8 +39,6 @@ module PactBroker
|
|
38
39
|
name == VERIFICATION_FAILED
|
39
40
|
end
|
40
41
|
end
|
41
|
-
|
42
|
-
WebhookEvent.plugin :timestamps, update_on_create: true
|
43
42
|
end
|
44
43
|
end
|
45
44
|
|
@@ -7,6 +7,7 @@ module PactBroker
|
|
7
7
|
let(:triggered_webhook) do
|
8
8
|
double('PactBroker::Webhooks::TriggeredWebhook',
|
9
9
|
trigger_type: PactBroker::Webhooks::TriggeredWebhook::TRIGGER_TYPE_RESOURCE_CREATION,
|
10
|
+
event_name: 'some_event',
|
10
11
|
status: status,
|
11
12
|
failure?: failure,
|
12
13
|
retrying?: retrying,
|
@@ -55,7 +56,8 @@ module PactBroker
|
|
55
56
|
status: 'success',
|
56
57
|
triggerType: 'resource_creation',
|
57
58
|
attemptsMade: 1,
|
58
|
-
attemptsRemaining: 2
|
59
|
+
attemptsRemaining: 2,
|
60
|
+
eventName: 'some_event'
|
59
61
|
)
|
60
62
|
end
|
61
63
|
end
|
@@ -3,6 +3,10 @@ require 'pact_broker/api/pact_broker_urls'
|
|
3
3
|
module PactBroker
|
4
4
|
module Api
|
5
5
|
describe PactBrokerUrls do
|
6
|
+
before do
|
7
|
+
allow(PactBrokerUrls).to receive(:logger).and_return(logger)
|
8
|
+
end
|
9
|
+
let(:logger) { double('logger').as_null_object }
|
6
10
|
|
7
11
|
# Regex find all the URL parameter names
|
8
12
|
# \/\{[^\}\s\[\(\.]+\}
|
@@ -117,6 +121,17 @@ module PactBroker
|
|
117
121
|
expect(PactBrokerUrls.decode_webhook_metadata(nil)).to eq({})
|
118
122
|
end
|
119
123
|
end
|
124
|
+
|
125
|
+
context "when the metadata is not valid base64" do
|
126
|
+
it "returns an empty hash" do
|
127
|
+
expect(PactBrokerUrls.decode_webhook_metadata("foo==,")).to eq({})
|
128
|
+
end
|
129
|
+
|
130
|
+
it "logs a warning" do
|
131
|
+
expect(logger).to receive(:warn).with("Exception parsing webhook metadata: foo==,", ArgumentError)
|
132
|
+
PactBrokerUrls.decode_webhook_metadata("foo==,")
|
133
|
+
end
|
134
|
+
end
|
120
135
|
end
|
121
136
|
|
122
137
|
describe "latest_verification_for_pact_url" do
|
@@ -386,7 +386,7 @@ module PactBroker
|
|
386
386
|
.create_verification
|
387
387
|
end
|
388
388
|
|
389
|
-
subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, td.verification, 'publication' }
|
389
|
+
subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, td.verification, 'publication', 'some_event' }
|
390
390
|
|
391
391
|
it "creates a TriggeredWebhook" do
|
392
392
|
expect(subject.webhook_uuid ).to eq td.webhook.uuid
|
@@ -395,6 +395,7 @@ module PactBroker
|
|
395
395
|
expect(subject.verification).to eq td.verification
|
396
396
|
expect(subject.trigger_uuid).to eq '1234'
|
397
397
|
expect(subject.trigger_type).to eq 'publication'
|
398
|
+
expect(subject.event_name).to eq 'some_event'
|
398
399
|
end
|
399
400
|
|
400
401
|
it "sets the webhook" do
|
@@ -418,7 +419,7 @@ module PactBroker
|
|
418
419
|
end
|
419
420
|
|
420
421
|
context "without a verification" do
|
421
|
-
subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, nil, 'publication' }
|
422
|
+
subject { Repository.new.create_triggered_webhook '1234', td.webhook, td.pact, nil, 'publication', 'some_event' }
|
422
423
|
|
423
424
|
it "does not set the verification" do
|
424
425
|
expect(subject.verification).to be nil
|
data/tasks/database.rb
CHANGED
@@ -1,45 +1,8 @@
|
|
1
|
+
require 'pact_broker/db/table_dependency_calculator'
|
2
|
+
|
1
3
|
module PactBroker
|
2
4
|
module Database
|
3
|
-
|
4
|
-
|
5
|
-
# they can be truncated or dropped
|
6
|
-
class TableDependencyCalculator
|
7
|
-
|
8
|
-
def self.call connection
|
9
|
-
new(connection).call
|
10
|
-
end
|
11
|
-
|
12
|
-
def initialize connection
|
13
|
-
@connection = connection
|
14
|
-
end
|
15
|
-
|
16
|
-
def call
|
17
|
-
ordered_table_names = []
|
18
|
-
dependencies = @connection
|
19
|
-
.tables
|
20
|
-
.collect{|it| @connection.foreign_key_list(it)
|
21
|
-
.collect{|fk| {from: it, to: fk[:table]} } }
|
22
|
-
.flatten
|
23
|
-
.uniq
|
24
|
-
table_names = @connection.tables - [:schema_migrations, :schema_info]
|
25
|
-
check(table_names, dependencies, ordered_table_names)
|
26
|
-
ordered_table_names
|
27
|
-
end
|
28
|
-
|
29
|
-
def deps_on table_name, deps
|
30
|
-
deps.select{ | d| d[:to] == table_name }.collect{ |d| d[:from] }
|
31
|
-
end
|
32
|
-
|
33
|
-
def check table_names, deps, ordered_table_names
|
34
|
-
return if table_names.size == 0
|
35
|
-
remaining_dependencies = deps_on(table_names.first, deps) - ordered_table_names
|
36
|
-
if remaining_dependencies.size == 0
|
37
|
-
ordered_table_names << table_names.first
|
38
|
-
check(table_names[1..-1], deps, ordered_table_names)
|
39
|
-
else
|
40
|
-
check((remaining_dependencies + table_names).uniq, deps, ordered_table_names)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
5
|
+
# For backwards compatibility
|
6
|
+
TableDependencyCalculator = PactBroker::DB::TableDependencyCalculator
|
44
7
|
end
|
45
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pact_broker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.62.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bethany Skurrie
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2020-09-
|
13
|
+
date: 2020-09-24 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: httparty
|
@@ -517,6 +517,7 @@ files:
|
|
517
517
|
- db/migrations/20191101_create_head_pact_tags.rb
|
518
518
|
- db/migrations/20200318_add_created_at_to_latest_pact_publications.rb
|
519
519
|
- db/migrations/20200319_add_created_at_to_latest_verifications.rb
|
520
|
+
- db/migrations/20200922_add_event_to_triggered_webhook.rb
|
520
521
|
- db/migrations/migration_helper.rb
|
521
522
|
- db/test/backwards_compatibility/.rspec
|
522
523
|
- db/test/backwards_compatibility/Appraisals
|
@@ -722,6 +723,7 @@ files:
|
|
722
723
|
- lib/pact_broker/db/seed/pact_2.json
|
723
724
|
- lib/pact_broker/db/seed/pact_3.json
|
724
725
|
- lib/pact_broker/db/seed_example_data.rb
|
726
|
+
- lib/pact_broker/db/table_dependency_calculator.rb
|
725
727
|
- lib/pact_broker/db/validate_encoding.rb
|
726
728
|
- lib/pact_broker/db/version.rb
|
727
729
|
- lib/pact_broker/diagnostic/app.rb
|