Sha256: 4a49a8aaed41dcef9f9e3ec8bd2133e8fdf8ee5e58e3d9b9c79918a3a81c2ac2

Contents?: true

Size: 895 Bytes

Versions: 1

Compression:

Stored size: 895 Bytes

Contents

require 'thor'
require 'sconb'
require 'toml'
require 'timeout'

module SshConfigToVulsConfig
  class CLI < Thor
    default_command :convert

    desc 'convert', 'ssh_config to vuls config.toml'
    def convert
      begin
        stdin = timeout(1) { $stdin.read }
      rescue Timeout::Error
      end
      parsed = Sconb::SSHConfig.parse(stdin)
      config = { servers: {} }
      parsed.each do |host, detail|
        next if host =~ /\*/
        next if detail.key?('Match')
        next unless detail.key?('Host')
        next unless detail.key?('IdentityFile')
        key_path = File.expand_path(detail['IdentityFile'].first)
        config[:servers][detail['Host']] = {
          host: detail['Hostname'],
          user: detail['User'] || 'root',
          port: detail['Port'] || '22',
          keyPath: key_path
        }
      end
      puts TOML.dump(config)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ssh_config_to_vuls_config-0.1.1 lib/ssh_config_to_vuls_config/cli.rb