diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-12 18:09:37 +0300 |
commit | 2c89e169769ead722394a79ed67fcd08e96863dd (patch) | |
tree | 0dadb576846c484475b895f75fab41f71cdb952e /app/services/projects/alerting | |
parent | bd497e352ebd279536ae11855871162e82a3f88c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/projects/alerting')
-rw-r--r-- | app/services/projects/alerting/notify_service.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/app/services/projects/alerting/notify_service.rb b/app/services/projects/alerting/notify_service.rb new file mode 100644 index 00000000000..4ca3b154e4b --- /dev/null +++ b/app/services/projects/alerting/notify_service.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +module Projects + module Alerting + class NotifyService < BaseService + include Gitlab::Utils::StrongMemoize + + def execute(token) + return forbidden unless alerts_service_activated? + return unauthorized unless valid_token?(token) + + process_incident_issues + + ServiceResponse.success + rescue Gitlab::Alerting::NotificationPayloadParser::BadPayloadError + bad_request + end + + private + + delegate :alerts_service, :alerts_service_activated?, to: :project + + def process_incident_issues + IncidentManagement::ProcessAlertWorker + .perform_async(project.id, parsed_payload) + end + + def parsed_payload + Gitlab::Alerting::NotificationPayloadParser.call(params.to_h) + end + + def valid_token?(token) + token == alerts_service.token + end + + def bad_request + ServiceResponse.error(message: 'Bad Request', http_status: 400) + end + + def unauthorized + ServiceResponse.error(message: 'Unauthorized', http_status: 401) + end + + def forbidden + ServiceResponse.error(message: 'Forbidden', http_status: 403) + end + end + end +end |