debian-mirror-gitlab/app/services/projects/alerting/notify_service.rb

48 lines
1 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module Projects
module Alerting
2022-10-11 01:57:18 +05:30
class NotifyService < ::BaseProjectService
2021-03-11 19:13:27 +05:30
extend ::Gitlab::Utils::Override
include ::AlertManagement::AlertProcessing
2021-12-11 22:18:48 +05:30
include ::AlertManagement::Responses
2020-03-13 15:44:24 +05:30
2022-10-11 01:57:18 +05:30
def initialize(project, params)
super(project: project, params: params.to_h)
2021-02-22 17:27:13 +05:30
end
2021-01-29 00:20:46 +05:30
def execute(token, integration = nil)
@integration = integration
2021-01-03 14:25:43 +05:30
return bad_request unless valid_payload_size?
2021-01-29 00:20:46 +05:30
return forbidden unless active_integration?
2020-03-13 15:44:24 +05:30
return unauthorized unless valid_token?(token)
2021-01-03 14:25:43 +05:30
process_alert
2020-05-24 23:13:21 +05:30
return bad_request unless alert.persisted?
2021-03-11 19:13:27 +05:30
complete_post_processing_tasks
2020-03-13 15:44:24 +05:30
2021-12-11 22:18:48 +05:30
success(alert)
2020-03-13 15:44:24 +05:30
end
private
2022-10-11 01:57:18 +05:30
attr_reader :integration
alias_method :payload, :params
2020-03-13 15:44:24 +05:30
2021-03-11 19:13:27 +05:30
def valid_payload_size?
2022-10-11 01:57:18 +05:30
Gitlab::Utils::DeepSize.new(params).valid?
2021-01-29 00:20:46 +05:30
end
def active_integration?
integration&.active?
end
2020-03-13 15:44:24 +05:30
def valid_token?(token)
2021-01-29 00:20:46 +05:30
token == integration.token
2020-03-13 15:44:24 +05:30
end
end
end
end