module Google::Auth::CredentialsLoader
def from_env(scope)
-
scope(string|array) -- the scope(s) to access
def from_env(scope) return nil unless ENV.key?(ENV_VAR) path = ENV[ENV_VAR] fail 'file #{path} does not exist' unless File.exist?(path) File.open(path) do |f| return make_creds(scope, f) end rescue StandardError => e raise "#{NOT_FOUND_ERROR}: #{e}" end
def from_well_known_path(scope)
-
scope(string|array) -- the scope(s) to access
def from_well_known_path(scope) home_var, base = windows? ? 'APPDATA' : 'HOME', WELL_KNOWN_PATH root = ENV[home_var].nil? ? '' : ENV[home_var] base = File.join('.config', base) unless windows? path = File.join(root, base) return nil unless File.exist?(path) File.open(path) do |f| return make_creds(scope, f) end rescue StandardError => e raise "#{WELL_KNOWN_ERROR}: #{e}" end
def make_creds(*args)
By default, it calls #new on the current class, but this behaviour can
make_creds proxies the construction of a credentials instance
def make_creds(*args) new(*args) end
def windows?
def windows? RbConfig::CONFIG['host_os'] =~ /Windows|mswin/ end