Class: Flydata::Credentials

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/flydata/credentials.rb

Constant Summary

Constants included from Helpers

Helpers::UNIT_PREFIX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

as_size, development?, env_mode, env_suffix, flydata_api_host_file, flydata_conf_file, flydata_version, format_menu_list, retry_on, to_command_class, usage_text

Constructor Details

#initializeCredentials

Returns a new instance of Credentials.


7
8
9
# File 'lib/flydata/credentials.rb', line 7

def initialize
  read_credentials
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token


6
7
8
# File 'lib/flydata/credentials.rb', line 6

def token
  @token
end

Instance Method Details

#authenticate!Object


10
11
12
# File 'lib/flydata/credentials.rb', line 10

def authenticate!
  @authenticated = true
end

#authenticated?Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/flydata/credentials.rb', line 13

def authenticated?
  @authenticated
end

#read_credentialsObject


26
27
28
29
30
31
32
33
34
35
# File 'lib/flydata/credentials.rb', line 26

def read_credentials
  if FileTest.exist?(credentials_file)
    File.open(credentials_file, 'r') do |f|
      @token = f.gets.chomp
      @authenticated = true if @token
    end
  else
    @token = nil
  end
end

#write_credentials(token) ⇒ Object


16
17
18
19
20
21
22
23
24
25
# File 'lib/flydata/credentials.rb', line 16

def write_credentials(token)
  dir = File.dirname(credentials_file)
  FileUtils.mkdir_p(dir)
  File.delete(credentials_file) if FileTest.exists?(credentials_file)
  File.open(credentials_file, 'w', 0400) do |out|
 out.puts token
  end
  FileUtils.chmod(0700, dir)
  @token = token
end