Class: Credential
- Inherits:
-
Object
- Object
- Credential
- Defined in:
- lib/resources/credential.rb
Constant Summary collapse
- FILE_PATH =
"#{ENV['HOME']}/.rncher"
Class Method Summary collapse
- .access_key ⇒ Object
- .env ⇒ Object
- .exists? ⇒ Boolean
- .host ⇒ Object
- .load_credentials ⇒ Object
- .secret_key ⇒ Object
- .set_credentials(attributes) ⇒ Object
Class Method Details
.access_key ⇒ Object
17 18 19 |
# File 'lib/resources/credential.rb', line 17 def self.access_key self.exists? ? self.load_credentials['default']['access_key'] : nil end |
.env ⇒ Object
29 30 31 |
# File 'lib/resources/credential.rb', line 29 def self.env self.exists? ? self.load_credentials['default']['env'] : nil end |
.exists? ⇒ Boolean
8 9 10 11 12 13 14 15 |
# File 'lib/resources/credential.rb', line 8 def self.exists? begin JSON.parse(File.read(FILE_PATH)) true rescue false end end |
.host ⇒ Object
25 26 27 |
# File 'lib/resources/credential.rb', line 25 def self.host self.exists? ? self.load_credentials['default']['host'] : nil end |
.load_credentials ⇒ Object
4 5 6 |
# File 'lib/resources/credential.rb', line 4 def self.load_credentials @attributes ||= JSON.parse(File.read(FILE_PATH)) end |
.secret_key ⇒ Object
21 22 23 |
# File 'lib/resources/credential.rb', line 21 def self.secret_key self.exists? ? self.load_credentials['default']['secret_key'] : nil end |
.set_credentials(attributes) ⇒ Object
33 34 35 |
# File 'lib/resources/credential.rb', line 33 def self.set_credentials(attributes) File.open(FILE_PATH, 'w') {|f| f.write(attributes.to_json) } end |