ssh-key-sync-man 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +22 -23
- data/VERSION +1 -1
- data/bin/ssh-key-sync-man +10 -9
- data/lib/alias_gen.rb +7 -6
- data/lib/file_combiner.rb +1 -2
- data/lib/uploader.rb +4 -5
- data/ssh-key-sync-man.gemspec +1 -1
- metadata +3 -3
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
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
49
|
-
alias
|
50
|
-
alias
|
51
|
-
alias
|
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.
|
1
|
+
0.1.3
|
data/bin/ssh-key-sync-man
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
require '
|
5
|
-
require '
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
-
|
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
|
data/ssh-key-sync-man.gemspec
CHANGED
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Michael He
|