class Google::Auth::DefaultCredentials
which type of credentials should be loaded.
DefaultCredentials is used to preload the credentials file, to determine
def self.determine_creds_class json_key_io = nil
-
(Google::Auth::InitializationError)- If the JSON is missing the type field or has an unsupported type,
Returns:
-
(Array(Hash, Class))- The JSON key (or nil if from environment) and the credential class to use
Parameters:
-
json_key_io(IO, nil) -- An optional IO object containing the JSON key.
def self.determine_creds_class json_key_io = nil if json_key_io json_key = MultiJson.load json_key_io.read key = "type" raise InitializationError, "the json is missing the '#{key}' field" unless json_key.key? key type = json_key[key] else env_var = CredentialsLoader::ACCOUNT_TYPE_VAR type = ENV[env_var] raise InitializationError, "#{env_var} is undefined in env" unless type json_key = nil end clz = case type when ServiceAccountCredentials::CREDENTIAL_TYPE_NAME ServiceAccountCredentials when UserRefreshCredentials::CREDENTIAL_TYPE_NAME UserRefreshCredentials when ExternalAccount::Credentials::CREDENTIAL_TYPE_NAME ExternalAccount::Credentials when ImpersonatedServiceAccountCredentials::CREDENTIAL_TYPE_NAME ImpersonatedServiceAccountCredentials else raise InitializationError, "credentials type '#{type}' is not supported" end [json_key, clz] end
def self.make_creds options = {}
-
(Google::Auth::InitializationError)- If the credentials cannot be determined
Returns:
-
(Google::Auth::Credentials)- The credentials instance
Parameters:
-
options(Hash) -- Options for creating the credentials
Other tags:
- See: Google::Auth::ServiceAccountCredentials.make_creds -
Deprecated:
- This method is deprecated and will be removed in a future version.
def self.make_creds options = {} json_key_io = options[:json_key_io] json_key, clz = determine_creds_class json_key_io if json_key io = StringIO.new MultiJson.dump(json_key) clz.make_creds options.merge(json_key_io: io) else clz.make_creds options end end