diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-01-10 15:23:22 +0100 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-01-10 15:23:22 +0100 |
commit | cf6258af41cee0638665560509c87bb49135081d (patch) | |
tree | 87f1c1f9ba9ad57573eb6805ae5e98fbc4552939 | |
parent | b44583e9c6a00c689be398fee54b24a6dab019a6 (diff) | |
download | gitlab-ce-cf6258af41cee0638665560509c87bb49135081d.tar.gz |
Fix billing checking
-rw-r--r-- | app/controllers/projects/clusters/gcp_controller.rb | 2 | ||||
-rw-r--r-- | app/services/check_gcp_project_billing_service.rb | 5 | ||||
-rw-r--r-- | app/workers/check_gcp_project_billing_worker.rb | 4 | ||||
-rw-r--r-- | lib/google_api/cloud_platform/client.rb | 4 |
4 files changed, 9 insertions, 6 deletions
diff --git a/app/controllers/projects/clusters/gcp_controller.rb b/app/controllers/projects/clusters/gcp_controller.rb index 659bf8d8f82..e0729c60670 100644 --- a/app/controllers/projects/clusters/gcp_controller.rb +++ b/app/controllers/projects/clusters/gcp_controller.rb @@ -1,7 +1,7 @@ class Projects::Clusters::GcpController < Projects::ApplicationController before_action :authorize_read_cluster! before_action :authorize_google_api, except: [:login] - before_action :authorize_google_project_billing, only: [:new] + before_action :authorize_google_project_billing, only: [:new, :create] before_action :authorize_create_cluster!, only: [:new, :create] before_action :verify_billing, only: [:create] diff --git a/app/services/check_gcp_project_billing_service.rb b/app/services/check_gcp_project_billing_service.rb index 854adf2177d..ea82b61b279 100644 --- a/app/services/check_gcp_project_billing_service.rb +++ b/app/services/check_gcp_project_billing_service.rb @@ -2,7 +2,10 @@ class CheckGcpProjectBillingService def execute(token) client = GoogleApi::CloudPlatform::Client.new(token, nil) client.projects_list.select do |project| - client.projects_get_billing_info(project.name).billingEnabled + begin + client.projects_get_billing_info(project.project_id).billing_enabled + rescue + end end end end diff --git a/app/workers/check_gcp_project_billing_worker.rb b/app/workers/check_gcp_project_billing_worker.rb index 557af14ee57..6a0d8ab263f 100644 --- a/app/workers/check_gcp_project_billing_worker.rb +++ b/app/workers/check_gcp_project_billing_worker.rb @@ -23,13 +23,13 @@ class CheckGcpProjectBillingWorker end def self.redis_shared_state_key_for(token) - "gitlab:gcp:#{token.hash}:billing_enabled" + "gitlab:gcp:#{Digest::SHA1.hexdigest(token)}:billing_enabled" end def perform(token_key) return unless token_key - token = self.get_session_token(token_key) + token = self.class.get_session_token(token_key) return unless token return unless try_obtain_lease_for(token) diff --git a/lib/google_api/cloud_platform/client.rb b/lib/google_api/cloud_platform/client.rb index f05d001fd02..a9bea218692 100644 --- a/lib/google_api/cloud_platform/client.rb +++ b/lib/google_api/cloud_platform/client.rb @@ -51,11 +51,11 @@ module GoogleApi end end - def projects_get_billing_info(project_name) + def projects_get_billing_info(project_id) service = Google::Apis::CloudbillingV1::CloudbillingService.new service.authorization = access_token - service.get_project_billing_info("projects/#{project_name}") + service.get_project_billing_info("projects/#{project_id}") end def projects_zones_clusters_get(project_id, zone, cluster_id) |