File: service_accounts_controller.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (45 lines) | stat: -rw-r--r-- 1,556 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true

class Projects::GoogleCloud::ServiceAccountsController < Projects::GoogleCloud::BaseController
  before_action :validate_gcp_token!

  def index
    if gcp_projects.empty?
      track_event(:error_no_gcp_projects)
      flash[:warning] = _('No Google Cloud projects - You need at least one Google Cloud project')
      redirect_to project_google_cloud_configuration_path(project)
    else
      js_data = {
        gcpProjects: gcp_projects,
        refs: refs,
        cancelPath: project_google_cloud_configuration_path(project)
      }
      @js_data = Gitlab::Json.dump(js_data)

      track_event(:render_form)
    end
  rescue Google::Apis::Error => e
    track_event(:error_google_api)
    flash[:warning] = _('Google Cloud Error - %{error}') % { error: e }
    redirect_to project_google_cloud_configuration_path(project)
  end

  def create
    permitted_params = params.permit(:gcp_project, :ref)

    response = CloudSeed::GoogleCloud::CreateServiceAccountsService.new(
      project,
      current_user,
      google_oauth2_token: token_in_session,
      gcp_project_id: permitted_params[:gcp_project],
      environment_name: permitted_params[:ref]
    ).execute

    track_event(:create_service_account)
    redirect_to project_google_cloud_configuration_path(project), notice: response.message
  rescue Google::Apis::Error => e
    track_event(:error_google_api)
    flash[:warning] = _('Google Cloud Error - %{error}') % { error: e }
    redirect_to project_google_cloud_configuration_path(project)
  end
end