pact_broker 2.72.0 → 2.76.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/test.yml +1 -1
  3. data/.optic/.gitignore +2 -0
  4. data/.optic/api/specification.json +1 -0
  5. data/.optic/ignore +14 -0
  6. data/CHANGELOG.md +66 -0
  7. data/DEVELOPER_SETUP.md +9 -0
  8. data/Dockerfile +1 -0
  9. data/ISSUES.md +3 -3
  10. data/README.md +1 -1
  11. data/config/database.yml +1 -1
  12. data/db/migrations/20210115_add_webhook_foreign_key_indexes.rb +49 -0
  13. data/db/migrations/20210116_add_context_to_triggered_webhook.rb +11 -0
  14. data/db/migrations/migration_helper.rb +8 -0
  15. data/docker-compose-issue-repro-with-pact-broker-docker-image.yml +33 -0
  16. data/docker-compose-test.yml +4 -4
  17. data/lib/db.rb +1 -0
  18. data/lib/pact_broker/api.rb +13 -2
  19. data/lib/pact_broker/api/decorators.rb +3 -7
  20. data/lib/pact_broker/api/decorators/configuration.rb +33 -0
  21. data/lib/pact_broker/api/decorators/decorator_context_creator.rb +13 -0
  22. data/lib/pact_broker/api/decorators/extended_pact_decorator.rb +9 -1
  23. data/lib/pact_broker/api/decorators/extended_verification_decorator.rb +8 -0
  24. data/lib/pact_broker/api/decorators/matrix_decorator.rb +9 -4
  25. data/lib/pact_broker/api/decorators/pact_collection_decorator.rb +1 -0
  26. data/lib/pact_broker/api/decorators/pacticipant_collection_decorator.rb +2 -3
  27. data/lib/pact_broker/api/decorators/reason_decorator.rb +2 -0
  28. data/lib/pact_broker/api/decorators/tag_decorator.rb +0 -3
  29. data/lib/pact_broker/api/decorators/verifiable_pact_decorator.rb +3 -1
  30. data/lib/pact_broker/api/pact_broker_urls.rb +4 -4
  31. data/lib/pact_broker/api/paths.rb +5 -0
  32. data/lib/pact_broker/api/renderers/html_pact_renderer.rb +2 -2
  33. data/lib/pact_broker/api/resources/all_webhooks.rb +3 -3
  34. data/lib/pact_broker/api/resources/can_i_deploy_badge.rb +1 -1
  35. data/lib/pact_broker/api/resources/dashboard.rb +2 -2
  36. data/lib/pact_broker/api/resources/default_base_resource.rb +37 -12
  37. data/lib/pact_broker/api/resources/error_handler.rb +1 -1
  38. data/lib/pact_broker/api/resources/error_response_body_generator.rb +41 -0
  39. data/lib/pact_broker/api/resources/group.rb +1 -1
  40. data/lib/pact_broker/api/resources/integrations.rb +1 -1
  41. data/lib/pact_broker/api/resources/label.rb +1 -1
  42. data/lib/pact_broker/api/resources/latest_pact.rb +2 -2
  43. data/lib/pact_broker/api/resources/latest_pacts.rb +1 -1
  44. data/lib/pact_broker/api/resources/latest_verifications_for_consumer_version.rb +2 -2
  45. data/lib/pact_broker/api/resources/matrix.rb +2 -2
  46. data/lib/pact_broker/api/resources/matrix_for_consumer_and_provider.rb +1 -1
  47. data/lib/pact_broker/api/resources/metadata_resource_methods.rb +2 -1
  48. data/lib/pact_broker/api/resources/pact.rb +2 -2
  49. data/lib/pact_broker/api/resources/pact_triggered_webhooks.rb +1 -1
  50. data/lib/pact_broker/api/resources/pact_versions.rb +1 -1
  51. data/lib/pact_broker/api/resources/pact_webhooks.rb +3 -3
  52. data/lib/pact_broker/api/resources/pact_webhooks_status.rb +2 -2
  53. data/lib/pact_broker/api/resources/pacticipant.rb +1 -1
  54. data/lib/pact_broker/api/resources/pacticipants.rb +3 -3
  55. data/lib/pact_broker/api/resources/pacticipants_for_label.rb +1 -1
  56. data/lib/pact_broker/api/resources/previous_distinct_pact_version.rb +1 -1
  57. data/lib/pact_broker/api/resources/provider_pacts.rb +1 -7
  58. data/lib/pact_broker/api/resources/provider_pacts_for_verification.rb +2 -2
  59. data/lib/pact_broker/api/resources/relationships.rb +1 -1
  60. data/lib/pact_broker/api/resources/tag.rb +1 -1
  61. data/lib/pact_broker/api/resources/tagged_pact_versions.rb +1 -1
  62. data/lib/pact_broker/api/resources/verification.rb +2 -2
  63. data/lib/pact_broker/api/resources/verification_triggered_webhooks.rb +1 -1
  64. data/lib/pact_broker/api/resources/verifications.rb +1 -1
  65. data/lib/pact_broker/api/resources/version.rb +1 -1
  66. data/lib/pact_broker/api/resources/versions.rb +1 -1
  67. data/lib/pact_broker/api/resources/webhook.rb +2 -2
  68. data/lib/pact_broker/api/resources/webhook_execution.rb +4 -4
  69. data/lib/pact_broker/api/resources/webhook_execution_methods.rb +1 -3
  70. data/lib/pact_broker/api/resources/webhooks.rb +3 -3
  71. data/lib/pact_broker/app.rb +14 -3
  72. data/lib/pact_broker/application_context.rb +41 -0
  73. data/lib/pact_broker/configuration.rb +12 -4
  74. data/lib/pact_broker/doc/controllers/app.rb +3 -2
  75. data/lib/pact_broker/domain/version.rb +13 -6
  76. data/lib/pact_broker/domain/webhook_request.rb +1 -1
  77. data/lib/pact_broker/error.rb +0 -2
  78. data/lib/pact_broker/errors.rb +28 -0
  79. data/lib/pact_broker/errors/error_logger.rb +25 -0
  80. data/lib/pact_broker/metrics/service.rb +12 -1
  81. data/lib/pact_broker/pacts/metadata.rb +53 -8
  82. data/lib/pact_broker/pacts/repository.rb +10 -17
  83. data/lib/pact_broker/pacts/selector.rb +22 -0
  84. data/lib/pact_broker/pacts/selectors.rb +4 -0
  85. data/lib/pact_broker/services.rb +106 -31
  86. data/lib/pact_broker/tags/tag_with_latest_flag.rb +2 -0
  87. data/lib/pact_broker/test/http_test_data_builder.rb +83 -21
  88. data/lib/pact_broker/test/test_data_builder.rb +3 -2
  89. data/lib/pact_broker/ui/views/index/_getting-started.haml +1 -1
  90. data/lib/pact_broker/ui/views/index/show-with-tags.haml +16 -16
  91. data/lib/pact_broker/ui/views/index/show.haml +6 -6
  92. data/lib/pact_broker/ui/views/layouts/main.haml +2 -2
  93. data/lib/pact_broker/ui/views/matrix/show.haml +32 -33
  94. data/lib/pact_broker/version.rb +1 -1
  95. data/lib/pact_broker/webhooks/execution_configuration.rb +4 -0
  96. data/lib/pact_broker/webhooks/execution_configuration_creator.rb +14 -0
  97. data/lib/pact_broker/webhooks/repository.rb +3 -2
  98. data/lib/pact_broker/webhooks/service.rb +2 -1
  99. data/lib/pact_broker/webhooks/triggered_webhook.rb +1 -0
  100. data/lib/rack/pact_broker/hal_browser_redirect.rb +42 -0
  101. data/lib/rack/pact_broker/set_base_url.rb +22 -0
  102. data/lib/sequel/extensions/statement_timeout.rb +22 -0
  103. data/optic.yml +5 -0
  104. data/pact_broker.gemspec +1 -1
  105. data/public/css/bootstrap-grid.css +3719 -0
  106. data/public/css/bootstrap-grid.css.map +1 -0
  107. data/public/css/bootstrap-grid.min.css +7 -0
  108. data/public/css/bootstrap-grid.min.css.map +1 -0
  109. data/public/css/bootstrap-reboot.css +331 -0
  110. data/public/css/bootstrap-reboot.css.map +1 -0
  111. data/public/css/bootstrap-reboot.min.css +8 -0
  112. data/public/css/bootstrap-reboot.min.css.map +1 -0
  113. data/public/css/bootstrap.css +8885 -5604
  114. data/public/css/bootstrap.css.map +1 -1
  115. data/public/css/bootstrap.min.css +4 -3
  116. data/public/css/bootstrap.min.css.map +1 -1
  117. data/public/images/alert.svg +1 -0
  118. data/public/images/arrow-switch.svg +1 -0
  119. data/public/images/check.svg +1 -0
  120. data/public/images/clock.svg +1 -0
  121. data/public/images/copy.svg +1 -0
  122. data/public/images/kebab-horizontal.svg +1 -0
  123. data/public/javascripts/clipboard.js +3 -3
  124. data/public/javascripts/{jquery-3.3.1.js → jquery-3.5.1.js} +1150 -642
  125. data/public/javascripts/jquery-3.5.1.min.js +2 -0
  126. data/public/javascripts/jquery-3.5.1.min.map +1 -0
  127. data/public/javascripts/matrix.js +2 -2
  128. data/public/js/bootstrap.bundle.js +7013 -0
  129. data/public/js/bootstrap.bundle.js.map +1 -0
  130. data/public/js/bootstrap.bundle.min.js +7 -0
  131. data/public/js/bootstrap.bundle.min.js.map +1 -0
  132. data/public/js/bootstrap.js +3862 -1804
  133. data/public/js/bootstrap.js.map +1 -0
  134. data/public/js/bootstrap.min.js +6 -6
  135. data/public/js/bootstrap.min.js.map +1 -0
  136. data/public/stylesheets/index.css +56 -3
  137. data/public/stylesheets/matrix.css +55 -5
  138. data/public/stylesheets/pact.css +14 -0
  139. data/regression/.gitignore +1 -0
  140. data/regression/can_i_deploy_spec.rb +42 -0
  141. data/regression/regression_helper.rb +37 -0
  142. data/regression/script/approval-all.sh +6 -0
  143. data/script/exercise-api-for-optic.sh +3 -0
  144. data/script/reproduce-issue-starting-up.rb +43 -0
  145. data/script/reproduce-issue.rb +9 -21
  146. data/spec/lib/pact_broker/api/decorators/extended_pact_decorator_spec.rb +1 -0
  147. data/spec/lib/pact_broker/api/decorators/matrix_decorator_spec.rb +20 -8
  148. data/spec/lib/pact_broker/api/decorators/verifiable_pact_decorator_spec.rb +5 -7
  149. data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +10 -6
  150. data/spec/lib/pact_broker/api/resources/can_i_deploy_badge_spec.rb +1 -1
  151. data/spec/lib/pact_broker/api/resources/default_base_resource_spec.rb +59 -10
  152. data/spec/lib/pact_broker/api/resources/error_response_body_generator_spec.rb +69 -0
  153. data/spec/lib/pact_broker/db/log_quietener_spec.rb +1 -1
  154. data/spec/lib/pact_broker/doc/controllers/app_spec.rb +3 -5
  155. data/spec/lib/pact_broker/errors/error_logger_spec.rb +62 -0
  156. data/spec/lib/pact_broker/errors_spec.rb +55 -0
  157. data/spec/lib/pact_broker/pacts/metadata_spec.rb +73 -0
  158. data/spec/lib/pact_broker/pacts/repository_find_for_verification_fallback_spec.rb +2 -2
  159. data/spec/lib/pact_broker/pacts/repository_find_for_verification_spec.rb +33 -13
  160. data/spec/lib/pact_broker/pacts/selected_pact_spec.rb +23 -0
  161. data/spec/lib/pact_broker/webhooks/repository_spec.rb +5 -2
  162. data/spec/lib/pact_broker/webhooks/service_spec.rb +2 -1
  163. data/spec/lib/rack/pact_broker/hal_browser_redirect_spec.rb +27 -0
  164. data/tasks/rspec.rake +6 -0
  165. metadata +65 -17
  166. data/public/css/bootstrap-theme.css +0 -587
  167. data/public/css/bootstrap-theme.css.map +0 -1
  168. data/public/css/bootstrap-theme.min.css +0 -6
  169. data/public/css/bootstrap-theme.min.css.map +0 -1
  170. data/public/fonts/glyphicons-halflings-regular.svg +0 -288
  171. data/public/javascripts/jquery-3.3.1.min.js +0 -2
  172. data/public/javascripts/jquery-3.3.1.min.map +0 -1
  173. data/spec/lib/pact_broker/api/resources/error_handler_spec.rb +0 -195
@@ -23,7 +23,7 @@ module PactBroker
23
23
 
24
24
  def to_json
25
25
  summary = verification_service.verification_summary_for_consumer_version(identifier_from_path)
26
- decorator_for(summary).to_json(user_options: decorator_context(identifier_from_path))
26
+ decorator_for(summary).to_json(decorator_options(identifier_from_path))
27
27
  end
28
28
 
29
29
  def policy_name
@@ -40,7 +40,7 @@ module PactBroker
40
40
  end
41
41
 
42
42
  def decorator_for summary
43
- PactBroker::Api::Decorators::VerificationSummaryDecorator.new(summary)
43
+ decorator_class(:verification_summary_decorator).new(summary)
44
44
  end
45
45
  end
46
46
  end
@@ -36,11 +36,11 @@ module PactBroker
36
36
  end
37
37
 
38
38
  def to_json
39
- PactBroker::Api::Decorators::MatrixDecorator.new(results).to_json(decorator_options)
39
+ decorator_class(:matrix_decorator).new(results).to_json(decorator_options)
40
40
  end
41
41
 
42
42
  def to_text
43
- PactBroker::Api::Decorators::MatrixTextDecorator.new(results).to_text(decorator_options)
43
+ decorator_class(:matrix_text_decorator).new(results).to_text(decorator_options)
44
44
  end
45
45
 
46
46
  def policy_name
@@ -24,7 +24,7 @@ module PactBroker
24
24
  end
25
25
 
26
26
  def to_json
27
- PactBroker::Api::Decorators::MatrixDecorator.new(results).to_json(decorator_options)
27
+ decorator_class(:matrix_decorator).new(results).to_json(decorator_options)
28
28
  end
29
29
 
30
30
  def policy_name
@@ -1,4 +1,5 @@
1
1
  require 'pact_broker/hash_refinements'
2
+ require 'pact_broker/pacts/metadata'
2
3
 
3
4
  module PactBroker
4
5
  module Api
@@ -15,7 +16,7 @@ module PactBroker
15
16
  end
16
17
 
17
18
  def metadata
18
- @metadata ||= PactBrokerUrls.decode_pact_metadata(identifier_from_path[:metadata])
19
+ @metadata ||= PactBroker::Pacts::Metadata.parse_metadata(PactBrokerUrls.decode_pact_metadata(identifier_from_path[:metadata]))
19
20
  end
20
21
  end
21
22
  end
@@ -69,11 +69,11 @@ module PactBroker
69
69
  end
70
70
 
71
71
  def to_json
72
- PactBroker::Api::Decorators::PactDecorator.new(pact).to_json(user_options: decorator_context(metadata: identifier_from_path[:metadata]))
72
+ decorator_class(:pact_decorator).new(pact).to_json(decorator_options(metadata: identifier_from_path[:metadata]))
73
73
  end
74
74
 
75
75
  def to_extended_json
76
- PactBroker::Api::Decorators::ExtendedPactDecorator.new(pact).to_json(user_options: decorator_context(metadata: identifier_from_path[:metadata]))
76
+ decorator_class(:extended_pact_decorator).new(pact).to_json(decorator_options(metadata: identifier_from_path[:metadata]))
77
77
  end
78
78
 
79
79
  def to_html
@@ -18,7 +18,7 @@ module PactBroker
18
18
  end
19
19
 
20
20
  def to_json
21
- Decorators::TriggeredWebhooksDecorator.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
@@ -19,7 +19,7 @@ module PactBroker
19
19
  end
20
20
 
21
21
  def to_json
22
- PactBroker::Api::Decorators::PactVersionsDecorator.new(pacts).to_json(user_options: decorator_context(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
@@ -52,11 +52,11 @@ module PactBroker
52
52
 
53
53
  def from_json
54
54
  saved_webhook = webhook_service.create next_uuid, webhook, consumer, provider
55
- response.body = Decorators::WebhookDecorator.new(saved_webhook).to_json(decorator_options)
55
+ response.body = decorator_class(:webhook_decorator).new(saved_webhook).to_json(decorator_options)
56
56
  end
57
57
 
58
58
  def to_json
59
- Decorators::WebhooksDecorator.new(webhooks).to_json(user_options: decorator_context(resource_title: 'Pact webhooks'))
59
+ decorator_class(:webhooks_decorator).new(webhooks).to_json(decorator_options(resource_title: 'Pact webhooks'))
60
60
  end
61
61
 
62
62
  def policy_name
@@ -70,7 +70,7 @@ module PactBroker
70
70
  end
71
71
 
72
72
  def webhook
73
- @webhook ||= Decorators::WebhookDecorator.new(PactBroker::Domain::Webhook.new).from_json(request_body)
73
+ @webhook ||= decorator_class(:webhook_decorator).new(PactBroker::Domain::Webhook.new).from_json(request_body)
74
74
  end
75
75
 
76
76
  def next_uuid
@@ -19,7 +19,7 @@ module PactBroker
19
19
  end
20
20
 
21
21
  def to_json
22
- decorator_for(latest_triggered_webhooks).to_json(user_options: decorator_context(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
@@ -41,7 +41,7 @@ module PactBroker
41
41
  end
42
42
 
43
43
  def decorator_for latest_triggered_webhooks
44
- PactBroker::Api::Decorators::PactWebhooksStatusDecorator.new(latest_triggered_webhooks)
44
+ decorator_class(:pact_webhooks_status_decorator).new(latest_triggered_webhooks)
45
45
  end
46
46
  end
47
47
  end
@@ -49,7 +49,7 @@ module PactBroker
49
49
  end
50
50
 
51
51
  def to_json
52
- PactBroker::Api::Decorators::PacticipantDecorator.new(pacticipant).to_json(decorator_options)
52
+ decorator_class(:pacticipant_decorator).new(pacticipant).to_json(decorator_options)
53
53
  end
54
54
 
55
55
  def policy_name
@@ -34,7 +34,7 @@ module PactBroker
34
34
 
35
35
  def from_json
36
36
  created_model = pacticipant_service.create(params.symbolize_keys.snakecase_keys.slice(:name, :repository_url))
37
- response.body = decorator_for(created_model).to_json(user_options: decorator_context)
37
+ response.body = decorator_for(created_model).to_json(decorator_options)
38
38
  end
39
39
 
40
40
  def create_path
@@ -46,11 +46,11 @@ module PactBroker
46
46
  end
47
47
 
48
48
  def generate_json pacticipants
49
- PactBroker::Api::Decorators::DeprecatedPacticipantCollectionDecorator.new(pacticipants).to_json(decorator_options)
49
+ decorator_class(:deprecated_pacticipant_collection_decorator).new(pacticipants).to_json(decorator_options)
50
50
  end
51
51
 
52
52
  def decorator_for model
53
- PactBroker::Api::Decorators::PacticipantDecorator.new(model)
53
+ decorator_class(:pacticipant_decorator).new(model)
54
54
  end
55
55
 
56
56
  def new_model
@@ -19,7 +19,7 @@ module PactBroker
19
19
  end
20
20
 
21
21
  def generate_json pacticipants
22
- PactBroker::Api::Decorators::PacticipantCollectionDecorator.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
@@ -21,7 +21,7 @@ module PactBroker
21
21
  end
22
22
 
23
23
  def to_json
24
- PactBroker::Api::Decorators::PactDecorator.new(pact).to_json(user_options: {base_url: base_url})
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
- PactBroker::Api::Decorators::ProviderPactsDecorator.new(pacts).to_json(to_json_options)
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
@@ -33,12 +33,6 @@ module PactBroker
33
33
  pact_service.find_pact_versions_for_provider provider_name, tag: identifier_from_path[:tag]
34
34
  end
35
35
 
36
- def to_json_options
37
- {
38
- user_options: decorator_context(identifier_from_path.merge(title: resource_title))
39
- }
40
- end
41
-
42
36
  def resource_title
43
37
  suffix = identifier_from_path[:tag] ? " with consumer version tag '#{identifier_from_path[:tag]}'" : ""
44
38
  "All pact versions for the provider #{identifier_from_path[:provider_name]}#{suffix}"
@@ -53,7 +53,7 @@ module PactBroker
53
53
 
54
54
  def to_json
55
55
  log_request
56
- PactBroker::Api::Decorators::VerifiablePactsDecorator.new(pacts).to_json(
56
+ decorator_class(:verifiable_pacts_decorator).new(pacts).to_json(
57
57
  decorator_options(
58
58
  include_pending_status: parsed_query_params.include_pending_status,
59
59
  title: "Pacts to be verified by provider #{provider_name}",
@@ -71,7 +71,7 @@ module PactBroker
71
71
  end
72
72
 
73
73
  def parsed_query_params
74
- @parsed_query_params ||= PactBroker::Api::Decorators::VerifiablePactsQueryDecorator.new(OpenStruct.new).from_hash(query)
74
+ @parsed_query_params ||= decorator_class(:verifiable_pacts_query_decorator).new(OpenStruct.new).from_hash(query)
75
75
  end
76
76
 
77
77
  def query
@@ -14,7 +14,7 @@ module PactBroker
14
14
  end
15
15
 
16
16
  def to_csv
17
- PactBroker::Api::Decorators::RelationshipsCsvDecorator.new(pacts).to_csv
17
+ decorator_class(:relationships_csv_decorator).new(pacts).to_csv
18
18
  end
19
19
 
20
20
  def pacts
@@ -31,7 +31,7 @@ module PactBroker
31
31
  end
32
32
 
33
33
  def to_json
34
- PactBroker::Api::Decorators::TagDecorator.new(tag).to_json(decorator_options)
34
+ decorator_class(:tag_decorator).new(tag).to_json(decorator_options)
35
35
  end
36
36
 
37
37
  def tag
@@ -22,7 +22,7 @@ module PactBroker
22
22
  end
23
23
 
24
24
  def to_json
25
- PactBroker::Api::Decorators::TaggedPactVersionsDecorator.new(pacts).to_json(user_options: decorator_context(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
@@ -60,11 +60,11 @@ module PactBroker
60
60
  end
61
61
 
62
62
  def decorator_for model
63
- PactBroker::Api::Decorators::VerificationDecorator.new(model)
63
+ decorator_class(:verification_decorator).new(model)
64
64
  end
65
65
 
66
66
  def extended_decorator_for model
67
- PactBroker::Api::Decorators::ExtendedVerificationDecorator.new(model)
67
+ decorator_class(:extended_verification_decorator).new(model)
68
68
  end
69
69
  end
70
70
  end
@@ -18,7 +18,7 @@ module PactBroker
18
18
  end
19
19
 
20
20
  def to_json
21
- Decorators::TriggeredWebhooksDecorator.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
@@ -74,7 +74,7 @@ module PactBroker
74
74
  end
75
75
 
76
76
  def decorator_for model
77
- PactBroker::Api::Decorators::VerificationDecorator.new(model)
77
+ decorator_class(:verification_decorator).new(model)
78
78
  end
79
79
 
80
80
  def wip?
@@ -19,7 +19,7 @@ module PactBroker
19
19
  end
20
20
 
21
21
  def to_json
22
- Decorators::VersionDecorator.new(version).to_json(decorator_options)
22
+ decorator_class(:version_decorator).new(version).to_json(decorator_options)
23
23
  end
24
24
 
25
25
  def delete_resource
@@ -19,7 +19,7 @@ module PactBroker
19
19
  end
20
20
 
21
21
  def to_json
22
- PactBroker::Api::Decorators::VersionsDecorator.new(versions).to_json(user_options: decorator_context(identifier_from_path))
22
+ decorator_class(:versions_decorator).new(versions).to_json(decorator_options(identifier_from_path))
23
23
  end
24
24
 
25
25
  def versions
@@ -49,7 +49,7 @@ module PactBroker
49
49
  end
50
50
 
51
51
  def to_json
52
- Decorators::WebhookDecorator.new(webhook).to_json(decorator_options)
52
+ decorator_class(:webhook_decorator).new(webhook).to_json(decorator_options)
53
53
  end
54
54
 
55
55
  def delete_resource
@@ -68,7 +68,7 @@ module PactBroker
68
68
  end
69
69
 
70
70
  def parsed_webhook
71
- @parsed_webhook ||= Decorators::WebhookDecorator.new(PactBroker::Domain::Webhook.new).from_json(request_body)
71
+ @parsed_webhook ||= decorator_class(:webhook_decorator).new(PactBroker::Domain::Webhook.new).from_json(request_body)
72
72
  end
73
73
 
74
74
  def uuid
@@ -55,7 +55,7 @@ module PactBroker
55
55
  private
56
56
 
57
57
  def post_response_body webhook_execution_result
58
- Decorators::WebhookExecutionResultDecorator.new(webhook_execution_result).to_json(user_options: user_options)
58
+ decorator_class(:webhook_execution_result_decorator).new(webhook_execution_result).to_json(decorator_options)
59
59
  end
60
60
 
61
61
  def webhook
@@ -72,15 +72,15 @@ module PactBroker
72
72
  identifier_from_path[:uuid]
73
73
  end
74
74
 
75
- def user_options
76
- decorator_context(
75
+ def decorator_options
76
+ super(
77
77
  webhook: webhook,
78
78
  show_response: PactBroker.configuration.show_webhook_response?
79
79
  )
80
80
  end
81
81
 
82
82
  def build_unsaved_webhook
83
- Decorators::WebhookDecorator.new(PactBroker::Domain::Webhook.new).from_json(request_body)
83
+ decorator_class(:webhook_decorator).new(PactBroker::Domain::Webhook.new).from_json(request_body)
84
84
  end
85
85
  end
86
86
  end
@@ -3,9 +3,7 @@ module PactBroker
3
3
  module Resources
4
4
  module WebhookExecutionMethods
5
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)
6
+ application_context.webhook_execution_configuration_creator.call(self)
9
7
  end
10
8
  end
11
9
  end
@@ -43,11 +43,11 @@ module PactBroker
43
43
 
44
44
  def from_json
45
45
  saved_webhook = webhook_service.create next_uuid, webhook, consumer, provider
46
- response.body = Decorators::WebhookDecorator.new(saved_webhook).to_json(decorator_options)
46
+ response.body = decorator_class(:webhook_decorator).new(saved_webhook).to_json(decorator_options)
47
47
  end
48
48
 
49
49
  def to_json
50
- Decorators::WebhooksDecorator.new(webhooks).to_json(decorator_options(resource_title: 'Pact webhooks'))
50
+ decorator_class(:webhooks_decorator).new(webhooks).to_json(decorator_options(resource_title: 'Pact webhooks'))
51
51
  end
52
52
 
53
53
  def policy_name
@@ -61,7 +61,7 @@ module PactBroker
61
61
  end
62
62
 
63
63
  def webhook
64
- @webhook ||= Decorators::WebhookDecorator.new(PactBroker::Domain::Webhook.new).from_json(request_body)
64
+ @webhook ||= decorator_class(:webhook_decorator).new(PactBroker::Domain::Webhook.new).from_json(request_body)
65
65
  end
66
66
 
67
67
  def next_uuid
@@ -5,6 +5,8 @@ require 'pact_broker/logging/default_formatter'
5
5
  require 'pact_broker/policies'
6
6
  require 'rack-protection'
7
7
  require 'rack/hal_browser'
8
+ require 'rack/pact_broker/hal_browser_redirect'
9
+ require 'rack/pact_broker/set_base_url'
8
10
  require 'rack/pact_broker/add_pact_broker_version_header'
9
11
  require 'rack/pact_broker/convert_file_extension_to_accept_header'
10
12
  require 'rack/pact_broker/database_transaction'
@@ -32,6 +34,8 @@ module PactBroker
32
34
  @cascade_apps = []
33
35
  @make_it_later_api_auth = ::Rack::PactBroker::ConfigurableMakeItLater.new(Rack::PactBroker::NoAuth)
34
36
  @make_it_later_ui_auth = ::Rack::PactBroker::ConfigurableMakeItLater.new(Rack::PactBroker::NoAuth)
37
+ # Can only be required after database connection has been made because the decorators rely on the Sequel models
38
+ @create_pact_broker_api_block = ->() { require 'pact_broker/api'; PactBroker::API }
35
39
  @configuration = PactBroker.configuration
36
40
  yield configuration
37
41
  post_configure
@@ -68,13 +72,17 @@ module PactBroker
68
72
  @custom_api = custom_api
69
73
  end
70
74
 
75
+ def use_to_create_pact_broker_api &block
76
+ @create_pact_broker_api_block = block
77
+ end
78
+
71
79
  def call env
72
80
  running_app.call env
73
81
  end
74
82
 
75
83
  private
76
84
 
77
- attr_reader :custom_ui
85
+ attr_reader :custom_ui, :create_pact_broker_api_block
78
86
 
79
87
  def post_configure
80
88
  configure_logger
@@ -126,6 +134,7 @@ module PactBroker
126
134
  PactBroker::DB.validate_connection_config if configuration.validate_database_connection_config
127
135
  PactBroker::DB.set_mysql_strict_mode_if_mysql
128
136
  PactBroker::DB.connection.extension(:pagination)
137
+ PactBroker::DB.connection.extension(:statement_timeout)
129
138
 
130
139
  Sequel.datetime_class = DateTime
131
140
  Sequel.database_timezone = :utc # Store all dates in UTC, assume any date without a TZ is UTC
@@ -182,10 +191,13 @@ module PactBroker
182
191
  @app_builder.use Rack::Static, :urls => ["/stylesheets", "/css", "/fonts", "/js", "/javascripts", "/images"], :root => PactBroker.project_root.join("public")
183
192
  @app_builder.use Rack::Static, :urls => ["/favicon.ico"], :root => PactBroker.project_root.join("public/images"), header_rules: [[:all, {'Content-Type' => 'image/x-icon'}]]
184
193
  @app_builder.use Rack::PactBroker::ConvertFileExtensionToAcceptHeader
194
+ # Rack::PactBroker::SetBaseUrl needs to be before the Rack::PactBroker::HalBrowserRedirect
195
+ @app_builder.use Rack::PactBroker::SetBaseUrl, configuration.base_url
185
196
 
186
197
  if configuration.use_hal_browser
187
198
  logger.info "Mounting HAL browser"
188
199
  @app_builder.use Rack::HalBrowser::Redirect
200
+ @app_builder.use Rack::PactBroker::HalBrowserRedirect
189
201
  else
190
202
  logger.info "Not mounting HAL browser"
191
203
  end
@@ -206,8 +218,7 @@ module PactBroker
206
218
 
207
219
  def build_api
208
220
  logger.info "Mounting PactBroker::API"
209
- require 'pact_broker/api'
210
- api_apps = [PactBroker::API]
221
+ api_apps = [create_pact_broker_api_block.call]
211
222
  api_apps.unshift(@custom_api) if @custom_api
212
223
  builder = ::Rack::Builder.new
213
224
  builder.use @make_it_later_api_auth