pact_broker 2.106.0 → 2.107.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/Gemfile +3 -0
- data/db/migrations/20230131_add_cons_ver_id_ndx_to_latest_pp_id_for_cons_ver.rb +8 -4
- data/db/migrations/20230216_add_branch_heads_branch_version_id_index.rb +21 -0
- data/db/migrations/20230428_add_index_for_webhook_executions_pact_publication_id.rb +17 -0
- data/lib/pact_broker/api/contracts/base_contract.rb +22 -7
- data/lib/pact_broker/api/contracts/can_i_deploy_query_schema.rb +34 -0
- data/lib/pact_broker/api/contracts/configuration.rb +2 -0
- data/lib/pact_broker/api/contracts/consumer_version_selector_contract.rb +140 -0
- data/lib/pact_broker/api/contracts/dry_validation_errors_formatter.rb +50 -0
- data/lib/pact_broker/api/contracts/dry_validation_macros.rb +79 -0
- data/lib/pact_broker/api/contracts/dry_validation_methods.rb +71 -0
- data/lib/pact_broker/api/contracts/environment_schema.rb +19 -33
- data/lib/pact_broker/api/contracts/pacticipant_create_schema.rb +4 -17
- data/lib/pact_broker/api/contracts/pacticipant_schema.rb +15 -24
- data/lib/pact_broker/api/contracts/pacts_for_verification_json_query_schema.rb +37 -146
- data/lib/pact_broker/api/contracts/pacts_for_verification_query_string_schema.rb +7 -20
- data/lib/pact_broker/api/contracts/publish_contracts_contract_contract.rb +62 -0
- data/lib/pact_broker/api/contracts/publish_contracts_schema.rb +25 -124
- data/lib/pact_broker/api/contracts/put_pact_params_contract.rb +21 -26
- data/lib/pact_broker/api/contracts/utf_8_validation.rb +2 -0
- data/lib/pact_broker/api/contracts/validation_helpers.rb +71 -0
- data/lib/pact_broker/api/contracts/verification_contract.rb +10 -29
- data/lib/pact_broker/api/contracts/webhook_contract.rb +20 -172
- data/lib/pact_broker/api/contracts/webhook_pacticipant_contract.rb +33 -0
- data/lib/pact_broker/api/contracts/webhook_request_contract.rb +125 -0
- data/lib/pact_broker/api/contracts.rb +3 -0
- data/lib/pact_broker/api/decorators/custom_error_problem_json_decorator.rb +4 -4
- data/lib/pact_broker/api/decorators/dashboard_text_decorator.rb +2 -2
- data/lib/pact_broker/api/decorators/extended_pact_decorator.rb +1 -1
- data/lib/pact_broker/api/decorators/matrix_decorator.rb +4 -4
- data/lib/pact_broker/api/decorators/matrix_text_decorator.rb +1 -1
- data/lib/pact_broker/api/decorators/pact_decorator.rb +1 -1
- data/lib/pact_broker/api/decorators/pacticipant_collection_decorator.rb +2 -2
- data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +2 -1
- data/lib/pact_broker/api/decorators/pacts_for_verification_query_decorator.rb +4 -1
- data/lib/pact_broker/api/decorators/pagination_links.rb +6 -6
- data/lib/pact_broker/api/decorators/runtime_error_problem_json_decorator.rb +4 -4
- data/lib/pact_broker/api/decorators/validation_errors_problem_json_decorator.rb +6 -6
- data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +4 -4
- data/lib/pact_broker/api/decorators/webhook_decorator.rb +2 -3
- data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +5 -12
- data/lib/pact_broker/api/resources/all_webhooks.rb +5 -11
- data/lib/pact_broker/api/resources/base_resource.rb +3 -20
- data/lib/pact_broker/api/resources/branch_version.rb +3 -3
- data/lib/pact_broker/api/resources/can_i_deploy.rb +4 -19
- data/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment.rb +1 -4
- data/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag.rb +0 -2
- data/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag_badge.rb +1 -2
- data/lib/pact_broker/api/resources/currently_deployed_versions_for_environment.rb +2 -2
- data/lib/pact_broker/api/resources/currently_supported_versions_for_environment.rb +2 -2
- data/lib/pact_broker/api/resources/dashboard.rb +3 -3
- data/lib/pact_broker/api/resources/deployed_version.rb +1 -1
- data/lib/pact_broker/api/resources/deployed_versions_for_version_and_environment.rb +2 -2
- data/lib/pact_broker/api/resources/environment.rb +1 -1
- data/lib/pact_broker/api/resources/environments.rb +2 -2
- data/lib/pact_broker/api/resources/error_handling_methods.rb +2 -2
- data/lib/pact_broker/api/resources/integrations.rb +1 -1
- data/lib/pact_broker/api/resources/label.rb +1 -1
- data/lib/pact_broker/api/resources/latest_pact.rb +2 -2
- data/lib/pact_broker/api/resources/latest_pacts.rb +1 -1
- data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +1 -1
- data/lib/pact_broker/api/resources/matrix.rb +2 -2
- data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +1 -1
- data/lib/pact_broker/api/resources/pact.rb +7 -4
- data/lib/pact_broker/api/resources/pact_triggered_webhooks.rb +1 -1
- data/lib/pact_broker/api/resources/pact_versions.rb +1 -1
- data/lib/pact_broker/api/resources/pact_webhooks.rb +7 -14
- data/lib/pact_broker/api/resources/pact_webhooks_status.rb +6 -2
- data/lib/pact_broker/api/resources/pacticipant.rb +1 -1
- data/lib/pact_broker/api/resources/pacticipant_webhooks.rb +7 -5
- data/lib/pact_broker/api/resources/pacticipants.rb +2 -2
- data/lib/pact_broker/api/resources/pacticipants_for_label.rb +1 -1
- data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
- data/lib/pact_broker/api/resources/provider_pacts.rb +1 -1
- data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +4 -13
- data/lib/pact_broker/api/resources/publish_contracts.rb +8 -3
- data/lib/pact_broker/api/resources/released_version.rb +1 -1
- data/lib/pact_broker/api/resources/released_versions_for_version_and_environment.rb +2 -2
- data/lib/pact_broker/api/resources/tag.rb +1 -1
- data/lib/pact_broker/api/resources/tagged_pact_versions.rb +1 -1
- data/lib/pact_broker/api/resources/triggered_webhook_logs.rb +2 -2
- data/lib/pact_broker/api/resources/verification.rb +2 -2
- data/lib/pact_broker/api/resources/verification_triggered_webhooks.rb +1 -1
- data/lib/pact_broker/api/resources/verifications.rb +4 -6
- data/lib/pact_broker/api/resources/version.rb +1 -1
- data/lib/pact_broker/api/resources/versions.rb +1 -1
- data/lib/pact_broker/api/resources/webhook.rb +7 -6
- data/lib/pact_broker/api/resources/webhook_execution.rb +6 -4
- data/lib/pact_broker/api.rb +3 -12
- data/lib/pact_broker/certificates/certificate.rb +1 -0
- data/lib/pact_broker/config/setting.rb +1 -0
- data/lib/pact_broker/contracts/service.rb +1 -0
- data/lib/pact_broker/date_helper.rb +1 -1
- data/lib/pact_broker/db/clean_incremental.rb +1 -1
- data/lib/pact_broker/db/delete_overwritten_data.rb +6 -2
- data/lib/pact_broker/deployments/currently_deployed_version_id.rb +2 -0
- data/lib/pact_broker/deployments/deployed_version.rb +2 -0
- data/lib/pact_broker/deployments/deployed_version_service.rb +5 -1
- data/lib/pact_broker/deployments/environment.rb +2 -0
- data/lib/pact_broker/deployments/environment_service.rb +4 -3
- data/lib/pact_broker/deployments/released_version.rb +2 -0
- data/lib/pact_broker/deployments/released_version_service.rb +4 -0
- data/lib/pact_broker/diagnostic/resources/base_resource.rb +1 -1
- data/lib/pact_broker/doc/views/index/publish-contracts.markdown +5 -5
- data/lib/pact_broker/domain/label.rb +1 -0
- data/lib/pact_broker/domain/tag.rb +2 -0
- data/lib/pact_broker/domain/verification.rb +1 -1
- data/lib/pact_broker/domain/version.rb +4 -1
- data/lib/pact_broker/domain/webhook.rb +1 -1
- data/lib/pact_broker/index/service.rb +1 -1
- data/lib/pact_broker/integrations/integration.rb +1 -0
- data/lib/pact_broker/locale/en.yml +35 -14
- data/lib/pact_broker/matrix/query_ids.rb +4 -4
- data/lib/pact_broker/matrix/resolved_selector.rb +6 -1
- data/lib/pact_broker/matrix/service.rb +1 -0
- data/lib/pact_broker/messages.rb +5 -1
- data/lib/pact_broker/pacticipants/repository.rb +12 -3
- data/lib/pact_broker/pacticipants/service.rb +7 -0
- data/lib/pact_broker/pacts/pact_params.rb +6 -17
- data/lib/pact_broker/pacts/pact_version.rb +1 -0
- data/lib/pact_broker/policies.rb +4 -4
- data/lib/pact_broker/test/http_test_data_builder.rb +46 -2
- data/lib/pact_broker/ui/app.rb +2 -2
- data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +1 -1
- data/lib/pact_broker/verifications/pact_version_provider_tag_successful_verification.rb +1 -0
- data/lib/pact_broker/verifications/service.rb +0 -6
- data/lib/pact_broker/version.rb +1 -1
- data/lib/pact_broker/versions/branch.rb +1 -0
- data/lib/pact_broker/versions/branch_head.rb +2 -1
- data/lib/pact_broker/versions/branch_version.rb +11 -0
- data/lib/pact_broker/webhooks/execution.rb +1 -1
- data/lib/pact_broker/webhooks/repository.rb +1 -1
- data/lib/pact_broker/webhooks/service.rb +3 -25
- data/lib/pact_broker/webhooks/triggered_webhook.rb +1 -0
- data/lib/pact_broker/webhooks/webhook_event.rb +1 -0
- data/lib/pact_broker/webmachine.rb +22 -0
- data/lib/rack/pact_broker/invalid_uri_protection.rb +1 -1
- data/lib/rack/pact_broker/use_when.rb +6 -5
- data/lib/sequel/plugins/age.rb +13 -0
- data/lib/webmachine/application_monkey_patch.rb +5 -0
- data/lib/webmachine/describe_routes.rb +35 -8
- data/lib/webmachine/render_error_monkey_patch.rb +1 -1
- data/pact_broker.gemspec +6 -17
- metadata +56 -72
- data/lib/pact/doc/README.md +0 -5
- data/lib/pact_broker/api/contracts/dry_validation_predicates.rb +0 -36
- data/lib/pact_broker/api/contracts/dry_validation_workarounds.rb +0 -39
- data/lib/pact_broker/api/contracts/pacticipant_name_contract.rb +0 -24
- data/lib/pact_broker/api/contracts/pacticipant_name_validation.rb +0 -30
- data/lib/pact_broker/api/contracts/request_validations.rb +0 -33
- data/lib/pact_broker/api/resources/webhook_resource_methods.rb +0 -17
- data/lib/pact_broker/matrix/can_i_deploy_query_schema.rb +0 -46
@@ -19,7 +19,7 @@ module PactBroker
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def generate_json pacticipants
|
22
|
-
decorator_class(:pacticipant_collection_decorator).new(pacticipants).to_json(decorator_options)
|
22
|
+
decorator_class(:pacticipant_collection_decorator).new(pacticipants).to_json(**decorator_options)
|
23
23
|
end
|
24
24
|
|
25
25
|
def policy_name
|
@@ -24,7 +24,7 @@ module PactBroker
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def to_json
|
27
|
-
decorator_class(:provider_pacts_decorator).new(pacts).to_json(decorator_options(identifier_from_path.merge(title: resource_title)))
|
27
|
+
decorator_class(:provider_pacts_decorator).new(pacts).to_json(**decorator_options(identifier_from_path.merge(title: resource_title)))
|
28
28
|
end
|
29
29
|
|
30
30
|
private
|
@@ -20,7 +20,7 @@ module PactBroker
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def malformed_request?
|
23
|
-
super || ((request.get? || (request.post? && content_type_json?)) &&
|
23
|
+
super || ((request.get? || (request.post? && content_type_json?)) && validation_errors_for_schema?(schema, query))
|
24
24
|
end
|
25
25
|
|
26
26
|
def process_post
|
@@ -58,7 +58,7 @@ module PactBroker
|
|
58
58
|
def to_json
|
59
59
|
log_request
|
60
60
|
decorator_class(:verifiable_pacts_decorator).new(pacts).to_json(
|
61
|
-
decorator_options(
|
61
|
+
**decorator_options(
|
62
62
|
include_pending_status: parsed_query_params.include_pending_status,
|
63
63
|
title: "Pacts to be verified by provider #{provider_name}",
|
64
64
|
deprecated: request.get?
|
@@ -66,10 +66,10 @@ module PactBroker
|
|
66
66
|
)
|
67
67
|
end
|
68
68
|
|
69
|
-
def
|
69
|
+
def schema
|
70
70
|
if request.get?
|
71
71
|
PactBroker::Api::Contracts::PactsForVerificationQueryStringSchema
|
72
|
-
|
72
|
+
elsif request.post?
|
73
73
|
PactBroker::Api::Contracts::PactsForVerificationJSONQuerySchema
|
74
74
|
end
|
75
75
|
end
|
@@ -95,15 +95,6 @@ module PactBroker
|
|
95
95
|
def nested_query
|
96
96
|
@nested_query ||= Rack::Utils.parse_nested_query(request.uri.query)
|
97
97
|
end
|
98
|
-
|
99
|
-
def schema_validation_errors?
|
100
|
-
if (errors = query_schema.call(query)).any?
|
101
|
-
set_json_validation_error_messages(errors)
|
102
|
-
true
|
103
|
-
else
|
104
|
-
false
|
105
|
-
end
|
106
|
-
end
|
107
98
|
end
|
108
99
|
end
|
109
100
|
end
|
@@ -40,11 +40,16 @@ module PactBroker
|
|
40
40
|
:'contracts::contracts'
|
41
41
|
end
|
42
42
|
|
43
|
-
# for
|
43
|
+
# for pactflow
|
44
44
|
def policy_record
|
45
45
|
@policy_record ||= pacticipant_service.find_pacticipant_by_name(parsed_contracts.pacticipant_name)
|
46
46
|
end
|
47
47
|
|
48
|
+
# for pactflow
|
49
|
+
def policy_record_context
|
50
|
+
{ pacticipant: policy_record }
|
51
|
+
end
|
52
|
+
|
48
53
|
private
|
49
54
|
|
50
55
|
def parsed_contracts
|
@@ -81,7 +86,7 @@ module PactBroker
|
|
81
86
|
def publish_contracts
|
82
87
|
handle_webhook_events(consumer_version_branch: parsed_contracts.branch, build_url: parsed_contracts.build_url) do
|
83
88
|
results = contract_service.publish(parsed_contracts, base_url: base_url)
|
84
|
-
response.body = decorator_class(:publish_contracts_results_decorator).new(results).to_json(decorator_options)
|
89
|
+
response.body = decorator_class(:publish_contracts_results_decorator).new(results).to_json(**decorator_options)
|
85
90
|
end
|
86
91
|
end
|
87
92
|
|
@@ -105,7 +110,7 @@ module PactBroker
|
|
105
110
|
|
106
111
|
# TODO put this somewhere shareable
|
107
112
|
def parse_yaml(content)
|
108
|
-
YAML.safe_load(content, [Time, Date, DateTime]) rescue nil
|
113
|
+
YAML.safe_load(content, permitted_classes: [Time, Date, DateTime]) rescue nil
|
109
114
|
end
|
110
115
|
|
111
116
|
def parse_json(content)
|
@@ -31,7 +31,7 @@ module PactBroker
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def to_json
|
34
|
-
decorator_class(:released_version_decorator).new(released_version).to_json(decorator_options)
|
34
|
+
decorator_class(:released_version_decorator).new(released_version).to_json(**decorator_options)
|
35
35
|
end
|
36
36
|
|
37
37
|
def from_merge_patch_json
|
@@ -32,12 +32,12 @@ module PactBroker
|
|
32
32
|
def from_json
|
33
33
|
existing_released_version # make sure we have this before we update the database
|
34
34
|
@released_version = released_version_service.create_or_update(next_released_version_uuid, version, environment)
|
35
|
-
response.body = decorator_class(:released_version_decorator).new(released_version).to_json(decorator_options)
|
35
|
+
response.body = decorator_class(:released_version_decorator).new(released_version).to_json(**decorator_options)
|
36
36
|
true
|
37
37
|
end
|
38
38
|
|
39
39
|
def to_json
|
40
|
-
decorator_class(:released_versions_decorator).new(released_versions).to_json(decorator_options(title: title))
|
40
|
+
decorator_class(:released_versions_decorator).new(released_versions).to_json(**decorator_options(title: title))
|
41
41
|
end
|
42
42
|
|
43
43
|
def policy_name
|
@@ -22,7 +22,7 @@ module PactBroker
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_json
|
25
|
-
decorator_class(:tagged_pact_versions_decorator).new(pacts).to_json(decorator_options(identifier_from_path))
|
25
|
+
decorator_class(:tagged_pact_versions_decorator).new(pacts).to_json(**decorator_options(identifier_from_path))
|
26
26
|
end
|
27
27
|
|
28
28
|
def delete_resource
|
@@ -38,11 +38,11 @@ module PactBroker
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def to_json
|
41
|
-
decorator_for(verification).to_json(decorator_options(pact: pact))
|
41
|
+
decorator_for(verification).to_json(**decorator_options(pact: pact))
|
42
42
|
end
|
43
43
|
|
44
44
|
def to_extended_json
|
45
|
-
extended_decorator_for(verification).to_json(decorator_options(pact: pact))
|
45
|
+
extended_decorator_for(verification).to_json(**decorator_options(pact: pact))
|
46
46
|
end
|
47
47
|
|
48
48
|
def delete_resource
|
@@ -18,7 +18,7 @@ module PactBroker
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def to_json
|
21
|
-
decorator_class(:triggered_webhooks_decorator).new(triggered_webhooks).to_json(decorator_options(resource_title: resource_title))
|
21
|
+
decorator_class(:triggered_webhooks_decorator).new(triggered_webhooks).to_json(**decorator_options(resource_title: resource_title))
|
22
22
|
end
|
23
23
|
|
24
24
|
def policy_name
|
@@ -34,7 +34,7 @@ module PactBroker
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def malformed_request?
|
37
|
-
super || (request.post? &&
|
37
|
+
super || (request.post? && validation_errors_for_schema?)
|
38
38
|
end
|
39
39
|
|
40
40
|
def create_path
|
@@ -45,7 +45,7 @@ module PactBroker
|
|
45
45
|
handle_webhook_events(build_url: verification_params["buildUrl"]) do
|
46
46
|
verified_pacts = pact_service.find_for_verification_publication(pact_params, event_context[:consumer_version_selectors])
|
47
47
|
verification = verification_service.create(next_verification_number, verification_params, verified_pacts, event_context)
|
48
|
-
response.body = decorator_for(verification).to_json(decorator_options)
|
48
|
+
response.body = decorator_for(verification).to_json(**decorator_options)
|
49
49
|
end
|
50
50
|
true
|
51
51
|
end
|
@@ -84,10 +84,8 @@ module PactBroker
|
|
84
84
|
params(symbolize_names: false).merge("wip" => wip?, "pending" => pending?)
|
85
85
|
end
|
86
86
|
|
87
|
-
def
|
88
|
-
|
89
|
-
set_json_validation_error_messages(errors.messages) if !errors.empty?
|
90
|
-
!errors.empty?
|
87
|
+
def schema
|
88
|
+
PactBroker::Api::Contracts::VerificationContract
|
91
89
|
end
|
92
90
|
end
|
93
91
|
end
|
@@ -54,7 +54,7 @@ module PactBroker
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def to_json
|
57
|
-
decorator_class(:version_decorator).new(version).to_json(decorator_options(environments: environments))
|
57
|
+
decorator_class(:version_decorator).new(version).to_json(**decorator_options(environments: environments))
|
58
58
|
end
|
59
59
|
|
60
60
|
def delete_resource
|
@@ -23,7 +23,7 @@ module PactBroker
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def to_json
|
26
|
-
decorator_class(:versions_decorator).new(versions).to_json(decorator_options(identifier_from_path))
|
26
|
+
decorator_class(:versions_decorator).new(versions).to_json(**decorator_options(identifier_from_path))
|
27
27
|
end
|
28
28
|
|
29
29
|
def versions
|
@@ -1,15 +1,12 @@
|
|
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/
|
4
|
+
require "pact_broker/api/contracts/webhook_contract"
|
5
5
|
|
6
6
|
module PactBroker
|
7
7
|
module Api
|
8
8
|
module Resources
|
9
9
|
class Webhook < BaseResource
|
10
|
-
|
11
|
-
include WebhookResourceMethods
|
12
|
-
|
13
10
|
def content_types_accepted
|
14
11
|
[["application/json", :from_json]]
|
15
12
|
end
|
@@ -31,7 +28,7 @@ module PactBroker
|
|
31
28
|
end
|
32
29
|
|
33
30
|
def malformed_request?
|
34
|
-
super || (request.put? &&
|
31
|
+
super || (request.put? && validation_errors_for_schema?(schema, { uuid: uuid }.compact.merge(params)))
|
35
32
|
end
|
36
33
|
|
37
34
|
def from_json
|
@@ -46,7 +43,7 @@ module PactBroker
|
|
46
43
|
end
|
47
44
|
|
48
45
|
def to_json
|
49
|
-
decorator_class(:webhook_decorator).new(webhook).to_json(decorator_options)
|
46
|
+
decorator_class(:webhook_decorator).new(webhook).to_json(**decorator_options)
|
50
47
|
end
|
51
48
|
|
52
49
|
def delete_resource
|
@@ -80,6 +77,10 @@ module PactBroker
|
|
80
77
|
@parsed_webhook ||= decorator_class(:webhook_decorator).new(PactBroker::Domain::Webhook.new).from_json(request_body)
|
81
78
|
end
|
82
79
|
|
80
|
+
def schema
|
81
|
+
api_contract_class(:webhook_contract)
|
82
|
+
end
|
83
|
+
|
83
84
|
def uuid
|
84
85
|
identifier_from_path[:uuid]
|
85
86
|
end
|
@@ -1,7 +1,6 @@
|
|
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"
|
5
4
|
require "pact_broker/constants"
|
6
5
|
require "pact_broker/webhooks/execution_configuration"
|
7
6
|
require "pact_broker/api/resources/webhook_execution_methods"
|
@@ -10,7 +9,6 @@ module PactBroker
|
|
10
9
|
module Api
|
11
10
|
module Resources
|
12
11
|
class WebhookExecution < BaseResource
|
13
|
-
include WebhookResourceMethods
|
14
12
|
include WebhookExecutionMethods
|
15
13
|
|
16
14
|
def content_types_provided
|
@@ -39,7 +37,7 @@ module PactBroker
|
|
39
37
|
if uuid
|
40
38
|
false
|
41
39
|
else
|
42
|
-
|
40
|
+
validation_errors_for_schema?
|
43
41
|
end
|
44
42
|
else
|
45
43
|
false
|
@@ -61,7 +59,7 @@ module PactBroker
|
|
61
59
|
private
|
62
60
|
|
63
61
|
def post_response_body webhook_execution_result
|
64
|
-
decorator_class(:webhook_execution_result_decorator).new(webhook_execution_result).to_json(decorator_options)
|
62
|
+
decorator_class(:webhook_execution_result_decorator).new(webhook_execution_result).to_json(**decorator_options)
|
65
63
|
end
|
66
64
|
|
67
65
|
def webhook
|
@@ -88,6 +86,10 @@ module PactBroker
|
|
88
86
|
def build_unsaved_webhook
|
89
87
|
decorator_class(:webhook_decorator).new(PactBroker::Domain::Webhook.new).from_json(request_body)
|
90
88
|
end
|
89
|
+
|
90
|
+
def schema
|
91
|
+
api_contract_class(:webhook_contract)
|
92
|
+
end
|
91
93
|
end
|
92
94
|
end
|
93
95
|
end
|
data/lib/pact_broker/api.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
require "webmachine
|
2
|
-
require "webmachine/application_monkey_patch"
|
3
|
-
require "webmachine/render_error_monkey_patch"
|
1
|
+
require "pact_broker/webmachine"
|
4
2
|
require "pact_broker/db/models"
|
5
3
|
require "pact_broker/api/resources"
|
6
4
|
require "pact_broker/api/decorators"
|
5
|
+
require "pact_broker/api/contracts"
|
7
6
|
require "pact_broker/application_context"
|
8
7
|
require "pact_broker/feature_toggle"
|
9
8
|
|
@@ -27,7 +26,7 @@ end
|
|
27
26
|
module PactBroker
|
28
27
|
# rubocop: disable Metrics/MethodLength
|
29
28
|
def self.build_api(application_context = PactBroker::ApplicationContext.default_application_context)
|
30
|
-
|
29
|
+
Webmachine.build_rack_api(application_context) do |app|
|
31
30
|
app.routes do
|
32
31
|
add(["trace", :*], Webmachine::Trace::TraceResource) unless ENV["RACK_ENV"] == "production"
|
33
32
|
|
@@ -141,14 +140,6 @@ module PactBroker
|
|
141
140
|
add [], Api::Resources::Index, {resource_name: "index"}
|
142
141
|
end
|
143
142
|
end
|
144
|
-
|
145
|
-
pact_api.application_context = application_context
|
146
|
-
|
147
|
-
pact_api.configure do |config|
|
148
|
-
config.adapter = :RackMapped
|
149
|
-
end
|
150
|
-
|
151
|
-
pact_api.adapter
|
152
143
|
end
|
153
144
|
|
154
145
|
|
@@ -83,7 +83,7 @@ module PactBroker
|
|
83
83
|
end
|
84
84
|
|
85
85
|
def version_ids_to_keep
|
86
|
-
@version_ids_to_keep ||= keep.collect { |selector| PactBroker::Domain::Version.select(:id)
|
86
|
+
@version_ids_to_keep ||= keep.collect { |selector| PactBroker::Domain::Version.for_selector(selector).select(:id) }.reduce(&:union)
|
87
87
|
end
|
88
88
|
|
89
89
|
def current_counts
|
@@ -36,9 +36,13 @@ module PactBroker
|
|
36
36
|
to_keep = deleted_counts.keys.each_with_object({}) do | table_name, new_counts |
|
37
37
|
new_counts[table_name] = kept_counts[table_name] - deleted_counts[table_name]
|
38
38
|
end
|
39
|
-
{
|
39
|
+
deleted_counts.each_with_object({}) do | (key, value), new_hash |
|
40
|
+
new_hash[key] = { toDelete: value, toKeep: to_keep[key] }
|
41
|
+
end
|
40
42
|
else
|
41
|
-
{
|
43
|
+
deleted_counts.each_with_object({}) do | (key, value), new_hash |
|
44
|
+
new_hash[key] = { deleted: value, kept: kept_counts[key] }
|
45
|
+
end
|
42
46
|
end
|
43
47
|
end
|
44
48
|
|
@@ -4,6 +4,8 @@ require "pact_broker/repositories/helpers"
|
|
4
4
|
module PactBroker
|
5
5
|
module Deployments
|
6
6
|
class CurrentlyDeployedVersionId < Sequel::Model
|
7
|
+
set_primary_key :id
|
8
|
+
|
7
9
|
plugin :upsert, identifying_columns: [:pacticipant_id, :environment_id, :target_for_index]
|
8
10
|
|
9
11
|
dataset_module do
|
@@ -4,6 +4,8 @@ require "pact_broker/deployments/currently_deployed_version_id"
|
|
4
4
|
module PactBroker
|
5
5
|
module Deployments
|
6
6
|
class DeployedVersion < Sequel::Model
|
7
|
+
set_primary_key :id
|
8
|
+
|
7
9
|
many_to_one :pacticipant, :class => "PactBroker::Domain::Pacticipant", :key => :pacticipant_id, :primary_key => :id
|
8
10
|
many_to_one :version, :class => "PactBroker::Domain::Version", :key => :version_id, :primary_key => :id
|
9
11
|
many_to_one :environment, :class => "PactBroker::Deployments::Environment", :key => :environment_id, :primary_key => :id
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "pact_broker/deployments/deployed_version"
|
2
2
|
require "pact_broker/repositories/scopes"
|
3
|
+
require "pact_broker/events/publisher"
|
3
4
|
|
4
5
|
module PactBroker
|
5
6
|
module Deployments
|
@@ -7,6 +8,7 @@ module PactBroker
|
|
7
8
|
include PactBroker::Logging
|
8
9
|
extend PactBroker::Repositories::Scopes
|
9
10
|
extend PactBroker::Services
|
11
|
+
extend PactBroker::Events::Publisher
|
10
12
|
|
11
13
|
def self.next_uuid
|
12
14
|
SecureRandom.uuid
|
@@ -22,7 +24,7 @@ module PactBroker
|
|
22
24
|
deployed_version
|
23
25
|
else
|
24
26
|
record_previous_version_undeployed(version.pacticipant, environment, target)
|
25
|
-
DeployedVersion.create(
|
27
|
+
deployed_version = DeployedVersion.create(
|
26
28
|
uuid: uuid,
|
27
29
|
version: version,
|
28
30
|
pacticipant_id: version.pacticipant_id,
|
@@ -30,6 +32,8 @@ module PactBroker
|
|
30
32
|
target: target,
|
31
33
|
auto_created: auto_created
|
32
34
|
)
|
35
|
+
broadcast(:deployed_version_created, { deployed_version: deployed_version })
|
36
|
+
deployed_version
|
33
37
|
end
|
34
38
|
end
|
35
39
|
|
@@ -5,6 +5,8 @@ require "sequel/plugins/serialization"
|
|
5
5
|
module PactBroker
|
6
6
|
module Deployments
|
7
7
|
class Environment < Sequel::Model
|
8
|
+
set_primary_key :id
|
9
|
+
|
8
10
|
OPEN_STRUCT_TO_JSON = lambda { | open_struct | Sequel.object_to_json(open_struct.collect(&:to_h)) }
|
9
11
|
JSON_TO_OPEN_STRUCT = lambda { | json | Sequel.parse_json(json).collect{ | hash| OpenStruct.new(hash) } }
|
10
12
|
plugin :upsert, identifying_columns: [:uuid]
|
@@ -9,7 +9,6 @@ module PactBroker
|
|
9
9
|
module EnvironmentService
|
10
10
|
using PactBroker::StringRefinements
|
11
11
|
extend PactBroker::Repositories::Scopes
|
12
|
-
|
13
12
|
extend self
|
14
13
|
|
15
14
|
def self.included(base)
|
@@ -36,8 +35,6 @@ module PactBroker
|
|
36
35
|
environment.upsert
|
37
36
|
end
|
38
37
|
|
39
|
-
alias_method :update, :replace # For PF
|
40
|
-
|
41
38
|
def find_all
|
42
39
|
scope_for(PactBroker::Deployments::Environment).order(Sequel.function(:lower, :display_name)).all
|
43
40
|
end
|
@@ -57,6 +54,10 @@ module PactBroker
|
|
57
54
|
def find_for_pacticipant(_pacticipant)
|
58
55
|
find_all
|
59
56
|
end
|
57
|
+
|
58
|
+
def scope_for(scope)
|
59
|
+
PactBroker.policy_scope!(scope)
|
60
|
+
end
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -4,6 +4,8 @@ require "pact_broker/repositories/helpers"
|
|
4
4
|
module PactBroker
|
5
5
|
module Deployments
|
6
6
|
class ReleasedVersion < Sequel::Model
|
7
|
+
set_primary_key :id
|
8
|
+
|
7
9
|
many_to_one :pacticipant, :class => "PactBroker::Domain::Pacticipant", :key => :pacticipant_id, :primary_key => :id
|
8
10
|
many_to_one :version, :class => "PactBroker::Domain::Version", :key => :version_id, :primary_key => :id
|
9
11
|
many_to_one :environment, :class => "PactBroker::Deployments::Environment", :key => :environment_id, :primary_key => :id
|
@@ -1,10 +1,12 @@
|
|
1
1
|
require "pact_broker/deployments/released_version"
|
2
2
|
require "pact_broker/repositories/scopes"
|
3
|
+
require "pact_broker/events/publisher"
|
3
4
|
|
4
5
|
module PactBroker
|
5
6
|
module Deployments
|
6
7
|
class ReleasedVersionService
|
7
8
|
extend PactBroker::Repositories::Scopes
|
9
|
+
extend PactBroker::Events::Publisher
|
8
10
|
|
9
11
|
def self.next_uuid
|
10
12
|
SecureRandom.uuid
|
@@ -25,6 +27,8 @@ module PactBroker
|
|
25
27
|
# error when marking an existing row as supported again IRL.
|
26
28
|
ReleasedVersion.where(id: released_version.id).set_currently_supported
|
27
29
|
released_version.refresh
|
30
|
+
broadcast(:released_version_created, { released_version: released_version })
|
31
|
+
released_version
|
28
32
|
end
|
29
33
|
|
30
34
|
def self.find_currently_supported_versions_for_environment(environment, pacticipant_name: nil, pacticipant_version_number: nil)
|
@@ -33,7 +33,7 @@ This endpoint is designed to be used by a command line tool, and hence, the resp
|
|
33
33
|
### Success
|
34
34
|
|
35
35
|
* `notices`
|
36
|
-
* `
|
36
|
+
* `type`: one of `debug`, `info`, `warning`,`prompt`,`success`, `error`, `danger`
|
37
37
|
* `text`: the text of the notice. This is designed to be displayed in the output of a CLI.
|
38
38
|
|
39
39
|
The `_links` section will contain links to all the resources created by the publication. The relations are:
|
@@ -105,19 +105,19 @@ If there is a conflict with an existing published pact and `allow_dangerous_cont
|
|
105
105
|
{
|
106
106
|
"notices": [
|
107
107
|
{
|
108
|
-
"
|
108
|
+
"type": "debug",
|
109
109
|
"text": "Created Foo version dc5eb529230038a4673b8c971395bd2922d8b240 with branch main and tags main"
|
110
110
|
},
|
111
111
|
{
|
112
|
-
"
|
112
|
+
"type": "info",
|
113
113
|
"text": "Pact published for Foo version dc5eb529230038a4673b8c971395bd2922d8b240 and provider Bar."
|
114
114
|
},
|
115
115
|
{
|
116
|
-
"
|
116
|
+
"type": "debug",
|
117
117
|
"text": " Events detected: contract_published, contract_content_changed (first time any pact published for this consumer with consumer version tagged main)"
|
118
118
|
},
|
119
119
|
{
|
120
|
-
"
|
120
|
+
"type": "debug",
|
121
121
|
"text": " Webhook \"foo webhook\" triggered for event contract_content_changed.\n See logs at http://example.org/triggered-webhooks/1234/logs\""
|
122
122
|
}
|
123
123
|
],
|
@@ -3,6 +3,7 @@ require "pact_broker/db"
|
|
3
3
|
module PactBroker
|
4
4
|
module Domain
|
5
5
|
class Label < Sequel::Model
|
6
|
+
set_primary_key([:name, :pacticipant_id])
|
6
7
|
unrestrict_primary_key
|
7
8
|
|
8
9
|
associate(:many_to_one, :pacticipant, :class => "PactBroker::Domain::Pacticipant", :key => :pacticipant_id, :primary_key => :id)
|