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