ssh-key-sync-man 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -11,31 +11,31 @@ Usage
11
11
 
12
12
  2. Put all your team members' keys into one `available_public_keys` directory with the structure looks like:
13
13
 
14
- available_public_keys/groupA/michael
15
- available_public_keys/------/jason
16
- available_public_keys/------/john
17
- available_public_keys/groupB/rose
18
- available_public_keys/------/ryan
14
+ available_public_keys/groupA/michael
15
+ available_public_keys/------/jason
16
+ available_public_keys/------/john
17
+ available_public_keys/groupB/rose
18
+ available_public_keys/------/ryan
19
19
 
20
20
  3. Add a `server_list.yml`, format like:
21
21
 
22
- servers:
23
- groupA:
24
- - host: xxx.com
25
- user: app
26
- groupB:
27
- - host: aaa.com
28
- user: app
29
- alias: app_server
30
- - host: aaa.com
31
- user: db
32
- alias: db_master
22
+ servers:
23
+ groupA:
24
+ - host: xxx.com
25
+ user: app
26
+ groupB:
27
+ - host: aaa.com
28
+ user: app
29
+ alias: app_server
30
+ - host: aaa.com
31
+ user: db
32
+ alias: db_master
33
33
 
34
- (You can puts `available_public_keys` and `server_list.yml` at github, them people can add files by themselves)
34
+ (You can puts `available_public_keys` and `server_list.yml` at github, them people can add files by themselves)
35
35
 
36
36
  4. ssh-key-sync-man -g groupA
37
37
 
38
- This will deploy public keys in `available_public_keys/groupA` to groupA servers
38
+ This will deploy public keys in `available_public_keys/groupA` to groupA servers
39
39
 
40
40
 
41
41
  "alias" list -- linux shotcut command list auto generator
@@ -45,10 +45,9 @@ This will deploy public keys in `available_public_keys/groupA` to groupA servers
45
45
 
46
46
  Generate alias file for everyone, for example:
47
47
 
48
- michael
49
- alias myasics_app1="ssh app@host"
50
- alias myasics_app2="ssh app@host"
51
- alias myasics_db="ssh app@host"
52
- alias myasics_staging="ssh app@host"
48
+ alias myasics_app1="ssh app@host"
49
+ alias myasics_app2="ssh app@host"
50
+ alias myasics_db="ssh app@host"
51
+ alias myasics_staging="ssh app@host"
53
52
 
54
53
  You can copy and paste into your .bashrc or .bash_profile
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
data/bin/ssh-key-sync-man CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require 'lib/uploader'
4
- require 'lib/file_combiner'
5
- require 'lib/alias_gen'
3
+ $: << "./lib"
4
+ require 'uploader'
5
+ require 'file_combiner'
6
+ require 'alias_gen'
6
7
  require 'optparse'
7
8
 
8
9
  options = {}
@@ -19,13 +20,13 @@ OptionParser.new do |opts|
19
20
  end
20
21
  end.parse!
21
22
 
22
- # check alias option
23
- if !(alias_for_user = options[:alias_for_user]).nil?
24
- SshKeyMan::AliasGen.generate alias_for_user
25
- exit
26
- end
27
-
28
23
  begin
24
+ # check alias option
25
+ if !(alias_for_user = options[:alias_for_user]).nil?
26
+ SshKeyMan::AliasGen.generate alias_for_user
27
+ exit
28
+ end
29
+
29
30
  # check group option
30
31
  raise "please provide group name: deploy_sshkey myasics." if (group = options[:group]).nil?
31
32
 
data/lib/alias_gen.rb CHANGED
@@ -2,22 +2,23 @@ require 'yaml'
2
2
 
3
3
  module SshKeyMan
4
4
  class AliasGen
5
- SERVER_LIST = File.join(".", "server_list.yml")
6
-
7
5
  def self.generate user
8
- servers = YAML::load_file(SERVER_LIST)['servers']
6
+ server_list_path = File.join(".", "server_list.yml")
7
+ servers = YAML::load_file(server_list_path)['servers']
8
+ groups = get_user_groups(user)
9
+
9
10
  puts "\e[31m You can copy below code to '~/.bash_profile' or '~/.bashrc'. \e[0m"
10
11
  puts "============================================="
11
- get_user_groups(user).each do |group|
12
+ groups.each do |group|
12
13
  servers[group].each do |server|
13
14
  puts "alias #{group}_#{server['alias']}=\"#{server['user']}@#{server['host']}\""
14
15
  end
15
16
  end
16
17
  puts "============================================="
17
18
  end
18
-
19
+
19
20
  def self.get_user_groups user
20
- user_groups = `cd available_public_keys; find . -name #{user}`.split("\n")
21
+ user_groups = `cd available_public_keys; find . -name #{user}`.split("\n")
21
22
  raise "Not found user: \"#{user}\"" if user_groups.size == 0
22
23
  user_groups.map { |user_group| user_group.slice(/[^\.\/]+(?=\/)/) }
23
24
  end
data/lib/file_combiner.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module SshKeyMan
2
2
  class PublicKeyCombiner
3
-
4
3
  def self.combine group
5
4
  puts "combining public keys ..."
6
5
 
@@ -11,7 +10,7 @@ module SshKeyMan
11
10
  f.write File.read(get_current_user_public_key_path) if get_current_user_public_key_path
12
11
  files = Dir[File.join(public_key_path, group, "*")]
13
12
 
14
- raise "No Such a Group: #{group}" if files.size == 0
13
+ raise "No such a server group: #{group}" if files.size == 0
15
14
 
16
15
  files.each do |file|
17
16
  f.write File.read(file)
data/lib/uploader.rb CHANGED
@@ -4,19 +4,18 @@ require 'yaml'
4
4
 
5
5
  module SshKeyMan
6
6
  class Uploader
7
- SERVER_LIST = File.join(".", "server_list.yml")
8
- AUTHORIZED_KEYS = File.join(".", "authorized_keys")
9
-
10
7
  # upload authorized_keys for a specific group
11
8
  #
12
9
  def self.upload_all_public_keys group
13
- upload_to_all_servers AUTHORIZED_KEYS, "~/.ssh/", group
10
+ authorized_keys = File.join(".", "authorized_keys")
11
+ upload_to_all_servers authorized_keys, "~/.ssh/", group
14
12
  end
15
13
 
16
14
  # upload file to a group of servers
17
15
  #
18
16
  def self.upload_to_all_servers source, dest, group
19
- servers = YAML::load_file(SERVER_LIST)['servers'][group]
17
+ server_list_path = File.join(".", "server_list.yml")
18
+ servers = YAML::load_file(server_list_path)['servers'][group]
20
19
  raise "No Server Group: #{group}" if servers.size == 0
21
20
  servers.each do |server_info|
22
21
  upload! server_info["host"], server_info["user"], source, dest
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ssh-key-sync-man}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael He"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssh-key-sync-man
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael He