Commit cf6258af authored by Kamil Trzciński's avatar Kamil Trzciński

Fix billing checking

parent b44583e9
class Projects::Clusters::GcpController < Projects::ApplicationController class Projects::Clusters::GcpController < Projects::ApplicationController
before_action :authorize_read_cluster! before_action :authorize_read_cluster!
before_action :authorize_google_api, except: [:login] 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 :authorize_create_cluster!, only: [:new, :create]
before_action :verify_billing, only: [:create] before_action :verify_billing, only: [:create]
......
...@@ -2,7 +2,10 @@ class CheckGcpProjectBillingService ...@@ -2,7 +2,10 @@ class CheckGcpProjectBillingService
def execute(token) def execute(token)
client = GoogleApi::CloudPlatform::Client.new(token, nil) client = GoogleApi::CloudPlatform::Client.new(token, nil)
client.projects_list.select do |project| 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 end
end end
...@@ -23,13 +23,13 @@ class CheckGcpProjectBillingWorker ...@@ -23,13 +23,13 @@ class CheckGcpProjectBillingWorker
end end
def self.redis_shared_state_key_for(token) def self.redis_shared_state_key_for(token)
"gitlab:gcp:#{token.hash}:billing_enabled" "gitlab:gcp:#{Digest::SHA1.hexdigest(token)}:billing_enabled"
end end
def perform(token_key) def perform(token_key)
return unless 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 token
return unless try_obtain_lease_for(token) return unless try_obtain_lease_for(token)
......
...@@ -51,11 +51,11 @@ module GoogleApi ...@@ -51,11 +51,11 @@ module GoogleApi
end end
end end
def projects_get_billing_info(project_name) def projects_get_billing_info(project_id)
service = Google::Apis::CloudbillingV1::CloudbillingService.new service = Google::Apis::CloudbillingV1::CloudbillingService.new
service.authorization = access_token service.authorization = access_token
service.get_project_billing_info("projects/#{project_name}") service.get_project_billing_info("projects/#{project_id}")
end end
def projects_zones_clusters_get(project_id, zone, cluster_id) def projects_zones_clusters_get(project_id, zone, cluster_id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment