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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/clusters/integrations/create_service.rb')
-rw-r--r--app/services/clusters/integrations/create_service.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/app/services/clusters/integrations/create_service.rb b/app/services/clusters/integrations/create_service.rb
new file mode 100644
index 00000000000..f9e9dd3e457
--- /dev/null
+++ b/app/services/clusters/integrations/create_service.rb
@@ -0,0 +1,43 @@
+# 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
+ case params[:application_type]
+ when 'prometheus'
+ cluster.find_or_build_integration_prometheus
+ else
+ raise ArgumentError, "invalid application_type: #{params[:application_type]}"
+ end
+ end
+
+ def authorized?
+ Ability.allowed?(current_user, :admin_cluster, cluster)
+ end
+ end
+ end
+end