Class: Gcloud::Credentials
- Inherits:
-
Object
- Object
- Gcloud::Credentials
- Extended by:
- Forwardable
- Defined in:
- lib/gcloud/credentials.rb
Overview
Represents the Oauth2 signing logic. This class is intended to be inherited by API-specific classes which overrides the SCOPE constant.
Direct Known Subclasses
Constant Summary collapse
- TOKEN_CREDENTIAL_URI =
:nodoc:
"https://accounts.google.com/o/oauth2/token"- AUDIENCE =
"https://accounts.google.com/o/oauth2/token"- SCOPE =
[]
- ENV_VARS =
["GOOGLE_CLOUD_KEYFILE"]
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
-
.default ⇒ Object
Returns the default credentials.
-
.sdk_default_creds ⇒ Object
The filepath of the default application credentials used by the gcloud SDK.
Instance Method Summary collapse
-
#initialize(keyfile, options = {}) ⇒ Credentials
constructor
A new instance of Credentials.
Constructor Details
#initialize(keyfile, options = {}) ⇒ Credentials
Returns a new instance of Credentials.
40 41 42 43 44 45 46 47 |
# File 'lib/gcloud/credentials.rb', line 40 def initialize keyfile, = {} if keyfile.is_a? Signet::OAuth2::Client @client = keyfile else @client = init_client keyfile, end @client.fetch_access_token! end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
31 32 33 |
# File 'lib/gcloud/credentials.rb', line 31 def client @client end |
Class Method Details
.default ⇒ Object
Returns the default credentials.
52 53 54 55 56 57 58 59 60 |
# File 'lib/gcloud/credentials.rb', line 52 def self.default self::ENV_VARS.each do |env_var| keyfile = ENV[env_var].to_s return new keyfile if ::File.file? keyfile end return new sdk_default_creds if ::File.file? sdk_default_creds client = Google::Auth.get_application_default self::SCOPE new client end |
.sdk_default_creds ⇒ Object
The filepath of the default application credentials used by the gcloud SDK.
This file is created when running gcloud auth login
67 68 69 70 71 72 |
# File 'lib/gcloud/credentials.rb', line 67 def self.sdk_default_creds #:nodoc: # This method will likely be moved once we gain better # support for running in a GCE environment. sdk_creds = "~/.config/gcloud/application_default_credentials.json" File. sdk_creds end |