pact_broker 2.34.0 → 2.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.dockerignore +2 -0
- data/.github/FUNDING.yml +4 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +34 -0
- data/DEVELOPER_DOCUMENTATION.md +24 -1
- data/DEVELOPER_SETUP.md +40 -20
- data/Dockerfile +22 -0
- data/db/migrations/000028_create_all_pact_publications.rb +0 -1
- data/db/migrations/20180311_optimise_head_matrix.rb +0 -1
- data/lib/pact/doc/doc_file.rb +0 -1
- data/lib/pact_broker/api/contracts/webhook_contract.rb +1 -1
- data/lib/pact_broker/api/decorators/decorator_context.rb +5 -5
- data/lib/pact_broker/api/decorators/pact_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/pact_pacticipant_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/tag_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +0 -1
- data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +8 -5
- data/lib/pact_broker/api/decorators/webhook_request_template_decorator.rb +1 -4
- data/lib/pact_broker/api/decorators/webhooks_decorator.rb +1 -2
- data/lib/pact_broker/api/resources/base_resource.rb +0 -1
- data/lib/pact_broker/api/resources/error_handler.rb +14 -7
- data/lib/pact_broker/api/resources/pact.rb +4 -9
- data/lib/pact_broker/api/resources/pact_webhooks.rb +0 -1
- data/lib/pact_broker/api/resources/verifications.rb +4 -8
- data/lib/pact_broker/api/resources/webhook.rb +4 -8
- data/lib/pact_broker/api/resources/webhook_execution.rb +36 -17
- data/lib/pact_broker/api/resources/webhook_execution_methods.rb +13 -0
- data/lib/pact_broker/api/resources/webhook_resource_methods.rb +8 -15
- data/lib/pact_broker/api/resources/webhooks.rb +3 -12
- data/lib/pact_broker/api.rb +1 -1
- data/lib/pact_broker/app.rb +2 -0
- data/lib/pact_broker/domain/webhook.rb +29 -18
- data/lib/pact_broker/hash_refinements.rb +13 -0
- data/lib/pact_broker/locale/en.yml +16 -0
- data/lib/pact_broker/logging.rb +1 -1
- data/lib/pact_broker/pacts/diff.rb +0 -1
- data/lib/pact_broker/pacts/pact_version.rb +13 -7
- data/lib/pact_broker/pacts/repository.rb +4 -6
- data/lib/pact_broker/pacts/service.rb +3 -4
- data/lib/pact_broker/repositories/helpers.rb +1 -1
- data/lib/pact_broker/string_refinements.rb +13 -0
- data/lib/pact_broker/tags/repository.rb +0 -1
- data/lib/pact_broker/ui/views/index/_css_and_js.haml +1 -0
- data/lib/pact_broker/ui/views/index/show-with-tags.haml +8 -2
- data/lib/pact_broker/ui/views/matrix/show.haml +12 -2
- data/lib/pact_broker/verifications/repository.rb +0 -1
- data/lib/pact_broker/verifications/service.rb +7 -5
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/parse_semantic_version.rb +0 -1
- data/lib/pact_broker/webhooks/execution.rb +0 -1
- data/lib/pact_broker/webhooks/execution_configuration.rb +45 -0
- data/lib/pact_broker/webhooks/job.rb +5 -8
- data/lib/pact_broker/webhooks/pact_and_verification_parameters.rb +39 -12
- data/lib/pact_broker/webhooks/redact_logs.rb +21 -4
- data/lib/pact_broker/webhooks/render.rb +11 -2
- data/lib/pact_broker/webhooks/repository.rb +11 -5
- data/lib/pact_broker/webhooks/service.rb +21 -27
- data/lib/pact_broker/webhooks/triggered_webhook.rb +0 -1
- data/lib/pact_broker/webhooks/webhook_request_logger.rb +13 -0
- data/lib/pact_broker/webhooks/webhook_request_template.rb +32 -18
- data/lib/rack/pact_broker/add_vary_header.rb +39 -0
- data/lib/rack/pact_broker/convert_file_extension_to_accept_header.rb +2 -0
- data/lib/webmachine/rack_adapter_monkey_patch.rb +0 -1
- data/public/javascripts/clipboard.js +73 -0
- data/public/javascripts/matrix.js +0 -2
- data/public/stylesheets/index.css +19 -0
- data/script/prod/clean-up.sql +11 -0
- data/script/query.rb +0 -1
- data/script/seed-matrix.rb +0 -1
- data/script/seed.rb +0 -1
- data/spec/features/delete_version_spec.rb +0 -1
- data/spec/features/execute_unsaved_webhook_spec.rb +56 -0
- data/spec/features/execute_webhook_spec.rb +2 -5
- data/spec/features/get_version_spec.rb +0 -1
- data/spec/lib/pact_broker/api/contracts/put_pact_params_contract_spec.rb +0 -1
- data/spec/lib/pact_broker/api/contracts/verification_contract_spec.rb +0 -1
- data/spec/lib/pact_broker/api/decorators/relationships_csv_decorator_spec.rb +0 -2
- data/spec/lib/pact_broker/api/decorators/verification_decorator_spec.rb +0 -1
- data/spec/lib/pact_broker/api/decorators/webhook_execution_result_decorator_spec.rb +26 -9
- data/spec/lib/pact_broker/api/decorators/webhook_request_template_decorator_spec.rb +3 -1
- data/spec/lib/pact_broker/api/decorators/webhooks_decorator_spec.rb +3 -2
- data/spec/lib/pact_broker/api/resources/badge_spec.rb +0 -2
- data/spec/lib/pact_broker/api/resources/dashboard_spec.rb +0 -1
- data/spec/lib/pact_broker/api/resources/error_handler_spec.rb +3 -0
- data/spec/lib/pact_broker/api/resources/group_spec.rb +0 -1
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +0 -2
- data/spec/lib/pact_broker/api/resources/pacticipant_spec.rb +0 -1
- data/spec/lib/pact_broker/api/resources/tag_spec.rb +0 -2
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +9 -7
- data/spec/lib/pact_broker/api/resources/webhook_execution_spec.rb +13 -15
- data/spec/lib/pact_broker/api/resources/webhooks_spec.rb +0 -1
- data/spec/lib/pact_broker/certificates/service_spec.rb +11 -5
- data/spec/lib/pact_broker/domain/group_spec.rb +0 -1
- data/spec/lib/pact_broker/domain/webhook_spec.rb +11 -4
- data/spec/lib/pact_broker/feature_toggle_spec.rb +0 -1
- data/spec/lib/pact_broker/groups/service_spec.rb +0 -1
- data/spec/lib/pact_broker/hash_refinements_spec.rb +15 -0
- data/spec/lib/pact_broker/matrix/repository_spec.rb +0 -2
- data/spec/lib/pact_broker/pacticipants/find_potential_duplicate_pacticipant_names_spec.rb +0 -1
- data/spec/lib/pact_broker/pacts/pact_version_spec.rb +16 -0
- data/spec/lib/pact_broker/pacts/repository_spec.rb +11 -0
- data/spec/lib/pact_broker/pacts/service_spec.rb +12 -5
- data/spec/lib/pact_broker/relationships/groupify_spec.rb +0 -2
- data/spec/lib/pact_broker/tags/repository_spec.rb +0 -1
- data/spec/lib/pact_broker/verifications/service_spec.rb +10 -3
- data/spec/lib/pact_broker/versions/repository_spec.rb +0 -1
- data/spec/lib/pact_broker/webhooks/execution_configuration_spec.rb +18 -0
- data/spec/lib/pact_broker/webhooks/job_spec.rb +21 -24
- data/spec/lib/pact_broker/webhooks/redact_logs_spec.rb +16 -5
- data/spec/lib/pact_broker/webhooks/repository_spec.rb +16 -1
- data/spec/lib/pact_broker/webhooks/service_spec.rb +23 -64
- data/spec/lib/pact_broker/webhooks/webhook_request_template_spec.rb +108 -24
- data/spec/migrations/23_pact_versions_spec.rb +3 -1
- data/spec/spec_helper.rb +4 -2
- data/spec/support/database_cleaner.rb +0 -1
- metadata +19 -5
- data/spec/support/jobs.rb +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 16a87ec2e8bd7d3047768e040433544194b306fa
|
|
4
|
+
data.tar.gz: 7dda1535ad3341c18acd174f2459cae29be8e287
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cf0fa7165f17a13b045d068d78cbe0aebe5cf860055d271a00dc369d56eff478c3946c8a22451f323eb762bee75069c6359c208c6178dfd82c0561a5c03444bd
|
|
7
|
+
data.tar.gz: 27f0ffd8fceaa7f907fe3e256c4e0f63947ffc4343cb01982e4d1eb5fe2d63b4c0097d602653026cc8deec4349b49e6c7bea9776fa45fc7e67bf80388df94f0b
|
data/.dockerignore
ADDED
data/.github/FUNDING.yml
ADDED
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
<a name="v2.35.0"></a>
|
|
2
|
+
### v2.35.0 (2019-08-08)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#### Features
|
|
6
|
+
|
|
7
|
+
* **webhooks**
|
|
8
|
+
* do not redact a password with a parameter in it ([47c602ef](/../../commit/47c602ef))
|
|
9
|
+
* update parameter text ([7fa518cb](/../../commit/7fa518cb))
|
|
10
|
+
* do not redact header if it contains a parameter ([5787e0d1](/../../commit/5787e0d1))
|
|
11
|
+
* support template parameters in header values, username and password ([a800ac2e](/../../commit/a800ac2e))
|
|
12
|
+
* simplify request logger format ([c52ade2f](/../../commit/c52ade2f))
|
|
13
|
+
* add the logs and success flag to the execution result ([96769a88](/../../commit/96769a88))
|
|
14
|
+
* allow testing of an unsaved webhook ([a436e42d](/../../commit/a436e42d))
|
|
15
|
+
* gracefully handle scenario where triggered webhook has been deleted while webhook was being executed ([052055d4](/../../commit/052055d4))
|
|
16
|
+
* use consumer/provider names in webhook title ([2b5d2498](/../../commit/2b5d2498))
|
|
17
|
+
|
|
18
|
+
* add copy to clipboard for version numbers (#283) ([c10a6f28](/../../commit/c10a6f28))
|
|
19
|
+
* update redact logs ([51aa13c0](/../../commit/51aa13c0))
|
|
20
|
+
* use hardcoded error message when error class has a nil message ([03a3b63c](/../../commit/03a3b63c))
|
|
21
|
+
* ensure clean up script handles pact versions for left over verifications ([116f8eaa](/../../commit/116f8eaa))
|
|
22
|
+
* added clean up sql script ([388b441e](/../../commit/388b441e))
|
|
23
|
+
* add Vary header to avoid browser returning the wrong cached content type for a resource ([6d30baa2](/../../commit/6d30baa2))
|
|
24
|
+
* change logging level from error to info for JSON parsing errors ([cc144062](/../../commit/cc144062))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
#### Bug Fixes
|
|
28
|
+
|
|
29
|
+
* inefficient SQL loading latest verification for pact version ([301d9a58](/../../commit/301d9a58))
|
|
30
|
+
|
|
31
|
+
* **publish pacts**
|
|
32
|
+
* handle race condition when creating pact version ([de0d3b7f](/../../commit/de0d3b7f))
|
|
33
|
+
|
|
34
|
+
|
|
1
35
|
<a name="v2.34.0"></a>
|
|
2
36
|
### v2.34.0 (2019-06-14)
|
|
3
37
|
|
data/DEVELOPER_DOCUMENTATION.md
CHANGED
|
@@ -8,7 +8,9 @@
|
|
|
8
8
|
* HTTP Resources - [lib/pact_broker/api/resources](lib/pact_broker/api/resources) These handle the HTTP requests.
|
|
9
9
|
* Decorators - [lib/pact_broker/api/decorators](lib/pact_broker/api/decorators) These render the response bodies.
|
|
10
10
|
* Contracts - [lib/pact_broker/api/contracts](lib/pact_broker/api/contracts) These validate incoming API requests.
|
|
11
|
-
* Domain - Domain classes were intially created in [lib/pact_broker/domain](lib/pact_broker/domain) but are now put in their own modules. The ones left here just haven't been migrated yet.
|
|
11
|
+
* Domain - Domain classes were intially created in [lib/pact_broker/domain](lib/pact_broker/domain) but are now put in their own modules. The ones left here just haven't been migrated yet. The module name is the plural of the domain class name. eg `lib/pact_broker/widgets/widget.rb`.
|
|
12
|
+
* Services and Repositories - in the module with the name of their domain concept. eg `lib/pact_broker/widgets/service.rb` and `lib/pact_broker/widgets/repository.rb`
|
|
13
|
+
* Standalone "function as class" classes go into the module they relate to. This pattern is used when there is some significant stateless logic that we want to
|
|
12
14
|
* Database migrations - [db/migrations](db/migrations)
|
|
13
15
|
|
|
14
16
|
* Tests - `spec`
|
|
@@ -95,3 +97,24 @@ Domain classes are found in `lib/pact_broker/domain`. Many of these classes are
|
|
|
95
97
|
|
|
96
98
|
* The supported database types are Postgres (recommended), MySQL (sigh) and Sqlite (just for testing, not recommended for production). Check the travis.yml file for the supported database versions.
|
|
97
99
|
* Any migration that uses the "order" column has to be defined using the Sequel DSL rather than pure SQL, because the word "order" is a key word, and it has to be escaped correctly and differently on each database (Postgres, MySQL, Sqlite).
|
|
100
|
+
|
|
101
|
+
## Adding a resource
|
|
102
|
+
|
|
103
|
+
* In `spec/features` add a new high level spec that executes the endpoint you're going to write. Don't worry if you're not sure exactly what it's going to look like yet - you can come back and change it as you go. Have a look at the other specs in the directory for the type of assertions that should be made. Basic rule of thumb is to check the http status code, and do a light touch of assertions on the body.
|
|
104
|
+
* Create a new directory for the classes that relate to your new resource. eg For a "Foo" resource, create `lib/pact_broker/foos`
|
|
105
|
+
* Create a new migration in `db/migrations` that creates the underlying database table.
|
|
106
|
+
* Create a new database model for the resource that extends from Sequel::Model. eg `lib/pact_broker/foos/foo.rb`
|
|
107
|
+
* Create a decorator in `spec/lib/pact_broker/api/decorators/` that will map to and from the representation that will be used in the HTTP request and response.
|
|
108
|
+
* Write a spec for the decorator.
|
|
109
|
+
* You may need to create a contract to validate the request. This is kind of broken while I upgrade to the latest dry-validation library. See Beth for more details.
|
|
110
|
+
* Add the HTTP resource in `lib/pact_broker/api/resources/`. It should extend from `BaseResource`.
|
|
111
|
+
* Write a spec for the resource, stubbing out the behaviour you expect from your service.
|
|
112
|
+
* Add the route to `lib/pact_broker/api.rb`
|
|
113
|
+
* Create a service that has the methods that you need for the resource. eg. `lib/pact_broker/foos/service.rb`
|
|
114
|
+
* Add the new service to `lib/pact_broker/services.rb`
|
|
115
|
+
* Write a spec for the service, stubbing out the behaviour you expect from your repository.
|
|
116
|
+
* Create a repository eg. `lib/pact_broker/foos/repository.rb`.
|
|
117
|
+
* Add the new repository to `lib/pact_broker/repositories.rb`.
|
|
118
|
+
* Write a spec for the repository.
|
|
119
|
+
* Go back and make the original feature spec pass.
|
|
120
|
+
* Profit.
|
data/DEVELOPER_SETUP.md
CHANGED
|
@@ -1,35 +1,55 @@
|
|
|
1
1
|
# Developer setup
|
|
2
2
|
|
|
3
|
+
## Preparation
|
|
4
|
+
|
|
5
|
+
### With virtual battery
|
|
6
|
+
|
|
7
|
+
* Build an initial local image with Docker
|
|
8
|
+
```sh
|
|
9
|
+
docker build --rm -t pact_broker:dev .
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
* Spin up a container with mounted volume and open an interactive shell session
|
|
13
|
+
```sh
|
|
14
|
+
docker run --rm -v $(PWD):/app -w /app -it pact_broker:dev bash
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### With native install
|
|
18
|
+
|
|
3
19
|
* You will need to install Ruby 2.5, and preferably a ruby version manager. I recommend using [chruby][chruby] and [ruby-install][ruby-install].
|
|
4
20
|
* Install bundler (the Ruby gem dependency manager) `gem install bundler`
|
|
5
21
|
* Check out the pact_broker repository and cd into it.
|
|
6
22
|
* Run `bundle install`. If you have not got mysql or postgres installed locally, comment out the `mysql2` and `pg` development dependency lines in `pact_broker.gemspec`, as these are only really required on Travis.
|
|
7
|
-
* Run `bundle exec rake pact_broker:dev:setup`. This will create an example application that you can run locally, that uses the local source code.
|
|
8
|
-
* To run the example:
|
|
9
23
|
|
|
10
|
-
|
|
11
|
-
bundle install
|
|
12
|
-
bundle exec rackup
|
|
24
|
+
## Running a local application
|
|
13
25
|
|
|
26
|
+
* Run `bundle exec rake pact_broker:dev:setup`. This will create an example application that you can run locally, that uses the local source code.
|
|
27
|
+
* To run the example:
|
|
28
|
+
```sh
|
|
29
|
+
cd dev
|
|
30
|
+
bundle install
|
|
31
|
+
bundle exec rackup
|
|
32
|
+
```
|
|
14
33
|
* The application will be available on `http://localhost:9292`
|
|
15
34
|
|
|
16
35
|
## Running the tests
|
|
17
36
|
|
|
18
|
-
To run everything (specs, pact verifications, vulnerability scan...):
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
To run a smaller subset of the tests:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
To run the "quick tests" (skip the lengthy migration specs)
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
To run a single spec:
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
* To run everything (specs, pact verifications, vulnerability scan...):
|
|
38
|
+
```sh
|
|
39
|
+
bundle exec rake
|
|
40
|
+
```
|
|
41
|
+
* To run a smaller subset of the tests:
|
|
42
|
+
```sh
|
|
43
|
+
bundle exec rake spec
|
|
44
|
+
```
|
|
45
|
+
* To run the "quick tests" (skip the lengthy migration specs)
|
|
46
|
+
```sh
|
|
47
|
+
bundle exec rake spec:quick
|
|
48
|
+
```
|
|
49
|
+
* To run a single spec:
|
|
50
|
+
```sh
|
|
51
|
+
bundle exec rspec path_to_your_spec.rb
|
|
52
|
+
```
|
|
33
53
|
|
|
34
54
|
[chruby]: https://github.com/postmodern/chruby
|
|
35
55
|
[ruby-install]: https://github.com/postmodern/ruby-install
|
data/Dockerfile
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
FROM ruby:2.5.3-alpine
|
|
2
|
+
|
|
3
|
+
RUN apk update \
|
|
4
|
+
&& apk --no-cache add \
|
|
5
|
+
"build-base>=0.5" \
|
|
6
|
+
"bash>=4.4" \
|
|
7
|
+
"ca-certificates>=20190108" \
|
|
8
|
+
"git>=2.20" \
|
|
9
|
+
"postgresql-dev>=11.3" \
|
|
10
|
+
"sqlite-dev>=3.28" \
|
|
11
|
+
"sqlite>=3.28" \
|
|
12
|
+
"tzdata>=2019" \
|
|
13
|
+
&& rm -rf /var/cache/apk/*
|
|
14
|
+
|
|
15
|
+
WORKDIR /app
|
|
16
|
+
|
|
17
|
+
COPY . ./
|
|
18
|
+
|
|
19
|
+
RUN gem install bundler -v '~>2.0.0' \
|
|
20
|
+
&& bundle install --jobs 3 --retry 3
|
|
21
|
+
|
|
22
|
+
CMD []
|
|
@@ -33,7 +33,6 @@ Sequel.migration do
|
|
|
33
33
|
and app.revision_number = lr.latest_revision_number"
|
|
34
34
|
)
|
|
35
35
|
|
|
36
|
-
|
|
37
36
|
# updated in 20180519_recreate_views.rb
|
|
38
37
|
# This view tells us the latest consumer version with a pact for a consumer/provider pair
|
|
39
38
|
create_or_replace_view(:latest_pact_consumer_version_orders,
|
data/lib/pact/doc/doc_file.rb
CHANGED
|
@@ -142,7 +142,7 @@ module PactBroker
|
|
|
142
142
|
end
|
|
143
143
|
|
|
144
144
|
def parse_uri(uri_string, placeholder = 'placeholder')
|
|
145
|
-
URI(
|
|
145
|
+
URI(PactBroker::Webhooks::Render.render_with_placeholder(uri_string, placeholder))
|
|
146
146
|
end
|
|
147
147
|
end
|
|
148
148
|
|
|
@@ -11,17 +11,17 @@ module PactBroker
|
|
|
11
11
|
self[:base_url] = base_url
|
|
12
12
|
@resource_url = resource_url
|
|
13
13
|
self[:resource_url] = resource_url
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
if options[:resource_title]
|
|
15
|
+
@resource_title = options[:resource_title]
|
|
16
|
+
self[:resource_title] = resource_title
|
|
17
|
+
end
|
|
16
18
|
merge!(options)
|
|
17
19
|
end
|
|
18
20
|
|
|
19
21
|
def to_s
|
|
20
22
|
"DecoratorContext #{super}"
|
|
21
23
|
end
|
|
22
|
-
|
|
23
24
|
end
|
|
24
|
-
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
|
-
end
|
|
27
|
+
end
|
|
@@ -35,7 +35,6 @@ module PactBroker
|
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
|
38
|
-
|
|
39
38
|
class HTTPResponseDecorator < BaseDecorator
|
|
40
39
|
property :status, :getter => lambda { |_| code.to_i }
|
|
41
40
|
property :headers, exec_context: :decorator
|
|
@@ -61,17 +60,21 @@ module PactBroker
|
|
|
61
60
|
property :request, :extend => HTTPRequestDecorator
|
|
62
61
|
property :response, :extend => HTTPResponseDecorator, if: lambda { |context| context[:options][:user_options][:show_response] }
|
|
63
62
|
property :response_hidden_message, as: :message, exec_context: :decorator, if: lambda { |context| !context[:options][:user_options][:show_response] }
|
|
63
|
+
property :logs
|
|
64
|
+
property :success?, as: :success
|
|
64
65
|
|
|
65
66
|
link :webhook do | options |
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
if options.fetch(:webhook).uuid
|
|
68
|
+
{
|
|
69
|
+
href: webhook_url(options.fetch(:webhook).uuid, options.fetch(:base_url))
|
|
70
|
+
}
|
|
71
|
+
end
|
|
69
72
|
end
|
|
70
73
|
|
|
71
74
|
link :'try-again' do | options |
|
|
72
75
|
{
|
|
73
76
|
title: 'Execute the webhook again',
|
|
74
|
-
href:
|
|
77
|
+
href: options.fetch(:resource_url)
|
|
75
78
|
}
|
|
76
79
|
end
|
|
77
80
|
|
|
@@ -7,15 +7,12 @@ module PactBroker
|
|
|
7
7
|
|
|
8
8
|
property :method
|
|
9
9
|
property :url
|
|
10
|
-
property :headers, getter: lambda { | _ |
|
|
10
|
+
property :headers, getter: lambda { | _ | self.redacted_headers.empty? ? nil : self.redacted_headers }
|
|
11
11
|
property :body
|
|
12
12
|
property :username
|
|
13
13
|
property :password, getter: lambda { | _ | display_password }
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
def redacted_headers
|
|
17
|
-
represented.headers
|
|
18
|
-
end
|
|
19
16
|
end
|
|
20
17
|
end
|
|
21
18
|
end
|
|
@@ -6,7 +6,6 @@ module PactBroker
|
|
|
6
6
|
module Decorators
|
|
7
7
|
class WebhooksDecorator < BaseDecorator
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
link :self do | context |
|
|
11
10
|
{
|
|
12
11
|
title: context[:resource_title],
|
|
@@ -24,7 +23,7 @@ module PactBroker
|
|
|
24
23
|
links :'pb:webhooks' do | context |
|
|
25
24
|
represented.entries.collect do | webhook |
|
|
26
25
|
{
|
|
27
|
-
title:
|
|
26
|
+
title: webhook.scope_description,
|
|
28
27
|
name: webhook.display_description,
|
|
29
28
|
href: webhook_url(webhook.uuid, context[:base_url])
|
|
30
29
|
}
|
|
@@ -9,20 +9,27 @@ module PactBroker
|
|
|
9
9
|
include PactBroker::Logging
|
|
10
10
|
|
|
11
11
|
def self.call e, request, response
|
|
12
|
-
error_reference =
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
error_reference = generate_error_reference
|
|
13
|
+
if reportable?(e)
|
|
14
|
+
log_error(e, "Error reference #{error_reference}")
|
|
15
|
+
report(e, error_reference, request)
|
|
16
|
+
else
|
|
17
|
+
logger.info "Error reference #{error_reference} - #{e.class} #{e.message}\n#{e.backtrace.join("\n")}"
|
|
18
|
+
end
|
|
15
19
|
response.body = response_body_hash(e, error_reference).to_json
|
|
16
|
-
report(e, error_reference, request) if reportable?(e)
|
|
17
20
|
end
|
|
18
21
|
|
|
19
|
-
def self.
|
|
20
|
-
|
|
22
|
+
def self.generate_error_reference
|
|
23
|
+
SecureRandom.urlsafe_base64.gsub(/[^a-z]/i, '')[0,10]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.reportable?(e)
|
|
27
|
+
!e.is_a?(PactBroker::Error) && !e.is_a?(JSON::GeneratorError)
|
|
21
28
|
end
|
|
22
29
|
|
|
23
30
|
def self.display_message(e, error_reference)
|
|
24
31
|
if PactBroker.configuration.show_backtrace_in_error_response?
|
|
25
|
-
e.message
|
|
32
|
+
e.message || obfuscated_error_message(error_reference)
|
|
26
33
|
else
|
|
27
34
|
reportable?(e) ? obfuscated_error_message(error_reference) : e.message
|
|
28
35
|
end
|
|
@@ -5,6 +5,8 @@ require 'pact_broker/api/decorators/pact_decorator'
|
|
|
5
5
|
require 'pact_broker/json'
|
|
6
6
|
require 'pact_broker/pacts/pact_params'
|
|
7
7
|
require 'pact_broker/api/contracts/put_pact_params_contract'
|
|
8
|
+
require 'pact_broker/webhooks/execution_configuration'
|
|
9
|
+
require 'pact_broker/api/resources/webhook_execution_methods'
|
|
8
10
|
|
|
9
11
|
module Webmachine
|
|
10
12
|
class Request
|
|
@@ -15,13 +17,11 @@ module Webmachine
|
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
module PactBroker
|
|
18
|
-
|
|
19
20
|
module Api
|
|
20
21
|
module Resources
|
|
21
|
-
|
|
22
22
|
class Pact < BaseResource
|
|
23
|
-
|
|
24
23
|
include PacticipantResourceMethods
|
|
24
|
+
include WebhookExecutionMethods
|
|
25
25
|
|
|
26
26
|
def content_types_provided
|
|
27
27
|
[["application/hal+json", :to_json],
|
|
@@ -122,12 +122,7 @@ module PactBroker
|
|
|
122
122
|
def webhook_options
|
|
123
123
|
{
|
|
124
124
|
database_connector: database_connector,
|
|
125
|
-
|
|
126
|
-
show_response: PactBroker.configuration.show_webhook_response?
|
|
127
|
-
},
|
|
128
|
-
webhook_context: {
|
|
129
|
-
base_url: base_url
|
|
130
|
-
}
|
|
125
|
+
webhook_execution_configuration: webhook_execution_configuration
|
|
131
126
|
}
|
|
132
127
|
end
|
|
133
128
|
end
|
|
@@ -3,12 +3,13 @@ require 'pact_broker/configuration'
|
|
|
3
3
|
require 'pact_broker/domain/verification'
|
|
4
4
|
require 'pact_broker/api/contracts/verification_contract'
|
|
5
5
|
require 'pact_broker/api/decorators/verification_decorator'
|
|
6
|
+
require 'pact_broker/api/resources/webhook_execution_methods'
|
|
6
7
|
|
|
7
8
|
module PactBroker
|
|
8
9
|
module Api
|
|
9
10
|
module Resources
|
|
10
|
-
|
|
11
11
|
class Verifications < BaseResource
|
|
12
|
+
include WebhookExecutionMethods
|
|
12
13
|
|
|
13
14
|
def content_types_accepted
|
|
14
15
|
[["application/json", :from_json]]
|
|
@@ -70,7 +71,6 @@ module PactBroker
|
|
|
70
71
|
request.post?
|
|
71
72
|
end
|
|
72
73
|
|
|
73
|
-
|
|
74
74
|
def metadata
|
|
75
75
|
PactBrokerUrls.parse_webhook_metadata(identifier_from_path[:metadata])
|
|
76
76
|
end
|
|
@@ -78,12 +78,8 @@ module PactBroker
|
|
|
78
78
|
def webhook_options
|
|
79
79
|
{
|
|
80
80
|
database_connector: database_connector,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
},
|
|
84
|
-
webhook_context: metadata.merge(
|
|
85
|
-
base_url: base_url
|
|
86
|
-
)
|
|
81
|
+
webhook_execution_configuration: webhook_execution_configuration
|
|
82
|
+
.with_webhook_context(metadata)
|
|
87
83
|
}
|
|
88
84
|
end
|
|
89
85
|
end
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
require 'pact_broker/api/resources/base_resource'
|
|
2
2
|
require 'pact_broker/services'
|
|
3
3
|
require 'pact_broker/api/decorators/webhook_decorator'
|
|
4
|
+
require 'pact_broker/api/resources/webhook_resource_methods'
|
|
4
5
|
|
|
5
6
|
module PactBroker
|
|
6
7
|
module Api
|
|
7
8
|
module Resources
|
|
8
|
-
|
|
9
9
|
class Webhook < BaseResource
|
|
10
10
|
|
|
11
|
+
include WebhookResourceMethods
|
|
12
|
+
|
|
11
13
|
def content_types_accepted
|
|
12
14
|
[["application/json", :from_json]]
|
|
13
15
|
end
|
|
@@ -26,7 +28,7 @@ module PactBroker
|
|
|
26
28
|
|
|
27
29
|
def malformed_request?
|
|
28
30
|
if request.put?
|
|
29
|
-
return invalid_json? ||
|
|
31
|
+
return invalid_json? || webhook_validation_errors?(new_webhook)
|
|
30
32
|
end
|
|
31
33
|
false
|
|
32
34
|
end
|
|
@@ -51,12 +53,6 @@ module PactBroker
|
|
|
51
53
|
|
|
52
54
|
private
|
|
53
55
|
|
|
54
|
-
def validation_errors? webhook
|
|
55
|
-
errors = webhook_service.errors(new_webhook)
|
|
56
|
-
set_json_validation_error_messages(errors.messages) if !errors.empty?
|
|
57
|
-
!errors.empty?
|
|
58
|
-
end
|
|
59
|
-
|
|
60
56
|
def webhook
|
|
61
57
|
@webhook ||= webhook_service.find_by_uuid uuid
|
|
62
58
|
end
|
|
@@ -1,21 +1,34 @@
|
|
|
1
1
|
require 'pact_broker/api/resources/base_resource'
|
|
2
2
|
require 'pact_broker/services'
|
|
3
3
|
require 'pact_broker/api/decorators/webhook_execution_result_decorator'
|
|
4
|
+
require 'pact_broker/api/resources/webhook_resource_methods'
|
|
4
5
|
require 'pact_broker/constants'
|
|
6
|
+
require 'pact_broker/webhooks/execution_configuration'
|
|
7
|
+
require 'pact_broker/api/resources/webhook_execution_methods'
|
|
5
8
|
|
|
6
9
|
module PactBroker
|
|
7
10
|
module Api
|
|
8
11
|
module Resources
|
|
9
12
|
class WebhookExecution < BaseResource
|
|
13
|
+
include WebhookResourceMethods
|
|
14
|
+
include WebhookExecutionMethods
|
|
15
|
+
|
|
16
|
+
def content_types_accepted
|
|
17
|
+
[["application/json"]]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def content_types_provided
|
|
21
|
+
[["application/hal+json"]]
|
|
22
|
+
end
|
|
10
23
|
|
|
11
24
|
def allowed_methods
|
|
12
25
|
["POST", "OPTIONS"]
|
|
13
26
|
end
|
|
14
27
|
|
|
15
28
|
def process_post
|
|
16
|
-
webhook_execution_result = webhook_service.test_execution(webhook,
|
|
29
|
+
webhook_execution_result = webhook_service.test_execution(webhook, webhook_execution_configuration)
|
|
17
30
|
response.headers['Content-Type'] = 'application/hal+json;charset=utf-8'
|
|
18
|
-
response.body = post_response_body
|
|
31
|
+
response.body = post_response_body(webhook_execution_result)
|
|
19
32
|
true
|
|
20
33
|
end
|
|
21
34
|
|
|
@@ -23,6 +36,14 @@ module PactBroker
|
|
|
23
36
|
webhook
|
|
24
37
|
end
|
|
25
38
|
|
|
39
|
+
def malformed_request?
|
|
40
|
+
if uuid
|
|
41
|
+
false
|
|
42
|
+
else
|
|
43
|
+
webhook_validation_errors?(webhook)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
26
47
|
private
|
|
27
48
|
|
|
28
49
|
def post_response_body webhook_execution_result
|
|
@@ -30,7 +51,13 @@ module PactBroker
|
|
|
30
51
|
end
|
|
31
52
|
|
|
32
53
|
def webhook
|
|
33
|
-
@webhook ||=
|
|
54
|
+
@webhook ||= begin
|
|
55
|
+
if uuid
|
|
56
|
+
webhook_service.find_by_uuid uuid
|
|
57
|
+
else
|
|
58
|
+
build_unsaved_webhook
|
|
59
|
+
end
|
|
60
|
+
end
|
|
34
61
|
end
|
|
35
62
|
|
|
36
63
|
def uuid
|
|
@@ -38,22 +65,14 @@ module PactBroker
|
|
|
38
65
|
end
|
|
39
66
|
|
|
40
67
|
def user_options
|
|
41
|
-
|
|
42
|
-
base_url: base_url,
|
|
68
|
+
decorator_context(
|
|
43
69
|
webhook: webhook,
|
|
44
70
|
show_response: PactBroker.configuration.show_webhook_response?
|
|
45
|
-
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
def
|
|
49
|
-
|
|
50
|
-
logging_options: {
|
|
51
|
-
show_response: PactBroker.configuration.show_webhook_response?
|
|
52
|
-
},
|
|
53
|
-
webhook_context: {
|
|
54
|
-
base_url: base_url
|
|
55
|
-
}
|
|
56
|
-
}
|
|
71
|
+
)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def build_unsaved_webhook
|
|
75
|
+
Decorators::WebhookDecorator.new(PactBroker::Domain::Webhook.new).from_json(request_body)
|
|
57
76
|
end
|
|
58
77
|
end
|
|
59
78
|
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module PactBroker
|
|
2
|
+
module Api
|
|
3
|
+
module Resources
|
|
4
|
+
module WebhookExecutionMethods
|
|
5
|
+
def webhook_execution_configuration
|
|
6
|
+
PactBroker::Webhooks::ExecutionConfiguration.new
|
|
7
|
+
.with_show_response(PactBroker.configuration.show_webhook_response?)
|
|
8
|
+
.with_webhook_context(base_url: base_url)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|