Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create.rb « prometheus_integration « alert_management « mutations « graphql « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b06a4f58df5e8f203c7b43a599aca55677d3de9a (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
43
44
45
46
# frozen_string_literal: true

module Mutations
  module AlertManagement
    module PrometheusIntegration
      class Create < PrometheusIntegrationBase
        graphql_name 'PrometheusIntegrationCreate'

        include FindsProject

        argument :project_path, GraphQL::Types::ID,
                 required: true,
                 description: 'Project to create the integration in.'

        argument :active, GraphQL::Types::Boolean,
                 required: true,
                 description: 'Whether the integration is receiving alerts.'

        argument :api_url, GraphQL::Types::String,
                 required: false,
                 description: 'Endpoint at which Prometheus can be queried.'

        def resolve(args)
          project = authorized_find!(args[:project_path])

          return integration_exists if project.prometheus_integration

          result = ::Projects::Operations::UpdateService.new(
            project,
            current_user,
            **integration_attributes(args),
            **token_attributes
          ).execute

          response(project.prometheus_integration, result)
        end

        private

        def integration_exists
          response(nil, message: _('Multiple Prometheus integrations are not supported'))
        end
      end
    end
  end
end