Class: Google::Auth::GCECredentials
- Inherits:
-
Signet::OAuth2::Client
- Object
- Signet::OAuth2::Client
- Google::Auth::GCECredentials
- Defined in:
- lib/googleauth/compute_engine.rb
Overview
Extends Signet::OAuth2::Client so that the auth token is obtained from the GCE metadata server.
Constant Summary
Constants included from BaseClient
Instance Attribute Summary
Attributes included from BaseClient
Class Method Summary collapse
-
.on_gce?(_options = {}, _reload = false) ⇒ Boolean
Detect if this appear to be a GCE instance, by checking if metadata is available.
- .reset_cache ⇒ Object (also: unmemoize_all)
Instance Method Summary collapse
-
#duplicate(options = {}) ⇒ Object
Creates a duplicate of these credentials without the Signet::OAuth2::Client-specific transient state (e.g. cached tokens).
-
#fetch_access_token(_options = {}) ⇒ Hash
Overrides the super class method to change how access tokens are fetched.
-
#initialize(options = {}) ⇒ GCECredentials
constructor
Construct a GCECredentials.
-
#update!(options = {}) ⇒ Google::Auth::GCECredentials
Destructively updates these credentials.
Methods inherited from Signet::OAuth2::Client
#build_default_connection, #configure_connection, #fetch_access_token!, #generate_access_token_request, #googleauth_orig_generate_access_token_request, #orig_fetch_access_token!, #retry_with_error, #token_type, #update_signet_base, #update_token!, #update_token_signet_base
Methods included from BaseClient
#apply, #apply!, #expires_within?, #needs_access_token?, #notify_refresh_listeners, #on_refresh, #updater_proc
Constructor Details
#initialize(options = {}) ⇒ GCECredentials
Construct a GCECredentials
88 89 90 91 92 93 94 95 |
# File 'lib/googleauth/compute_engine.rb', line 88 def initialize = {} # Override the constructor to remember whether the universe domain was # overridden by a constructor argument. @universe_domain_overridden = ["universe_domain"] || [:universe_domain] # TODO: Remove when universe domain metadata endpoint is stable (see b/349488459). @disable_universe_domain_check = true super end |
Class Method Details
.on_gce?(_options = {}, _reload = false) ⇒ Boolean
Detect if this appear to be a GCE instance, by checking if metadata is available. The parameters are deprecated and unused.
73 74 75 |
# File 'lib/googleauth/compute_engine.rb', line 73 def on_gce? = {}, _reload = false # rubocop:disable Style/OptionalBooleanParameter Google::Cloud.env. end |
Instance Method Details
#duplicate(options = {}) ⇒ Object
Creates a duplicate of these credentials without the Signet::OAuth2::Client-specific transient state (e.g. cached tokens)
106 107 108 109 110 111 112 113 |
# File 'lib/googleauth/compute_engine.rb', line 106 def duplicate = {} = deep_hash_normalize super( { universe_domain_overridden: @universe_domain_overridden }.merge() ) end |
#fetch_access_token(_options = {}) ⇒ Hash
Overrides the super class method to change how access tokens are fetched.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/googleauth/compute_engine.rb', line 135 def fetch_access_token = {} query, entry = begin log_fetch_query resp = Google::Cloud.env. "instance", entry, query: query log_fetch_resp resp resp rescue Google::Cloud::Env::MetadataServerNotResponding => e log_fetch_err e raise AuthorizationError.with_details( e., credential_type_name: self.class.name, principal: principal ) end end |
#update!(options = {}) ⇒ Google::Auth::GCECredentials
Destructively updates these credentials.
This method is called by Signet::OAuth2::Client
's constructor
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/googleauth/compute_engine.rb', line 162 def update! = {} # Normalize all keys to symbols to allow indifferent access. = deep_hash_normalize @universe_domain_overridden = [:universe_domain_overridden] if .key? :universe_domain_overridden super() self end |