Class: GoogleCloud::GcpRegionAddOrReplaceService

Inherits:
BaseService show all
Defined in:
app/services/google_cloud/gcp_region_add_or_replace_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

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

This class inherits a constructor from BaseService

Instance Method Details

#execute(environment, region) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/services/google_cloud/gcp_region_add_or_replace_service.rb', line 5

def execute(environment, region)
  gcp_region_key = Projects::GoogleCloud::GcpRegionsController::GCP_REGION_CI_VAR_KEY

  change_params = { variable_params: { key: gcp_region_key, value: region, environment_scope: environment } }
  filter_params = { key: gcp_region_key, filter: { environment_scope: environment } }

  existing_variable = ::Ci::VariablesFinder.new(project, filter_params).execute.first

  if existing_variable
    change_params[:action] = :update
    change_params[:variable] = existing_variable
  else
    change_params[:action] = :create
  end

  ::Ci::ChangeVariableService.new(container: project, current_user: current_user, params: change_params).execute
end