cap-ssh-key-man 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,9 +12,9 @@ Usage
12
12
 
13
13
  2. Add `require 'cap-ssh-key-man/tasks/rsync'` to `config/deploy.rb` of your rails project.
14
14
 
15
- 3. Put all public ssh keys to `config/developer_ssh_keys` dir of your rails project.
15
+ 3. Add `set :sshkeys_path, PATH_TO_SSHKEYS_STORE_PATH` to `deploy.rb`.
16
16
 
17
- 4. Add `set :sshkeys_path, PATH_TO_SSHKEYS_STORE_PATH` to `deploy.rb`.
17
+ 4. Put all public ssh keys to `PATH_TO_SSHKEYS_STORE_PATH` dir of your rails project.
18
18
 
19
19
  5. Execute `cap sshkey:deploy`
20
20
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.3
1
+ 1.3.0
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cap-ssh-key-man}
8
- s.version = "1.2.3"
8
+ s.version = "1.3.0"
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"]
@@ -1,19 +1,24 @@
1
1
  module CapSshKeyMan
2
2
  class PublicKeyCombiner
3
- AUTHORIZED_KEYS_PATH = File.join ".", "tmp", "authorized_keys"
3
+ # AUTHORIZED_KEYS_PATH = File.join ".", "tmp", "authorized_keys"
4
4
  PUBLIC_KEY_PATH = File.join(".", "config", "developer_public_keys")
5
5
  OMNI_RSA_KEY_PATH = File.expand_path(File.join "~", ".ssh", "id_rsa.pub")
6
6
  OMNI_DSA_KEY_PATH = File.expand_path(File.join "~", ".ssh", "id_dsa.pub")
7
7
 
8
- def self.combine_developer_public_keys_to public_key_path = PUBLIC_KEY_PATH
9
- File.open AUTHORIZED_KEYS_PATH, "w" do |f|
10
- f.write File.read(get_current_user_public_key_path) if get_current_user_public_key_path
11
- files = Dir[File.join(public_key_path, '*')]
12
- raise "Can't find any public keys in #{public_key_path} dir." if files.size == 0
13
- files.each do |file|
14
- f.write File.read(file)
15
- end
8
+ def self.combine_developer_public_keys_in public_key_path
9
+ public_key_path ||= PUBLIC_KEY_PATH
10
+ abort "Please put your public keys in #{public_key_path}." unless File.exist?(public_key_path)
11
+
12
+ authorized_keys_string = ""
13
+ authorized_keys_string << File.read(get_current_user_public_key_path) if get_current_user_public_key_path
14
+
15
+ files = Dir[File.join(public_key_path, '*')]
16
+ raise "Can't find any public keys in #{public_key_path} dir." if files.size == 0
17
+ files.each do |file|
18
+ authorized_keys_string << File.read(file)
16
19
  end
20
+
21
+ authorized_keys_string
17
22
  end
18
23
 
19
24
  def self.get_current_user_public_key_path
@@ -5,12 +5,10 @@ Capistrano::Configuration.instance(true).load do
5
5
  namespace :sshkey do
6
6
  desc "Sync keys to servers"
7
7
  task :deploy do
8
- if !exists?(:sshkeys_path) or !File.exist?(sshkeys_path)
9
- abort "Please add 'set :sshkeys_path, YOUR_PUBLIC_KEY_DIR' in your deploy.rb, and put public keys in YOUR_PUBLIC_KEY_DIR."
10
- end
11
- CapSshKeyMan::PublicKeyCombiner.combine_developer_public_keys_to sshkeys_path
12
- put File.read(CapSshKeyMan::PublicKeyCombiner::AUTHORIZED_KEYS_PATH), File.join("/home/#{user}", ".ssh", "authorized_keys")
13
- FileUtils.rm CapSshKeyMan::PublicKeyCombiner::AUTHORIZED_KEYS_PATH # delete temp file after use it.
8
+ set :sshkeys_path, nil unless exists?(:sshkeys_path)
9
+ remote_ssh_folder_path = File.join("/home/#{user}", ".ssh", "authorized_keys")
10
+ put CapSshKeyMan::PublicKeyCombiner.combine_developer_public_keys_in(sshkeys_path), remote_ssh_folder_path
11
+ run "chmod 600 #{remote_ssh_folder_path}"
14
12
  end
15
13
  end
16
14
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cap-ssh-key-man
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 2
9
8
  - 3
10
- version: 1.2.3
9
+ - 0
10
+ version: 1.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael He