debian-mirror-gitlab/app/controllers/projects/google_cloud_controller.rb

35 lines
1.4 KiB
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# frozen_string_literal: true
2022-01-26 12:08:38 +05:30
class Projects::GoogleCloudController < Projects::GoogleCloud::BaseController
2022-05-07 20:08:51 +05:30
GCP_REGION_CI_VAR_KEY = 'GCP_REGION'
2021-11-18 22:05:49 +05:30
def index
2022-05-07 20:08:51 +05:30
js_data = {
2022-01-26 12:08:38 +05:30
screen: 'home',
2021-12-11 22:18:48 +05:30
serviceAccounts: GoogleCloud::ServiceAccountsService.new(project).find_for_project,
2022-01-26 12:08:38 +05:30
createServiceAccountUrl: project_google_cloud_service_accounts_path(project),
2022-04-04 11:22:00 +05:30
enableCloudRunUrl: project_google_cloud_deployments_cloud_run_path(project),
enableCloudStorageUrl: project_google_cloud_deployments_cloud_storage_path(project),
2022-05-07 20:08:51 +05:30
emptyIllustrationUrl: ActionController::Base.helpers.image_path('illustrations/pipelines_empty.svg'),
configureGcpRegionsUrl: project_google_cloud_gcp_regions_path(project),
gcpRegions: gcp_regions,
revokeOauthUrl: revoke_oauth_url
}
@js_data = js_data.to_json
track_event('google_cloud#index', 'index', js_data)
end
private
def gcp_regions
list = ::Ci::VariablesFinder.new(project, { key: GCP_REGION_CI_VAR_KEY }).execute
list.map { |variable| { gcp_region: variable.value, environment: variable.environment_scope } }
end
def revoke_oauth_url
google_token_valid = GoogleApi::CloudPlatform::Client.new(token_in_session, nil)
.validate_token(expires_at_in_session)
google_token_valid ? project_google_cloud_revoke_oauth_index_path(project) : nil
2021-11-18 22:05:49 +05:30
end
end