Class: Rundock::Configure

Inherits:
Object show all
Defined in:
lib/rundock/configure.rb

Constant Summary collapse

CONFIGURE_TYPE =
%i[ssh]
CONFIGURE_SSH_OPTIONS =
%i[port user keys passphrase ssh_config]
CONFIGURE_SSH_OPTIONS_QUESTION =
[
  'ssh port',
  'user name',
  'private key path',
  'private key passphrase',
  'ssh config file path'
]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Configure

Returns a new instance of Configure.



27
28
29
# File 'lib/rundock/configure.rb', line 27

def initialize(options)
  @options = options
end

Class Method Details

.start(options) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/rundock/configure.rb', line 17

def start(options)
  Logger.debug 'Starting Configure:'

  configure = self.new(options)
  CONFIGURE_TYPE.each do |type|
    configure.send(type) if options[type]
  end
end

Instance Method Details

#sshObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rundock/configure.rb', line 31

def ssh
  cli = HighLine.new
  ssh_opts = { paranoid: false }

  CONFIGURE_SSH_OPTIONS.each_with_index do |opt, i|
    ans = if opt == :port
            cli.ask("#{CONFIGURE_SSH_OPTIONS_QUESTION[i]}:", Integer) { |q| q.in = 0..65535 }
          elsif opt == :user
            cli.ask("#{CONFIGURE_SSH_OPTIONS_QUESTION[i]}:") { |q| q.default = ENV['USER'] }
          elsif opt == :keys
            [cli.ask("#{CONFIGURE_SSH_OPTIONS_QUESTION[i]}:") { |q| q.default = '~/.ssh/id_rsa' }]
          elsif opt == :passphrase
            cli.ask("#{CONFIGURE_SSH_OPTIONS_QUESTION[i]}:") { |q| q.echo = '*' }
          elsif opt == :ssh_config
            cli.ask("#{CONFIGURE_SSH_OPTIONS_QUESTION[i]}:") { |q| q.default = '~/.ssh/config' }
          else
            cli.ask("#{CONFIGURE_SSH_OPTIONS_QUESTION[i]}:")
          end

    ssh_opts[opt] = ans unless ans.blank?
  end

  YAML.dump(ssh_opts, File.open(@options[:ssh_config_path], 'w'))
end