Class: Credential

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/credential.rb

Constant Summary collapse

FILE_PATH =
"#{ENV['HOME']}/.rncher"

Class Method Summary collapse

Class Method Details

.access_keyObject



17
18
19
# File 'lib/resources/credential.rb', line 17

def self.access_key
  self.exists? ? self.load_credentials['default']['access_key'] : nil
end

.envObject



29
30
31
# File 'lib/resources/credential.rb', line 29

def self.env
  self.exists? ? self.load_credentials['default']['env'] : nil
end

.exists?Boolean

Returns:

  • (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

.hostObject



25
26
27
# File 'lib/resources/credential.rb', line 25

def self.host
  self.exists? ? self.load_credentials['default']['host'] : nil
end

.load_credentialsObject



4
5
6
# File 'lib/resources/credential.rb', line 4

def self.load_credentials
  @attributes ||= JSON.parse(File.read(FILE_PATH))
end

.secret_keyObject



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