Module: Collins::Authenticator

Defined in:
lib/collins_auth.rb

Class Method Summary collapse

Class Method Details

.load_config(options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/collins_auth.rb', line 16

def self.load_config(options = {})
  conf = (options[:prompt] == :only) ? {} : (read_config(options[:config_file]) || {}).merge(options)

  # check if we have all that we expect
  if [:username, :password, :host].all? {|key| conf.keys.include? key}
    return conf
  end

  # Something is missing. Can we prompt for it?
  if options[:prompt]
    conf.merge!(prompt_creds(conf))
  else
    raise "could not load any valid configuration."
  end

  conf
end

.setup_client(options = {:prompt => false}) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/collins_auth.rb', line 8

def self.setup_client(options = {:prompt => false})
  if options[:config_file] and not File.readable? options[:config_file]
    raise 'unable to read invalid config file: ' + options[:config_file]
  end

  Collins::Client.new load_config(options)
end