debian-mirror-gitlab/app/services/clusters/integrations/create_service.rb

47 lines
1.3 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
module Clusters
module Integrations
class CreateService < BaseContainerService
attr_accessor :cluster
def initialize(container:, cluster:, current_user: nil, params: {})
@cluster = cluster
super(container: container, current_user: current_user, params: params)
end
def execute
return ServiceResponse.error(message: 'Unauthorized') unless authorized?
integration.enabled = params[:enabled]
integration.save!
if integration.enabled?
ServiceResponse.success(message: s_('ClusterIntegration|Integration enabled'), payload: { integration: integration })
else
ServiceResponse.success(message: s_('ClusterIntegration|Integration disabled'), payload: { integration: integration })
end
end
private
def integration
2021-06-08 01:23:25 +05:30
@integration ||= \
case params[:application_type]
when 'prometheus'
cluster.find_or_build_integration_prometheus
when 'elastic_stack'
cluster.find_or_build_integration_elastic_stack
else
raise ArgumentError, "invalid application_type: #{params[:application_type]}"
end
2021-04-29 21:17:54 +05:30
end
def authorized?
Ability.allowed?(current_user, :admin_cluster, cluster)
end
end
end
end