pact_broker 2.105.0 → 2.107.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +57 -1
  3. data/Gemfile +3 -0
  4. data/README.md +1 -1
  5. data/db/migrations/20221130_add_provider_version_id_index_to_verifications.rb +28 -0
  6. data/db/migrations/20221208_add_index_to_pact_version_provider_tag_successful_verifications.rb +21 -0
  7. data/db/migrations/20221215_add_prov_ver_id_ndx_to_latest_verifi_id_for_pact_ver_and_prov_ver.rb +21 -0
  8. data/db/migrations/20230131_add_cons_ver_id_ndx_to_latest_pp_id_for_cons_ver.rb +21 -0
  9. data/db/migrations/20230216_add_branch_heads_branch_version_id_index.rb +21 -0
  10. data/db/migrations/20230428_add_index_for_webhook_executions_pact_publication_id.rb +17 -0
  11. data/docs/CONFIGURATION.md +1 -1
  12. data/docs/api/PAGINATION.md +43 -0
  13. data/lib/pact_broker/api/contracts/base_contract.rb +22 -7
  14. data/lib/pact_broker/api/contracts/can_i_deploy_query_schema.rb +34 -0
  15. data/lib/pact_broker/api/contracts/configuration.rb +2 -0
  16. data/lib/pact_broker/api/contracts/consumer_version_selector_contract.rb +140 -0
  17. data/lib/pact_broker/api/contracts/dry_validation_errors_formatter.rb +50 -0
  18. data/lib/pact_broker/api/contracts/dry_validation_macros.rb +79 -0
  19. data/lib/pact_broker/api/contracts/dry_validation_methods.rb +71 -0
  20. data/lib/pact_broker/api/contracts/environment_schema.rb +19 -33
  21. data/lib/pact_broker/api/contracts/pacticipant_create_schema.rb +4 -17
  22. data/lib/pact_broker/api/contracts/pacticipant_schema.rb +15 -24
  23. data/lib/pact_broker/api/contracts/pacts_for_verification_json_query_schema.rb +37 -146
  24. data/lib/pact_broker/api/contracts/pacts_for_verification_query_string_schema.rb +7 -20
  25. data/lib/pact_broker/api/contracts/publish_contracts_contract_contract.rb +62 -0
  26. data/lib/pact_broker/api/contracts/publish_contracts_schema.rb +25 -112
  27. data/lib/pact_broker/api/contracts/put_pact_params_contract.rb +21 -26
  28. data/lib/pact_broker/api/contracts/utf_8_validation.rb +19 -0
  29. data/lib/pact_broker/api/contracts/validation_helpers.rb +71 -0
  30. data/lib/pact_broker/api/contracts/verification_contract.rb +10 -29
  31. data/lib/pact_broker/api/contracts/webhook_contract.rb +20 -170
  32. data/lib/pact_broker/api/contracts/webhook_pacticipant_contract.rb +33 -0
  33. data/lib/pact_broker/api/contracts/webhook_request_contract.rb +125 -0
  34. data/lib/pact_broker/api/contracts.rb +3 -0
  35. data/lib/pact_broker/api/decorators/custom_error_problem_json_decorator.rb +36 -0
  36. data/lib/pact_broker/api/decorators/dashboard_text_decorator.rb +2 -2
  37. data/lib/pact_broker/api/decorators/extended_pact_decorator.rb +1 -1
  38. data/lib/pact_broker/api/decorators/matrix_decorator.rb +4 -4
  39. data/lib/pact_broker/api/decorators/matrix_text_decorator.rb +1 -1
  40. data/lib/pact_broker/api/decorators/pact_decorator.rb +1 -1
  41. data/lib/pact_broker/api/decorators/pacticipant_collection_decorator.rb +5 -2
  42. data/lib/pact_broker/api/decorators/pacticipant_decorator.rb +2 -1
  43. data/lib/pact_broker/api/decorators/pacts_for_verification_query_decorator.rb +4 -1
  44. data/lib/pact_broker/api/decorators/pagination_links.rb +11 -0
  45. data/lib/pact_broker/api/decorators/runtime_error_problem_json_decorator.rb +34 -0
  46. data/lib/pact_broker/api/decorators/validation_errors_problem_json_decorator.rb +66 -0
  47. data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +4 -4
  48. data/lib/pact_broker/api/decorators/webhook_decorator.rb +2 -3
  49. data/lib/pact_broker/api/decorators/webhook_execution_result_decorator.rb +5 -12
  50. data/lib/pact_broker/api/resources/all_webhooks.rb +5 -11
  51. data/lib/pact_broker/api/resources/badge_methods.rb +1 -1
  52. data/lib/pact_broker/api/resources/base_resource.rb +31 -68
  53. data/lib/pact_broker/api/resources/branch_version.rb +3 -3
  54. data/lib/pact_broker/api/resources/can_i_deploy.rb +4 -19
  55. data/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_branch_to_environment.rb +1 -4
  56. data/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag.rb +0 -2
  57. data/lib/pact_broker/api/resources/can_i_deploy_pacticipant_version_by_tag_to_tag_badge.rb +1 -2
  58. data/lib/pact_broker/api/resources/currently_deployed_versions_for_environment.rb +2 -2
  59. data/lib/pact_broker/api/resources/currently_supported_versions_for_environment.rb +2 -2
  60. data/lib/pact_broker/api/resources/dashboard.rb +3 -3
  61. data/lib/pact_broker/api/resources/deployed_version.rb +1 -1
  62. data/lib/pact_broker/api/resources/deployed_versions_for_version_and_environment.rb +2 -2
  63. data/lib/pact_broker/api/resources/environment.rb +1 -1
  64. data/lib/pact_broker/api/resources/environments.rb +2 -2
  65. data/lib/pact_broker/api/resources/error_handling_methods.rb +57 -0
  66. data/lib/pact_broker/api/resources/error_response_generator.rb +70 -0
  67. data/lib/pact_broker/api/resources/integrations.rb +1 -1
  68. data/lib/pact_broker/api/resources/label.rb +1 -1
  69. data/lib/pact_broker/api/resources/latest_pact.rb +2 -2
  70. data/lib/pact_broker/api/resources/latest_pacts.rb +1 -1
  71. data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +2 -2
  72. data/lib/pact_broker/api/resources/matrix.rb +2 -2
  73. data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +1 -1
  74. data/lib/pact_broker/api/resources/pact.rb +7 -4
  75. data/lib/pact_broker/api/resources/pact_triggered_webhooks.rb +1 -1
  76. data/lib/pact_broker/api/resources/pact_version.rb +1 -1
  77. data/lib/pact_broker/api/resources/pact_versions.rb +1 -1
  78. data/lib/pact_broker/api/resources/pact_webhooks.rb +7 -14
  79. data/lib/pact_broker/api/resources/pact_webhooks_status.rb +6 -2
  80. data/lib/pact_broker/api/resources/pacticipant.rb +1 -1
  81. data/lib/pact_broker/api/resources/pacticipant_webhooks.rb +7 -5
  82. data/lib/pact_broker/api/resources/pacticipants.rb +6 -3
  83. data/lib/pact_broker/api/resources/pacticipants_for_label.rb +1 -1
  84. data/lib/pact_broker/api/resources/pagination_methods.rb +8 -4
  85. data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
  86. data/lib/pact_broker/api/resources/provider_pacts.rb +1 -1
  87. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +4 -13
  88. data/lib/pact_broker/api/resources/publish_contracts.rb +8 -3
  89. data/lib/pact_broker/api/resources/released_version.rb +1 -1
  90. data/lib/pact_broker/api/resources/released_versions_for_version_and_environment.rb +2 -2
  91. data/lib/pact_broker/api/resources/tag.rb +1 -1
  92. data/lib/pact_broker/api/resources/tagged_pact_versions.rb +1 -1
  93. data/lib/pact_broker/api/resources/triggered_webhook_logs.rb +2 -2
  94. data/lib/pact_broker/api/resources/verification.rb +2 -2
  95. data/lib/pact_broker/api/resources/verification_triggered_webhooks.rb +1 -1
  96. data/lib/pact_broker/api/resources/verifications.rb +4 -6
  97. data/lib/pact_broker/api/resources/version.rb +1 -1
  98. data/lib/pact_broker/api/resources/versions.rb +6 -13
  99. data/lib/pact_broker/api/resources/webhook.rb +7 -6
  100. data/lib/pact_broker/api/resources/webhook_execution.rb +6 -4
  101. data/lib/pact_broker/api.rb +3 -13
  102. data/lib/pact_broker/app.rb +0 -2
  103. data/lib/pact_broker/application_context.rb +4 -4
  104. data/lib/pact_broker/certificates/certificate.rb +1 -0
  105. data/lib/pact_broker/config/setting.rb +1 -0
  106. data/lib/pact_broker/contracts/service.rb +1 -0
  107. data/lib/pact_broker/date_helper.rb +1 -1
  108. data/lib/pact_broker/db/clean_incremental.rb +67 -59
  109. data/lib/pact_broker/db/delete_overwritten_data.rb +6 -2
  110. data/lib/pact_broker/deployments/currently_deployed_version_id.rb +2 -0
  111. data/lib/pact_broker/deployments/deployed_version.rb +2 -0
  112. data/lib/pact_broker/deployments/deployed_version_service.rb +5 -1
  113. data/lib/pact_broker/deployments/environment.rb +2 -0
  114. data/lib/pact_broker/deployments/environment_service.rb +4 -3
  115. data/lib/pact_broker/deployments/released_version.rb +2 -0
  116. data/lib/pact_broker/deployments/released_version_service.rb +4 -0
  117. data/lib/pact_broker/diagnostic/resources/base_resource.rb +1 -1
  118. data/lib/pact_broker/doc/views/index/publish-contracts.markdown +5 -5
  119. data/lib/pact_broker/domain/label.rb +1 -0
  120. data/lib/pact_broker/domain/tag.rb +2 -0
  121. data/lib/pact_broker/domain/verification.rb +1 -1
  122. data/lib/pact_broker/domain/version.rb +4 -1
  123. data/lib/pact_broker/domain/webhook.rb +1 -1
  124. data/lib/pact_broker/index/service.rb +2 -2
  125. data/lib/pact_broker/integrations/integration.rb +1 -0
  126. data/lib/pact_broker/locale/en.yml +36 -14
  127. data/lib/pact_broker/matrix/query_ids.rb +4 -4
  128. data/lib/pact_broker/matrix/resolved_selector.rb +6 -1
  129. data/lib/pact_broker/matrix/service.rb +1 -0
  130. data/lib/pact_broker/messages.rb +5 -1
  131. data/lib/pact_broker/pacticipants/repository.rb +16 -14
  132. data/lib/pact_broker/pacticipants/service.rb +11 -8
  133. data/lib/pact_broker/pacts/pact_params.rb +6 -17
  134. data/lib/pact_broker/pacts/pact_version.rb +1 -0
  135. data/lib/pact_broker/pacts/selected_pact.rb +4 -0
  136. data/lib/pact_broker/policies.rb +4 -4
  137. data/lib/pact_broker/repositories/helpers.rb +11 -0
  138. data/lib/pact_broker/repositories/page.rb +24 -0
  139. data/lib/pact_broker/string_refinements.rb +4 -0
  140. data/lib/pact_broker/tasks/clean_task.rb +7 -3
  141. data/lib/pact_broker/test/http_test_data_builder.rb +46 -2
  142. data/lib/pact_broker/ui/app.rb +2 -2
  143. data/lib/pact_broker/ui/views/matrix/show.haml +1 -1
  144. data/lib/pact_broker/verifications/latest_verification_id_for_pact_version_and_provider_version.rb +1 -1
  145. data/lib/pact_broker/verifications/pact_version_provider_tag_successful_verification.rb +1 -0
  146. data/lib/pact_broker/verifications/repository.rb +14 -11
  147. data/lib/pact_broker/verifications/service.rb +0 -6
  148. data/lib/pact_broker/version.rb +1 -1
  149. data/lib/pact_broker/versions/branch.rb +1 -0
  150. data/lib/pact_broker/versions/branch_head.rb +2 -1
  151. data/lib/pact_broker/versions/branch_version.rb +11 -0
  152. data/lib/pact_broker/versions/repository.rb +12 -0
  153. data/lib/pact_broker/versions/service.rb +4 -0
  154. data/lib/pact_broker/webhooks/execution.rb +1 -1
  155. data/lib/pact_broker/webhooks/repository.rb +1 -1
  156. data/lib/pact_broker/webhooks/service.rb +3 -25
  157. data/lib/pact_broker/webhooks/triggered_webhook.rb +1 -0
  158. data/lib/pact_broker/webhooks/webhook_event.rb +1 -0
  159. data/lib/pact_broker/webmachine.rb +22 -0
  160. data/lib/rack/pact_broker/invalid_uri_protection.rb +1 -1
  161. data/lib/rack/pact_broker/request_target.rb +1 -1
  162. data/lib/rack/pact_broker/use_when.rb +6 -5
  163. data/lib/sequel/plugins/age.rb +13 -0
  164. data/lib/webmachine/application_monkey_patch.rb +15 -0
  165. data/lib/webmachine/describe_routes.rb +35 -8
  166. data/lib/webmachine/render_error_monkey_patch.rb +70 -0
  167. data/pact_broker.gemspec +7 -18
  168. metadata +72 -76
  169. data/lib/pact/doc/README.md +0 -5
  170. data/lib/pact_broker/api/contracts/dry_validation_predicates.rb +0 -36
  171. data/lib/pact_broker/api/contracts/dry_validation_workarounds.rb +0 -39
  172. data/lib/pact_broker/api/contracts/pacticipant_name_contract.rb +0 -24
  173. data/lib/pact_broker/api/contracts/pacticipant_name_validation.rb +0 -30
  174. data/lib/pact_broker/api/contracts/request_validations.rb +0 -33
  175. data/lib/pact_broker/api/resources/error_response_body_generator.rb +0 -41
  176. data/lib/pact_broker/api/resources/webhook_resource_methods.rb +0 -17
  177. data/lib/pact_broker/matrix/can_i_deploy_query_schema.rb +0 -46
  178. data/lib/rack/pact_broker/convert_404_to_hal.rb +0 -20
@@ -19,7 +19,7 @@ module PactBroker
19
19
  end
20
20
 
21
21
  def to_json
22
- decorator_class(:pact_versions_decorator).new(pacts).to_json(decorator_options(identifier_from_path))
22
+ decorator_class(:pact_versions_decorator).new(pacts).to_json(**decorator_options(identifier_from_path))
23
23
  end
24
24
 
25
25
  def pacts
@@ -25,18 +25,7 @@ module PactBroker
25
25
  end
26
26
 
27
27
  def malformed_request?
28
- super || (request.post? && validation_errors?(webhook))
29
- end
30
-
31
- def validation_errors? webhook
32
- errors = webhook_service.errors(webhook)
33
-
34
- unless errors.empty?
35
- response.headers["Content-Type"] = "application/hal+json;charset=utf-8"
36
- response.body = { errors: errors.messages }.to_json
37
- end
38
-
39
- !errors.empty?
28
+ super || (request.post? && validation_errors_for_schema?)
40
29
  end
41
30
 
42
31
  def create_path
@@ -49,11 +38,11 @@ module PactBroker
49
38
 
50
39
  def from_json
51
40
  saved_webhook = webhook_service.create next_uuid, webhook, consumer, provider
52
- response.body = decorator_class(:webhook_decorator).new(saved_webhook).to_json(decorator_options)
41
+ response.body = decorator_class(:webhook_decorator).new(saved_webhook).to_json(**decorator_options)
53
42
  end
54
43
 
55
44
  def to_json
56
- decorator_class(:webhooks_decorator).new(webhooks).to_json(decorator_options(resource_title: "Pact webhooks"))
45
+ decorator_class(:webhooks_decorator).new(webhooks).to_json(**decorator_options(resource_title: "Pact webhooks"))
57
46
  end
58
47
 
59
48
  def policy_name
@@ -62,6 +51,10 @@ module PactBroker
62
51
 
63
52
  private
64
53
 
54
+ def schema
55
+ api_contract_class(:webhook_contract)
56
+ end
57
+
65
58
  def webhooks
66
59
  @webhooks ||= webhook_service.find_by_consumer_and_provider consumer, provider
67
60
  end
@@ -19,11 +19,15 @@ module PactBroker
19
19
  end
20
20
 
21
21
  def to_json
22
- decorator_for(latest_triggered_webhooks).to_json(decorator_options(identifier_from_path))
22
+ decorator_for(latest_triggered_webhooks).to_json(**decorator_options(identifier_from_path))
23
23
  end
24
24
 
25
25
  def policy_name
26
- :'webhooks::webhooks'
26
+ :'pacts::pact'
27
+ end
28
+
29
+ def policy_record
30
+ pact
27
31
  end
28
32
 
29
33
  private
@@ -71,7 +71,7 @@ module PactBroker
71
71
  end
72
72
 
73
73
  def to_json
74
- decorator_class(:pacticipant_decorator).new(pacticipant).to_json(decorator_options)
74
+ decorator_class(:pacticipant_decorator).new(pacticipant).to_json(**decorator_options)
75
75
  end
76
76
 
77
77
  def parsed_pacticipant(pacticipant)
@@ -2,13 +2,11 @@ require "pact_broker/api/resources/base_resource"
2
2
  require "pact_broker/api/decorators/webhook_decorator"
3
3
  require "pact_broker/api/decorators/webhooks_decorator"
4
4
  require "pact_broker/api/contracts/webhook_contract"
5
- require "pact_broker/api/resources/webhook_resource_methods"
6
5
 
7
6
  module PactBroker
8
7
  module Api
9
8
  module Resources
10
9
  class PacticipantWebhooks < BaseResource
11
- include WebhookResourceMethods
12
10
 
13
11
  def allowed_methods
14
12
  ["POST", "GET", "OPTIONS"]
@@ -27,7 +25,7 @@ module PactBroker
27
25
  end
28
26
 
29
27
  def malformed_request?
30
- super || (request.post? && webhook_validation_errors?(webhook))
28
+ super || (request.post? && validation_errors_for_schema?)
31
29
  end
32
30
 
33
31
  def create_path
@@ -40,11 +38,11 @@ module PactBroker
40
38
 
41
39
  def from_json
42
40
  saved_webhook = webhook_service.create next_uuid, webhook, consumer, provider
43
- response.body = decorator_class(:webhook_decorator).new(saved_webhook).to_json(decorator_options)
41
+ response.body = decorator_class(:webhook_decorator).new(saved_webhook).to_json(**decorator_options)
44
42
  end
45
43
 
46
44
  def to_json
47
- decorator_class(:webhooks_decorator).new(webhooks).to_json(decorator_options(resource_title: "Webhooks"))
45
+ decorator_class(:webhooks_decorator).new(webhooks).to_json(**decorator_options(resource_title: "Webhooks"))
48
46
  end
49
47
 
50
48
  def policy_name
@@ -57,6 +55,10 @@ module PactBroker
57
55
 
58
56
  private
59
57
 
58
+ def schema
59
+ api_contract_class(:webhook_contract)
60
+ end
61
+
60
62
  def webhooks
61
63
  webhook_service.find_by_consumer_and_provider(consumer, provider)
62
64
  end
@@ -3,12 +3,15 @@ require "pact_broker/api/decorators/pacticipant_decorator"
3
3
  require "pact_broker/domain/pacticipant"
4
4
  require "pact_broker/hash_refinements"
5
5
  require "pact_broker/api/contracts/pacticipant_create_schema"
6
+ require "pact_broker/api/resources/pagination_methods"
6
7
 
7
8
  module PactBroker
8
9
  module Api
9
10
  module Resources
10
11
  class Pacticipants < BaseResource
11
12
  using PactBroker::HashRefinements
13
+ include PaginationMethods
14
+
12
15
 
13
16
  def content_types_provided
14
17
  [["application/hal+json", :to_json]]
@@ -36,7 +39,7 @@ module PactBroker
36
39
 
37
40
  def from_json
38
41
  created_model = pacticipant_service.create(parsed_pacticipant.to_h)
39
- response.body = decorator_for(created_model).to_json(decorator_options)
42
+ response.body = decorator_for(created_model).to_json(**decorator_options)
40
43
  end
41
44
 
42
45
  def create_path
@@ -44,11 +47,11 @@ module PactBroker
44
47
  end
45
48
 
46
49
  def to_json
47
- generate_json(pacticipant_service.find_all_pacticipants)
50
+ generate_json(pacticipant_service.find_all_pacticipants(pagination_options))
48
51
  end
49
52
 
50
53
  def generate_json pacticipants
51
- decorator_class(:deprecated_pacticipant_collection_decorator).new(pacticipants).to_json(decorator_options)
54
+ decorator_class(:deprecated_pacticipant_collection_decorator).new(pacticipants).to_json(**decorator_options)
52
55
  end
53
56
 
54
57
  def decorator_for model
@@ -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
@@ -3,10 +3,14 @@ module PactBroker
3
3
  module Resources
4
4
  module PaginationMethods
5
5
  def pagination_options
6
- {
7
- page_number: request.query["pageNumber"]&.to_i,
8
- page_size: request.query["pageSize"]&.to_i
9
- }.compact
6
+ if request.query["pageNumber"] || request.query["pageSize"]
7
+ {
8
+ page_number: request.query["pageNumber"]&.to_i || 1,
9
+ page_size: request.query["pageSize"]&.to_i || 100
10
+ }
11
+ else
12
+ {}
13
+ end
10
14
  end
11
15
  end
12
16
  end
@@ -21,7 +21,7 @@ module PactBroker
21
21
  end
22
22
 
23
23
  def to_json
24
- decorator_class(:pact_decorator).new(pact).to_json(decorator_options)
24
+ decorator_class(:pact_decorator).new(pact).to_json(**decorator_options)
25
25
  end
26
26
 
27
27
  def pact
@@ -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?)) && schema_validation_errors?)
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 query_schema
69
+ def schema
70
70
  if request.get?
71
71
  PactBroker::Api::Contracts::PactsForVerificationQueryStringSchema
72
- else
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 Pactflow
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
@@ -36,7 +36,7 @@ module PactBroker
36
36
  end
37
37
 
38
38
  def to_json
39
- decorator_class(:tag_decorator).new(tag).to_json(decorator_options)
39
+ decorator_class(:tag_decorator).new(tag).to_json(**decorator_options)
40
40
  end
41
41
 
42
42
  def tag
@@ -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
@@ -28,11 +28,11 @@ module PactBroker
28
28
  end
29
29
 
30
30
  def policy_name
31
- :'webhooks::webhook'
31
+ :'webhooks::triggered_webhook'
32
32
  end
33
33
 
34
34
  def policy_record
35
- triggered_webhook&.webhook
35
+ triggered_webhook
36
36
  end
37
37
 
38
38
  private
@@ -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? && any_validation_errors?)
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 any_validation_errors?
88
- errors = verification_service.errors(params)
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
@@ -1,11 +1,15 @@
1
1
  require "pact_broker/api/resources/base_resource"
2
2
  require "pact_broker/configuration"
3
3
  require "pact_broker/api/decorators/versions_decorator"
4
+ require "pact_broker/api/resources/pagination_methods"
5
+
4
6
 
5
7
  module PactBroker
6
8
  module Api
7
9
  module Resources
8
10
  class Versions < BaseResource
11
+ include PaginationMethods
12
+
9
13
  def content_types_provided
10
14
  [["application/hal+json", :to_json]]
11
15
  end
@@ -19,27 +23,16 @@ module PactBroker
19
23
  end
20
24
 
21
25
  def to_json
22
- 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))
23
27
  end
24
28
 
25
29
  def versions
26
- @versions ||= pacticipant_service.find_all_pacticipant_versions_in_reverse_order(pacticipant_name, pagination_options)
30
+ @versions ||= version_service.find_all_pacticipant_versions_in_reverse_order(pacticipant_name, pagination_options)
27
31
  end
28
32
 
29
33
  def policy_name
30
34
  :'versions::versions'
31
35
  end
32
-
33
- def pagination_options
34
- if request.query["pageNumber"] || request.query["pageSize"]
35
- {
36
- page_number: request.query["pageNumber"]&.to_i || 1,
37
- page_size: request.query["pageSize"]&.to_i || 100
38
- }
39
- else
40
- nil
41
- end
42
- end
43
36
  end
44
37
  end
45
38
  end
@@ -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/resources/webhook_resource_methods"
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? && webhook_validation_errors?(parsed_webhook, uuid))
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
- webhook_validation_errors?(webhook)
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
@@ -1,7 +1,8 @@
1
- require "webmachine/adapters/rack_mapped"
1
+ require "pact_broker/webmachine"
2
2
  require "pact_broker/db/models"
3
3
  require "pact_broker/api/resources"
4
4
  require "pact_broker/api/decorators"
5
+ require "pact_broker/api/contracts"
5
6
  require "pact_broker/application_context"
6
7
  require "pact_broker/feature_toggle"
7
8
 
@@ -25,7 +26,7 @@ end
25
26
  module PactBroker
26
27
  # rubocop: disable Metrics/MethodLength
27
28
  def self.build_api(application_context = PactBroker::ApplicationContext.default_application_context)
28
- pact_api = Webmachine::Application.new do |app|
29
+ Webmachine.build_rack_api(application_context) do |app|
29
30
  app.routes do
30
31
  add(["trace", :*], Webmachine::Trace::TraceResource) unless ENV["RACK_ENV"] == "production"
31
32
 
@@ -139,17 +140,6 @@ module PactBroker
139
140
  add [], Api::Resources::Index, {resource_name: "index"}
140
141
  end
141
142
  end
142
-
143
- # naughty, but better than setting each route manually
144
- pact_api.routes.each do | route |
145
- route.instance_variable_get(:@bindings)[:application_context] = application_context
146
- end
147
-
148
- pact_api.configure do |config|
149
- config.adapter = :RackMapped
150
- end
151
-
152
- pact_api.adapter
153
143
  end
154
144
 
155
145
 
@@ -20,7 +20,6 @@ require "rack/pact_broker/ui_request_filter"
20
20
  require "rack/pact_broker/ui_authentication"
21
21
  require "rack/pact_broker/configurable_make_it_later"
22
22
  require "rack/pact_broker/no_auth"
23
- require "rack/pact_broker/convert_404_to_hal"
24
23
  require "rack/pact_broker/reset_thread_data"
25
24
  require "rack/pact_broker/add_vary_header"
26
25
  require "rack/pact_broker/use_when"
@@ -256,7 +255,6 @@ module PactBroker
256
255
  api_apps.unshift(@custom_api) if @custom_api
257
256
  builder = ::Rack::Builder.new
258
257
  builder.use @make_it_later_api_auth
259
- builder.use Rack::PactBroker::Convert404ToHal
260
258
  builder.use Rack::PactBroker::DatabaseTransaction, configuration.database_connection
261
259
  builder.run Rack::Cascade.new(api_apps, [404])
262
260
  builder
@@ -3,7 +3,7 @@ require "pact_broker/api/contracts/configuration"
3
3
  require "pact_broker/api/decorators/decorator_context_creator"
4
4
  require "pact_broker/webhooks/execution_configuration_creator"
5
5
  require "pact_broker/errors/error_logger"
6
- require "pact_broker/api/resources/error_response_body_generator"
6
+ require "pact_broker/api/resources/error_response_generator"
7
7
 
8
8
  module PactBroker
9
9
  class ApplicationContext
@@ -15,7 +15,7 @@ module PactBroker
15
15
  :before_resource,
16
16
  :after_resource,
17
17
  :error_logger,
18
- :error_response_body_generator
18
+ :error_response_generator
19
19
 
20
20
  def initialize(params = {})
21
21
  params_with_defaults = {
@@ -24,7 +24,7 @@ module PactBroker
24
24
  decorator_context_creator: PactBroker::Api::Decorators::DecoratorContextCreator,
25
25
  webhook_execution_configuration_creator: PactBroker::Webhooks::ExecutionConfigurationCreator,
26
26
  error_logger: PactBroker::Errors::ErrorLogger,
27
- error_response_body_generator: PactBroker::Api::Resources::ErrorResponseBodyGenerator
27
+ error_response_generator: PactBroker::Api::Resources::ErrorResponseGenerator
28
28
  }.merge(params)
29
29
 
30
30
  @decorator_configuration = params_with_defaults[:decorator_configuration]
@@ -35,7 +35,7 @@ module PactBroker
35
35
  @before_resource = params_with_defaults[:before_resource]
36
36
  @after_resource = params_with_defaults[:after_resource]
37
37
  @error_logger = params_with_defaults[:error_logger]
38
- @error_response_body_generator = params_with_defaults[:error_response_body_generator]
38
+ @error_response_generator = params_with_defaults[:error_response_generator]
39
39
 
40
40
  end
41
41
 
@@ -1,6 +1,7 @@
1
1
  module PactBroker
2
2
  module Certificates
3
3
  class Certificate < Sequel::Model
4
+ set_primary_key :id
4
5
  end
5
6
 
6
7
  Certificate.plugin :timestamps, update_on_create: true