Class: SshKeyMan::AliasGen

Inherits:
Object
  • Object
show all
Defined in:
lib/alias_gen.rb

Class Method Summary collapse

Class Method Details

.generate(user) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/alias_gen.rb', line 5

def self.generate user
  server_list_path = File.join(".", "server_list.yml")
  servers = YAML::load_file(server_list_path)['servers']
  groups = get_user_groups(user)

  puts "\e[31m You can copy below code to '~/.bash_profile' or '~/.bashrc'. \e[0m"
  puts "============================================="
  groups.each do |group|
    servers[group].each do |server|
      puts "alias #{group}_#{server['alias']}=\"#{server['user']}@#{server['host']}\""
    end
  end
  puts "============================================="
end

.get_user_groups(user) ⇒ Object



20
21
22
23
24
# File 'lib/alias_gen.rb', line 20

def self.get_user_groups user
  user_groups = `cd available_public_keys; find . -name #{user}`.split("\n")      
  raise "Not found user: \"#{user}\"" if user_groups.size == 0
  user_groups.map { |user_group| user_group.slice(/[^\.\/]+(?=\/)/) }
end