2022-01-26 12:08:38 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Projects::GoogleCloud::ServiceAccountsController < Projects::GoogleCloud::BaseController
|
|
|
|
before_action :validate_gcp_token!
|
|
|
|
|
|
|
|
def index
|
|
|
|
if gcp_projects.empty?
|
2022-10-11 01:57:18 +05:30
|
|
|
track_event(:error_no_gcp_projects)
|
2022-08-13 15:12:31 +05:30
|
|
|
flash[:warning] = _('No Google Cloud projects - You need at least one Google Cloud project')
|
|
|
|
redirect_to project_google_cloud_configuration_path(project)
|
2022-01-26 12:08:38 +05:30
|
|
|
else
|
2022-05-07 20:08:51 +05:30
|
|
|
js_data = {
|
2022-01-26 12:08:38 +05:30
|
|
|
gcpProjects: gcp_projects,
|
2022-05-07 20:08:51 +05:30
|
|
|
refs: refs,
|
2022-08-13 15:12:31 +05:30
|
|
|
cancelPath: project_google_cloud_configuration_path(project)
|
2022-05-07 20:08:51 +05:30
|
|
|
}
|
2023-01-13 00:05:48 +05:30
|
|
|
@js_data = Gitlab::Json.dump(js_data)
|
2022-05-07 20:08:51 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
track_event(:render_form)
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
rescue Google::Apis::Error => e
|
|
|
|
track_event(:error_google_api)
|
2022-08-27 11:52:29 +05:30
|
|
|
flash[:warning] = _('Google Cloud Error - %{error}') % { error: e }
|
2022-08-13 15:12:31 +05:30
|
|
|
redirect_to project_google_cloud_configuration_path(project)
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2022-05-07 20:08:51 +05:30
|
|
|
permitted_params = params.permit(:gcp_project, :ref)
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
response = GoogleCloud::CreateServiceAccountsService.new(
|
|
|
|
project,
|
|
|
|
current_user,
|
|
|
|
google_oauth2_token: token_in_session,
|
2022-05-07 20:08:51 +05:30
|
|
|
gcp_project_id: permitted_params[:gcp_project],
|
|
|
|
environment_name: permitted_params[:ref]
|
2022-03-02 08:16:31 +05:30
|
|
|
).execute
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
track_event(:create_service_account)
|
2022-08-13 15:12:31 +05:30
|
|
|
redirect_to project_google_cloud_configuration_path(project), notice: response.message
|
2022-10-11 01:57:18 +05:30
|
|
|
rescue Google::Apis::Error => e
|
|
|
|
track_event(:error_google_api)
|
2022-08-27 11:52:29 +05:30
|
|
|
flash[:warning] = _('Google Cloud Error - %{error}') % { error: e }
|
2022-08-13 15:12:31 +05:30
|
|
|
redirect_to project_google_cloud_configuration_path(project)
|
2022-01-26 12:08:38 +05:30
|
|
|
end
|
|
|
|
end
|