debian-mirror-gitlab/app/graphql/resolvers/alert_management/integrations_resolver.rb

63 lines
1.7 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
module Resolvers
module AlertManagement
class IntegrationsResolver < BaseResolver
2021-04-29 21:17:54 +05:30
include ::Gitlab::Graphql::Laziness
alias_method :project, :object
argument :id, ::Types::GlobalIDType,
required: false,
description: 'ID of the integration.'
2021-01-29 00:20:46 +05:30
type Types::AlertManagement::IntegrationType.connection_type, null: true
2021-04-29 21:17:54 +05:30
def resolve(id: nil)
if id
integrations_by(gid: id)
else
http_integrations + prometheus_integrations
end
2021-01-29 00:20:46 +05:30
end
private
2021-04-29 21:17:54 +05:30
def integrations_by(gid:)
object = GitlabSchema.object_from_id(gid, expected_type: expected_integration_types)
defer { object }.then do |integration|
ret = integration if project == integration&.project
Array.wrap(ret)
end
end
2021-01-29 00:20:46 +05:30
def prometheus_integrations
2021-04-29 21:17:54 +05:30
return [] unless prometheus_integrations_allowed?
2021-01-29 00:20:46 +05:30
2021-09-30 23:02:18 +05:30
Array(project.prometheus_integration)
2021-01-29 00:20:46 +05:30
end
def http_integrations
2021-04-29 21:17:54 +05:30
return [] unless http_integrations_allowed?
2021-01-29 00:20:46 +05:30
::AlertManagement::HttpIntegrationsFinder.new(project, {}).execute
end
2021-04-29 21:17:54 +05:30
def prometheus_integrations_allowed?
Ability.allowed?(current_user, :admin_project, project)
end
def http_integrations_allowed?
Ability.allowed?(current_user, :admin_operations, project)
end
def expected_integration_types
[].tap do |types|
types << ::AlertManagement::HttpIntegration if http_integrations_allowed?
2021-09-30 23:02:18 +05:30
types << ::Integrations::Prometheus if prometheus_integrations_allowed?
2021-04-29 21:17:54 +05:30
end
end
2021-01-29 00:20:46 +05:30
end
end
end