ssh-key-sync-man 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.2)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.6.2)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Michael He
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ SSH Key sync tool Readme
2
+ ========================
3
+
4
+ This tool is used to mass deploy ssh-keys to all your servers according to the config.
5
+
6
+
7
+ Usage
8
+ =====
9
+
10
+ 1. `gem install ssh-key-sync-man`
11
+
12
+ 2. Put all your team members' keys into one `available_public_keys` directory with the structure looks like:
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
19
+
20
+ 3. Add a `server_list.yml`, format like:
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
33
+
34
+ (You can puts `available_public_keys` and `server_list.yml` at github, them people can add files by themselves)
35
+
36
+ 4. ssh-key-sync-man -g groupA
37
+
38
+ This will deploy public keys in `available_public_keys/groupA` to groupA servers
39
+
40
+
41
+ "alias" list -- linux shotcut command list auto generator
42
+ =========================================================
43
+
44
+ `ssh-key-sync-man -a michael` generate alias for michael.
45
+
46
+ Generate alias file for everyone, for example:
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"
53
+
54
+ You can copy and paste into your .bashrc or .bash_profile
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "ssh-key-sync-man"
18
+ gem.homepage = "http://github.com/hlxwell/ssh-key-sync-man"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Manage all your servers' auto login ssh-keys. One-command-line adding or removing any ssh-key for all servers.}
21
+ gem.description = %Q{Manage all your servers' auto login ssh-keys. One-command-line adding or removing any ssh-key for all servers.}
22
+ gem.email = "hlxwell@gmail.com"
23
+ gem.authors = ["Michael He"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "ssh-key-sync-man #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lib/uploader'
4
+ require 'lib/file_combiner'
5
+ require 'lib/alias_gen'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: deploy_sshkey [options]"
12
+
13
+ opts.on("-a", "--alias user", "Generate shell alias for specific user") do |user|
14
+ options[:alias_for_user] = user
15
+ end
16
+
17
+ opts.on("-g group", "--group group", "Server Group Name") do |group|
18
+ options[:group] = group
19
+ end
20
+ end.parse!
21
+
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
+ begin
29
+ # check group option
30
+ raise "please provide group name: deploy_sshkey myasics." if (group = options[:group]).nil?
31
+
32
+ SshKeyMan::PublicKeyCombiner.combine group
33
+ SshKeyMan::Uploader.upload_all_public_keys group
34
+ puts "Done!"
35
+ rescue => e
36
+ puts "Got an error:"
37
+ puts e.to_s
38
+ end
data/lib/alias_gen.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+
3
+ module SshKeyMan
4
+ class AliasGen
5
+ SERVER_LIST = File.join(".", "server_list.yml")
6
+
7
+ def self.generate user
8
+ servers = YAML::load_file(SERVER_LIST)['servers']
9
+ puts "\e[31m You can copy below code to '~/.bash_profile' or '~/.bashrc'. \e[0m"
10
+ puts "============================================="
11
+ get_user_groups(user).each do |group|
12
+ servers[group].each do |server|
13
+ puts "alias #{group}_#{server['alias']}=\"#{server['user']}@#{server['host']}\""
14
+ end
15
+ end
16
+ puts "============================================="
17
+ end
18
+
19
+ def self.get_user_groups user
20
+ user_groups = `cd available_public_keys; find . -name #{user}`.split("\n")
21
+ raise "Not found user: \"#{user}\"" if user_groups.size == 0
22
+ user_groups.map { |user_group| user_group.slice(/[^\.\/]+(?=\/)/) }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ module SshKeyMan
2
+ class PublicKeyCombiner
3
+
4
+ def self.combine group
5
+ puts "combining public keys ..."
6
+
7
+ authorized_keys_path = File.join ".", "authorized_keys"
8
+ public_key_path = File.join(".", "available_public_keys")
9
+
10
+ File.open authorized_keys_path, "w" do |f|
11
+ f.write File.read(get_current_user_public_key_path) if get_current_user_public_key_path
12
+ files = Dir[File.join(public_key_path, group, "*")]
13
+
14
+ raise "No Such a Group: #{group}" if files.size == 0
15
+
16
+ files.each do |file|
17
+ f.write File.read(file)
18
+ end
19
+ end
20
+
21
+ puts "finished combining public keys ..."
22
+ end
23
+
24
+ def self.get_current_user_public_key_path
25
+ omni_rsa_key_path = File.expand_path(File.join "~", ".ssh", "id_rsa.pub")
26
+ omni_dsa_key_path = File.expand_path(File.join "~", ".ssh", "id_dsa.pub")
27
+ current_user_key_path = nil
28
+ current_user_key_path = omni_rsa_key_path if File.exist?(omni_rsa_key_path)
29
+ current_user_key_path = omni_dsa_key_path if File.exist?(omni_dsa_key_path)
30
+ current_user_key_path
31
+ end
32
+ end
33
+ end
data/lib/uploader.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'net/scp'
3
+ require 'yaml'
4
+
5
+ module SshKeyMan
6
+ class Uploader
7
+ SERVER_LIST = File.join(".", "server_list.yml")
8
+ AUTHORIZED_KEYS = File.join(".", "authorized_keys")
9
+
10
+ # upload authorized_keys for a specific group
11
+ #
12
+ def self.upload_all_public_keys group
13
+ upload_to_all_servers AUTHORIZED_KEYS, "~/.ssh/", group
14
+ end
15
+
16
+ # upload file to a group of servers
17
+ #
18
+ def self.upload_to_all_servers source, dest, group
19
+ servers = YAML::load_file(SERVER_LIST)['servers'][group]
20
+ raise "No Server Group: #{group}" if servers.size == 0
21
+ servers.each do |server_info|
22
+ upload! server_info["host"], server_info["user"], source, dest
23
+ end
24
+ end
25
+
26
+ # upload a file to a remote server
27
+ #
28
+ def self.upload! host, user, source, dest
29
+ puts "coping file from #{source} to #{user}@#{host}:#{dest}"
30
+ `scp #{source} #{user}@#{host}:#{dest}`
31
+ raise "upload failed" if $?.exitstatus != 0
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ssh-key-sync-man}
8
+ s.version = "0.1.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Michael He"]
12
+ s.date = %q{2011-06-20}
13
+ s.default_executable = %q{ssh-key-sync-man}
14
+ s.description = %q{Manage all your servers' auto login ssh-keys. One-command-line adding or removing any ssh-key for all servers.}
15
+ s.email = %q{hlxwell@gmail.com}
16
+ s.executables = ["ssh-key-sync-man"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.md"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.md",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/ssh-key-sync-man",
30
+ "lib/alias_gen.rb",
31
+ "lib/file_combiner.rb",
32
+ "lib/uploader.rb",
33
+ "ssh-key-sync-man.gemspec",
34
+ "test/helper.rb",
35
+ "test/test_ssh-key-sync-man.rb"
36
+ ]
37
+ s.homepage = %q{http://github.com/hlxwell/ssh-key-sync-man}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.5.0}
41
+ s.summary = %q{Manage all your servers' auto login ssh-keys. One-command-line adding or removing any ssh-key for all servers.}
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
50
+ s.add_development_dependency(%q<rcov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<shoulda>, [">= 0"])
59
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
61
+ s.add_dependency(%q<rcov>, [">= 0"])
62
+ end
63
+ end
64
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'ssh-key-sync-man'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestSshKeySyncMan < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ssh-key-sync-man
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Michael He
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-20 00:00:00 +08:00
19
+ default_executable: ssh-key-sync-man
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ prerelease: false
33
+ type: :development
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ prerelease: false
49
+ type: :development
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: jeweler
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 11
59
+ segments:
60
+ - 1
61
+ - 6
62
+ - 2
63
+ version: 1.6.2
64
+ prerelease: false
65
+ type: :development
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: rcov
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ prerelease: false
79
+ type: :development
80
+ requirement: *id004
81
+ description: Manage all your servers' auto login ssh-keys. One-command-line adding or removing any ssh-key for all servers.
82
+ email: hlxwell@gmail.com
83
+ executables:
84
+ - ssh-key-sync-man
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.md
90
+ files:
91
+ - .document
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - VERSION
98
+ - bin/ssh-key-sync-man
99
+ - lib/alias_gen.rb
100
+ - lib/file_combiner.rb
101
+ - lib/uploader.rb
102
+ - ssh-key-sync-man.gemspec
103
+ - test/helper.rb
104
+ - test/test_ssh-key-sync-man.rb
105
+ has_rdoc: true
106
+ homepage: http://github.com/hlxwell/ssh-key-sync-man
107
+ licenses:
108
+ - MIT
109
+ post_install_message:
110
+ rdoc_options: []
111
+
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ none: false
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ hash: 3
129
+ segments:
130
+ - 0
131
+ version: "0"
132
+ requirements: []
133
+
134
+ rubyforge_project:
135
+ rubygems_version: 1.5.0
136
+ signing_key:
137
+ specification_version: 3
138
+ summary: Manage all your servers' auto login ssh-keys. One-command-line adding or removing any ssh-key for all servers.
139
+ test_files: []
140
+