Module: Ci::Go::Access

Defined in:
lib/ci-go-nfo/go_info.rb

Class Method Summary collapse

Class Method Details

.configObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ci-go-nfo/go_info.rb', line 21

def self.config
  conf_fyl = config_from
  if File.exists? conf_fyl
    defaults = YAML.load_file conf_fyl
  else
    defaults = persist_config
  end
  defaults = persist_config unless defaults
  baseurl  = defaults['baseurl']
  unless defaults['creds'].nil?
    user     = defaults['creds']['user']
    password = defaults['creds']['pass']
  end
  if baseurl.nil?
    return persist_config_from
  else
    return {'user' => user, 'password' => password, 'baseurl' => baseurl}
  end
end

.config_from(new_file = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ci-go-nfo/go_info.rb', line 9

def self.config_from(new_file = nil)
  gem = File.join File.expand_path(File.dirname __FILE__), '..', '..'
  gem_res = File.join gem, 'resource', 'config.store'
  if new_file.nil?
    from_file = File.open(gem_res, 'r'){|fyl| fyl.read}
    return from_file.chop.gsub(/^~/,File.expand_path('~'))
  end
  new_file = new_file.chop.gsub(/^~/,File.expand_path('~'))
  File.open(gem_res, 'w'){|fyl| fyl.puts new_file}
  new_file
end

.persist_configObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ci-go-nfo/go_info.rb', line 41

def self.persist_config
  inputs = setup_access
  config_hash = {
                  'baseurl' => inputs['baseurl'],
                  'creds' => {
                              'user' => inputs['user'],
                              'pass' => inputs['password']
                            }
                }
  config_from inputs['config_from'] unless inputs['config_from'].empty?
  File.open(config_from, 'w+') do |conf|
    conf.write( config_hash.to_yaml )
  end

  {
   'baseurl' => inputs['baseurl'],
   'user'    => inputs['user'],
   'pass'    => inputs['password']
  }
end

.setup_accessObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ci-go-nfo/go_info.rb', line 62

def self.setup_access
  ARGV.clear
  print "\nStore sensitive Go Configs in file {current file: #{config_from}}: "
  conf_file = gets.strip
  print "\nEnter Base URL of Go Server {like http://<ip>:8153}: "
  baseurl = gets.strip
  puts "\nThis is better to be ReadOnly account details..."
  print "\nEnter Log-in UserName: "
  user = gets.strip
  print "\nPassword: "
  password = gets.strip
  {'config_from' => conf_file, 'user' => user, 'password' => password, 'baseurl' => baseurl}
end