Module: Fluent::GoogleCloudOutput::CredentialsInfo
- Defined in:
- lib/fluent/plugin/out_google_cloud.rb
Overview
TODO: This functionality should eventually be available in another library, but implement it ourselves for now.
Class Method Summary collapse
-
.extract_project_id(str) ⇒ Object
Extracts the project id from str.
-
.project_id ⇒ Object
Determine the project ID from the credentials, if possible.
Class Method Details
.extract_project_id(str) ⇒ Object
Extracts the project id from str. Assumes the project ID is at the front of str, and consists of a string of digits terminated by a dash (-) which is not part of the project ID. Example: 270694816269-1l1r2hb813leuppurdeik0apglbs80sv.apps.googleusercontent.com Returns the project ID (as a string) on success, or nil on failure.
604 605 606 607 608 |
# File 'lib/fluent/plugin/out_google_cloud.rb', line 604 def self.extract_project_id(str) @project_regexp = /^(?<project_id>\d+)-/ match_data = @project_regexp.match(str) match_data ? match_data['project_id'] : nil end |
.project_id ⇒ Object
Determine the project ID from the credentials, if possible. Returns the project ID (as a string) on success, or nil on failure.
585 586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/fluent/plugin/out_google_cloud.rb', line 585 def self.project_id return nil if @auth_method == 'private_key' creds = Google::Auth.get_application_default(LOGGING_SCOPE) if creds.issuer id = extract_project_id(creds.issuer) return id unless id.nil? end if creds.client_id id = extract_project_id(creds.client_id) return id unless id.nil? end nil end |