Class: Flydata::Credentials

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

development?, env_mode, env_suffix, flydata_api_host_file, flydata_conf_file, format_menu_list, parse_command, print_usage, retry_on, to_command_class, usage_text

Constructor Details

#initializeCredentials

Returns a new instance of Credentials.



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

def initialize
  read_credentials
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



4
5
6
# File 'lib/flydata/credentials.rb', line 4

def token
  @token
end

Instance Method Details

#authenticate!Object



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

def authenticate!
  @authenticated = true
end

#authenticated?Boolean

Returns:

  • (Boolean)


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

def authenticated?
  @authenticated
end

#read_credentialsObject



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

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



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

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