Class: Acquia::Cloud::Credentials
- Inherits:
-
Object
- Object
- Acquia::Cloud::Credentials
- Defined in:
- lib/acquia/cloud/credentials.rb
Overview
This class controls access to Acquia Cloud API credentials.
This class can load data from a few different places. Firstly, you can pass a string of the form “$email:$key”. You can also load a similar string from the environment variable ACQUIA_CLOUD_CREDENTIALS.
As a fallback if none of the above is provided then this class will check the ~/.acquia/cloudapi.conf file. This is the recommended approach for using credentials with this API as this file is shared between many different libraries.
Constant Summary collapse
- CREDENTIALS_FILE =
"#{ENV['HOME']}/.acquia/cloudapi.conf"
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #defined? ⇒ Boolean
-
#initialize(value = nil) ⇒ Credentials
constructor
A new instance of Credentials.
- #inspect ⇒ Object
Constructor Details
#initialize(value = nil) ⇒ Credentials
Returns a new instance of Credentials.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/acquia/cloud/credentials.rb', line 21 def initialize(value = nil) value = ENV['ACQUIA_CLOUD_CREDENTIALS'] if value.nil? if value.nil? if File.exist? CREDENTIALS_FILE creds = YAML.load_file CREDENTIALS_FILE @email = creds['email'] @key = creds['key'] end else vals = value.split(':', 2) @email = vals[0] @key = vals[1] end end |
Instance Attribute Details
#email ⇒ Object (readonly)
Returns the value of attribute email.
18 19 20 |
# File 'lib/acquia/cloud/credentials.rb', line 18 def email @email end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
19 20 21 |
# File 'lib/acquia/cloud/credentials.rb', line 19 def key @key end |
Instance Method Details
#defined? ⇒ Boolean
39 40 41 |
# File 'lib/acquia/cloud/credentials.rb', line 39 def defined? !@email.nil? && !@key.nil? end |
#inspect ⇒ Object
45 46 47 |
# File 'lib/acquia/cloud/credentials.rb', line 45 def inspect old_inspect.gsub(/, @key=".*?"/, '') end |