Class: PactBroker::Webhooks::Service
Constant Summary
collapse
- RESOURCE_CREATION =
PactBroker::Webhooks::TriggeredWebhook::TRIGGER_TYPE_RESOURCE_CREATION
- USER =
PactBroker::Webhooks::TriggeredWebhook::TRIGGER_TYPE_USER
Class Method Summary
collapse
-
.create(uuid, webhook, consumer, provider) ⇒ Object
-
.delete_all_webhhook_related_objects_by_pacticipant(pacticipant) ⇒ Object
-
.delete_all_webhook_related_objects_by_pact_publication_ids(pact_publication_ids) ⇒ Object
-
.delete_all_webhook_related_objects_by_verification_ids(verification_ids) ⇒ Object
-
.delete_by_uuid(uuid) ⇒ Object
-
.errors(webhook, uuid = nil) ⇒ Object
-
.execute_triggered_webhook_now(triggered_webhook, webhook_execution_configuration_hash) ⇒ Object
-
.fail_retrying_triggered_webhooks ⇒ Object
-
.find_all ⇒ Object
-
.find_by_consumer_and_or_provider(consumer, provider) ⇒ Object
-
.find_by_consumer_and_provider(consumer, provider) ⇒ Object
-
.find_by_uuid(uuid) ⇒ Object
-
.find_for_pact(pact) ⇒ Object
-
.find_latest_triggered_webhooks(consumer, provider) ⇒ Object
-
.find_latest_triggered_webhooks_for_pact(pact) ⇒ Object
-
.find_triggered_webhooks_for_pact(pact) ⇒ Object
-
.find_triggered_webhooks_for_verification(verification) ⇒ Object
-
.next_uuid ⇒ Object
-
.parameters ⇒ Object
-
.run_later(webhooks, pact, verification, event_name, options) ⇒ Object
-
.test_execution(webhook, execution_configuration) ⇒ Object
-
.trigger_webhooks(pact, verification, event_name, options) ⇒ Object
-
.update_by_uuid(uuid, params) ⇒ Object
-
.update_triggered_webhook_status(triggered_webhook, status) ⇒ Object
-
.valid_uuid_format?(uuid) ⇒ Boolean
label_repository, matrix_repository, pact_repository, pacticipant_repository, tag_repository, verification_repository, version_repository, webhook_repository
Methods included from Services
badge_service, certificate_service, group_service, index_service, integration_service, label_service, matrix_service, metrics_service, pact_service, pacticipant_service, tag_service, verification_service, version_service, webhook_service, webhook_trigger_service
Methods included from Messages
message, potential_duplicate_pacticipant_message, validation_message
Methods included from Logging
included, #log_error
Class Method Details
.create(uuid, webhook, consumer, provider) ⇒ Object
51
52
53
|
# File 'lib/pact_broker/webhooks/service.rb', line 51
def self.create uuid, webhook, consumer, provider
webhook_repository.create uuid, webhook, consumer, provider
end
|
71
72
73
74
75
|
# File 'lib/pact_broker/webhooks/service.rb', line 71
def self.delete_all_webhhook_related_objects_by_pacticipant pacticipant
webhook_repository.delete_executions_by_pacticipant pacticipant
webhook_repository.delete_triggered_webhooks_by_pacticipant pacticipant
webhook_repository.delete_by_pacticipant pacticipant
end
|
77
78
79
|
# File 'lib/pact_broker/webhooks/service.rb', line 77
def self.delete_all_webhook_related_objects_by_pact_publication_ids pact_publication_ids
webhook_repository.delete_triggered_webhooks_by_pact_publication_ids pact_publication_ids
end
|
81
82
83
|
# File 'lib/pact_broker/webhooks/service.rb', line 81
def self.delete_all_webhook_related_objects_by_verification_ids verification_ids
webhook_repository.delete_triggered_webhooks_by_verification_ids verification_ids
end
|
.delete_by_uuid(uuid) ⇒ Object
66
67
68
69
|
# File 'lib/pact_broker/webhooks/service.rb', line 66
def self.delete_by_uuid uuid
webhook_repository.delete_triggered_webhooks_by_webhook_uuid uuid
webhook_repository.delete_by_uuid uuid
end
|
.errors(webhook, uuid = nil) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/pact_broker/webhooks/service.rb', line 40
def self.errors webhook, uuid = nil
contract = PactBroker::Api::Contracts::WebhookContract.new(webhook)
contract.validate(webhook.attributes)
errors = contract.errors
if uuid && !valid_uuid_format?(uuid)
errors.add("uuid", message("errors.validation.invalid_webhook_uuid"))
end
errors
end
|
.execute_triggered_webhook_now(triggered_webhook, webhook_execution_configuration_hash) ⇒ Object
101
102
103
104
105
|
# File 'lib/pact_broker/webhooks/service.rb', line 101
def self.execute_triggered_webhook_now triggered_webhook, webhook_execution_configuration_hash
webhook_execution_result = triggered_webhook.execute webhook_execution_configuration_hash
webhook_repository.create_execution triggered_webhook, webhook_execution_result
webhook_execution_result
end
|
.fail_retrying_triggered_webhooks ⇒ Object
158
159
160
|
# File 'lib/pact_broker/webhooks/service.rb', line 158
def self.fail_retrying_triggered_webhooks
webhook_repository.fail_retrying_triggered_webhooks
end
|
.find_all ⇒ Object
85
86
87
|
# File 'lib/pact_broker/webhooks/service.rb', line 85
def self.find_all
webhook_repository.find_all
end
|
.find_by_consumer_and_or_provider(consumer, provider) ⇒ Object
115
116
117
|
# File 'lib/pact_broker/webhooks/service.rb', line 115
def self.find_by_consumer_and_or_provider consumer, provider
webhook_repository.find_by_consumer_and_or_provider(consumer, provider)
end
|
.find_by_consumer_and_provider(consumer, provider) ⇒ Object
119
120
121
|
# File 'lib/pact_broker/webhooks/service.rb', line 119
def self.find_by_consumer_and_provider consumer, provider
webhook_repository.find_by_consumer_and_provider consumer, provider
end
|
.find_by_uuid(uuid) ⇒ Object
55
56
57
|
# File 'lib/pact_broker/webhooks/service.rb', line 55
def self.find_by_uuid uuid
webhook_repository.find_by_uuid uuid
end
|
.find_for_pact(pact) ⇒ Object
111
112
113
|
# File 'lib/pact_broker/webhooks/service.rb', line 111
def self.find_for_pact pact
webhook_repository.find_for_pact(pact)
end
|
.find_latest_triggered_webhooks(consumer, provider) ⇒ Object
154
155
156
|
# File 'lib/pact_broker/webhooks/service.rb', line 154
def self.find_latest_triggered_webhooks consumer, provider
webhook_repository.find_latest_triggered_webhooks consumer, provider
end
|
.find_latest_triggered_webhooks_for_pact(pact) ⇒ Object
150
151
152
|
# File 'lib/pact_broker/webhooks/service.rb', line 150
def self.find_latest_triggered_webhooks_for_pact pact
webhook_repository.find_latest_triggered_webhooks_for_pact pact
end
|
.find_triggered_webhooks_for_pact(pact) ⇒ Object
162
163
164
|
# File 'lib/pact_broker/webhooks/service.rb', line 162
def self.find_triggered_webhooks_for_pact pact
webhook_repository.find_triggered_webhooks_for_pact(pact)
end
|
.find_triggered_webhooks_for_verification(verification) ⇒ Object
166
167
168
|
# File 'lib/pact_broker/webhooks/service.rb', line 166
def self.find_triggered_webhooks_for_verification verification
webhook_repository.find_triggered_webhooks_for_verification(verification)
end
|
.next_uuid ⇒ Object
36
37
38
|
# File 'lib/pact_broker/webhooks/service.rb', line 36
def self.next_uuid
SecureRandom.urlsafe_base64
end
|
.parameters ⇒ Object
170
171
172
173
174
175
176
177
|
# File 'lib/pact_broker/webhooks/service.rb', line 170
def self.parameters
PactAndVerificationParameters::ALL.collect do | parameter |
OpenStruct.new(
name: parameter,
description: message("messages.webhooks.parameters.#{parameter}")
)
end
end
|
.run_later(webhooks, pact, verification, event_name, options) ⇒ Object
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/pact_broker/webhooks/service.rb', line 134
def self.run_later webhooks, pact, verification, event_name, options
trigger_uuid = next_uuid
webhooks.each do | webhook |
begin
triggered_webhook = webhook_repository.create_triggered_webhook(trigger_uuid, webhook, pact, verification, RESOURCE_CREATION)
logger.info "Scheduling job for webhook with uuid #{webhook.uuid}"
logger.debug "Schedule webhook with options #{options}"
job_data = { triggered_webhook: triggered_webhook }.deep_merge(options)
Job.perform_in(5, job_data)
rescue StandardError => e
log_error e
end
end
end
|
.test_execution(webhook, execution_configuration) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/pact_broker/webhooks/service.rb', line 89
def self.test_execution webhook, execution_configuration
merged_options = execution_configuration.with_failure_log_message("Webhook execution failed").to_hash
verification = nil
if webhook.trigger_on_provider_verification_published?
verification = verification_service.search_for_latest(webhook.consumer_name, webhook.provider_name) || PactBroker::Verifications::PlaceholderVerification.new
end
pact = pact_service.search_for_latest_pact(consumer_name: webhook.consumer_name, provider_name: webhook.provider_name) || PactBroker::Pacts::PlaceholderPact.new
webhook.execute(pact, verification, merged_options)
end
|
.trigger_webhooks(pact, verification, event_name, options) ⇒ Object
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/pact_broker/webhooks/service.rb', line 123
def self.trigger_webhooks pact, verification, event_name, options
webhooks = webhook_repository.find_by_consumer_and_or_provider_and_event_name pact.consumer, pact.provider, event_name
if webhooks.any?
webhook_execution_configuration = options.fetch(:webhook_execution_configuration).with_webhook_context(event_name: event_name)
run_later(webhooks, pact, verification, event_name, options.merge(webhook_execution_configuration: webhook_execution_configuration))
else
logger.info "No enabled webhooks found for consumer \"#{pact.consumer.name}\" and provider \"#{pact.provider.name}\" and event #{event_name}"
end
end
|
.update_by_uuid(uuid, params) ⇒ Object
59
60
61
62
63
64
|
# File 'lib/pact_broker/webhooks/service.rb', line 59
def self.update_by_uuid uuid, params
webhook = webhook_repository.find_by_uuid(uuid)
maintain_redacted_params(webhook, params)
PactBroker::Api::Decorators::WebhookDecorator.new(webhook).from_hash(params)
webhook_repository.update_by_uuid uuid, webhook
end
|
.update_triggered_webhook_status(triggered_webhook, status) ⇒ Object
107
108
109
|
# File 'lib/pact_broker/webhooks/service.rb', line 107
def self.update_triggered_webhook_status triggered_webhook, status
webhook_repository.update_triggered_webhook_status triggered_webhook, status
end
|
Not actually a UUID. Ah well.
32
33
34
|
# File 'lib/pact_broker/webhooks/service.rb', line 32
def self.valid_uuid_format?(uuid)
!!(uuid =~ /^[A-Za-z0-9_\-]{16,}$/)
end
|