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

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
2021-03-11 19:13:27 +05:30
include FindsProject
2021-01-29 00:20:46 +05:30
graphql_name 'PrometheusIntegrationCreate'
argument :project_path, GraphQL::ID_TYPE,
required: true,
2021-03-08 18:12:59 +05:30
description: 'The project to create the integration in.'
2021-01-29 00:20:46 +05:30
argument :active, GraphQL::BOOLEAN_TYPE,
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
argument :api_url, GraphQL::STRING_TYPE,
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
return integration_exists if project.prometheus_service
result = ::Projects::Operations::UpdateService.new(
project,
current_user,
**integration_attributes(args),
**token_attributes
).execute
response(project.prometheus_service, result)
end
private
def integration_exists
response(nil, message: _('Multiple Prometheus integrations are not supported'))
end
end
end
end
end