diff options
Diffstat (limited to 'app/services/google_cloud/service_accounts_service.rb')
-rw-r--r-- | app/services/google_cloud/service_accounts_service.rb | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/app/services/google_cloud/service_accounts_service.rb b/app/services/google_cloud/service_accounts_service.rb index a512b27493d..3014daf08e2 100644 --- a/app/services/google_cloud/service_accounts_service.rb +++ b/app/services/google_cloud/service_accounts_service.rb @@ -27,39 +27,42 @@ module GoogleCloud end end - def add_for_project(environment, gcp_project_id, service_account, service_account_key) + def add_for_project(environment, gcp_project_id, service_account, service_account_key, is_protected) project_var_create_or_replace( environment, 'GCP_PROJECT_ID', - gcp_project_id + gcp_project_id, + is_protected ) project_var_create_or_replace( environment, 'GCP_SERVICE_ACCOUNT', - service_account + service_account, + is_protected ) project_var_create_or_replace( environment, 'GCP_SERVICE_ACCOUNT_KEY', - service_account_key + service_account_key, + is_protected ) end private def group_vars_by_environment - filtered_vars = @project.variables.filter { |variable| GCP_KEYS.include? variable.key } + filtered_vars = project.variables.filter { |variable| GCP_KEYS.include? variable.key } filtered_vars.each_with_object({}) do |variable, grouped| grouped[variable.environment_scope] ||= {} grouped[variable.environment_scope][variable.key] = variable.value end end - def project_var_create_or_replace(environment_scope, key, value) + def project_var_create_or_replace(environment_scope, key, value, is_protected) params = { key: key, filter: { environment_scope: environment_scope } } - existing_variable = ::Ci::VariablesFinder.new(@project, params).execute.first + existing_variable = ::Ci::VariablesFinder.new(project, params).execute.first existing_variable.destroy if existing_variable - @project.variables.create!(key: key, value: value, environment_scope: environment_scope, protected: true) + project.variables.create!(key: key, value: value, environment_scope: environment_scope, protected: is_protected) end end end |