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 (either name or number) from str and returns it (as a string) on success, or nil on failure.
-
.project_id ⇒ Object
Determine the project ID from the credentials, if possible.
Class Method Details
.extract_project_id(str) ⇒ Object
Extracts the project id (either name or number) from str and returns it (as a string) on success, or nil on failure.
Recognizes IAM format ([email protected]) as well as the legacy format with a project number at the front of the string, terminated by a dash (-) which is not part of the ID, i.e.: 270694816269-1l1r2hb813leuppurdeik0apglbs80sv.apps.googleusercontent.com
736 737 738 739 740 741 742 743 |
# File 'lib/fluent/plugin/out_google_cloud.rb', line 736 def self.extract_project_id(str) [/^.*@(?<project_id>.+)\.iam\.gserviceaccount\.com/, /^(?<project_id>\d+)-/].each do |exp| match_data = exp.match(str) return match_data['project_id'] unless match_data.nil? end 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.
716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/fluent/plugin/out_google_cloud.rb', line 716 def self.project_id 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 |