debian-mirror-gitlab/app/graphql/mutations/alert_management/prometheus_integration/create.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.3 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
module Mutations
module AlertManagement
module PrometheusIntegration
class Create < PrometheusIntegrationBase
graphql_name 'PrometheusIntegrationCreate'
2022-04-04 11:22:00 +05:30
include FindsProject
2021-10-27 15:23:28 +05:30
argument :project_path, GraphQL::Types::ID,
2021-01-29 00:20:46 +05:30
required: true,
2021-10-27 15:23:28 +05:30
description: 'Project to create the integration in.'
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
argument :active, GraphQL::Types::Boolean,
2021-01-29 00:20:46 +05:30
required: true,
2021-03-08 18:12:59 +05:30
description: 'Whether the integration is receiving alerts.'
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
argument :api_url, GraphQL::Types::String,
2021-01-29 00:20:46 +05:30
required: true,
2021-04-29 21:17:54 +05:30
description: 'Endpoint at which Prometheus can be queried.'
2021-01-29 00:20:46 +05:30
def resolve(args)
2021-03-11 19:13:27 +05:30
project = authorized_find!(args[:project_path])
2021-01-29 00:20:46 +05:30
2021-09-30 23:02:18 +05:30
return integration_exists if project.prometheus_integration
2021-01-29 00:20:46 +05:30
result = ::Projects::Operations::UpdateService.new(
project,
current_user,
**integration_attributes(args),
**token_attributes
).execute
2021-09-30 23:02:18 +05:30
response(project.prometheus_integration, result)
2021-01-29 00:20:46 +05:30
end
private
def integration_exists
response(nil, message: _('Multiple Prometheus integrations are not supported'))
end
end
end
end
end