class Google::Auth::GCECredentials

the GCE metadata server.
Extends Signet::OAuth2::Client so that the auth token is obtained from

def build_token_hash body, content_type, retrieval_time

def build_token_hash body, content_type, retrieval_time
  hash =
    if ["text/html", "application/text"].include? content_type
      { token_type.to_s => body }
    else
      Signet::OAuth2.parse_credentials body, content_type
    end
  universe_domain = Google::Cloud.env.lookup_metadata "universe", "universe_domain"
  universe_domain = "googleapis.com" if !universe_domain || universe_domain.empty?
  hash["universe_domain"] = universe_domain.strip
  # The response might have been cached, which means expires_in might be
  # stale. Update it based on the time since the data was retrieved.
  # We also ensure expires_in is conservative; subtracting at least 1
  # second to offset any skew from metadata server latency.
  if hash["expires_in"].is_a? Numeric
    offset = 1 + (Process.clock_gettime(Process::CLOCK_MONOTONIC) - retrieval_time).round
    hash["expires_in"] -= offset if offset.positive?
    hash["expires_in"] = 0 if hash["expires_in"].negative?
  end
  hash
end

def compute_auth_token_uri

Other tags:
    Private: - Unused and deprecated
def compute_auth_token_uri
  "#{compute_check_uri}/computeMetadata/v1/instance/service-accounts/default/token".freeze
end

def compute_check_uri

Other tags:
    Private: - Unused and deprecated
def compute_check_uri
  "http://#{metadata_host}".freeze
end

def compute_id_token_uri

Other tags:
    Private: - Unused and deprecated
def compute_id_token_uri
  "#{compute_check_uri}/computeMetadata/v1/instance/service-accounts/default/identity".freeze
end

def fetch_access_token _options = {}

fetched.
Overrides the super class method to change how access tokens are
def fetch_access_token _options = {}
  if token_type == :id_token
    query = { "audience" => target_audience, "format" => "full" }
    entry = "service-accounts/default/identity"
  else
    query = {}
    entry = "service-accounts/default/token"
  end
  query[:scopes] = Array(scope).join "," if scope
  begin
    resp = Google::Cloud.env.lookup_metadata_response "instance", entry, query: query
    case resp.status
    when 200
      build_token_hash resp.body, resp.headers["content-type"], resp.retrieval_monotonic_time
    when 403, 500
      msg = "Unexpected error code #{resp.status} #{UNEXPECTED_ERROR_SUFFIX}"
      raise Signet::UnexpectedStatusError, msg
    when 404
      raise Signet::AuthorizationError, NO_METADATA_SERVER_ERROR
    else
      msg = "Unexpected error code #{resp.status} #{UNEXPECTED_ERROR_SUFFIX}"
      raise Signet::AuthorizationError, msg
    end
  rescue Google::Cloud::Env::MetadataServerNotResponding => e
    raise Signet::AuthorizationError, e.message
  end
end

def metadata_host

Other tags:
    Private: - Unused and deprecated
def metadata_host
  ENV.fetch "GCE_METADATA_HOST", DEFAULT_METADATA_HOST
end

def on_gce? _options = {}, _reload = false # rubocop:disable Style/OptionalBooleanParameter

rubocop:disable Style/OptionalBooleanParameter
The parameters are deprecated and unused.
is available.
Detect if this appear to be a GCE instance, by checking if metadata
def on_gce? _options = {}, _reload = false # rubocop:disable Style/OptionalBooleanParameter
  Google::Cloud.env.metadata?
end

def reset_cache

def reset_cache
  Google::Cloud.env.compute_metadata.reset_existence!
  Google::Cloud.env.compute_metadata.cache.expire_all!
end