summaryrefslogtreecommitdiff
path: root/app/graphql/mutations/alert_management/prometheus_integration/prometheus_integration_base.rb
blob: 6b690ac239aad0dbe3e84c2ea5fa34b491ffa3d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true

module Mutations
  module AlertManagement
    module PrometheusIntegration
      class PrometheusIntegrationBase < BaseMutation
        field :integration,
              Types::AlertManagement::PrometheusIntegrationType,
              null: true,
              description: "The newly created integration"

        authorize :admin_project

        private

        def find_object(id:)
          GitlabSchema.object_from_id(id, expected_class: ::PrometheusService)
        end

        def response(integration, result)
          {
            integration: integration,
            errors: Array(result[:message])
          }
        end

        def integration_attributes(args)
          {
            prometheus_integration_attributes: {
              manual_configuration: args[:active],
              api_url: args[:api_url]
            }.compact
          }
        end

        def token_attributes
          { alerting_setting_attributes: { regenerate_token: true } }
        end
      end
    end
  end
end