Class: Clusters::Integrations::CreateService

Inherits:
BaseContainerService show all
Defined in:
app/services/clusters/integrations/create_service.rb

Instance Attribute Summary collapse

Attributes inherited from BaseContainerService

#container, #current_user, #group, #params, #project

Instance Method Summary collapse

Methods inherited from BaseContainerService

#group_container?, #namespace_container?, #project_container?, #project_group

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

#initialize(container:, cluster:, current_user: nil, params: {}) ⇒ CreateService

Returns a new instance of CreateService.



8
9
10
11
12
# File 'app/services/clusters/integrations/create_service.rb', line 8

def initialize(container:, cluster:, current_user: nil, params: {})
  @cluster = cluster

  super(container: container, current_user: current_user, params: params)
end

Instance Attribute Details

#clusterObject

Returns the value of attribute cluster.



6
7
8
# File 'app/services/clusters/integrations/create_service.rb', line 6

def cluster
  @cluster
end

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/clusters/integrations/create_service.rb', line 14

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