ssh-short 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA512:
3
- data.tar.gz: 8dd082ac87f7edfae8849622cd12d53e72c869a794bba884d58b3a1b86155025f0cc11608ee1dc89b2c54759be97beadb6dffcdc8997f9fb975ccfbc4a49bab0
4
- metadata.gz: abee1242981455872aa9556b41588e8fd0b379d1db3ca458951b2b662fdea744412db526862b7155689aa085427a758b14fae13bf4eaa7dee3939f3f556c73a8
3
+ data.tar.gz: 013894983677178843ed84e84de179db2646b94851fbb8352bec508d392d0bef9f4473178cf6bb9170f8882ba2dc6173f45cf1673236be8e7794631e81d565cd
4
+ metadata.gz: f0950a8ffdcdbcbe3f69fe3b92d34d9be9f69aa713d76d5459f36794c2a87ab43ececc0660b4de31632d5645cb57bfa030e7eb17c650d10038590baa224a4c45
5
5
  SHA1:
6
- data.tar.gz: 38070a5945bf08e55a334e6eff7a2e5abf5c6f7d
7
- metadata.gz: 06f47f255095c87e0dcf0f740fc8c5ea7ad1085a
6
+ data.tar.gz: 31394bed9beb69c61f3cfc15142abe3ed88d1e7f
7
+ metadata.gz: 9ae918535b15ed6c1ea250f7b12d9902bdb12820
data/README.md CHANGED
@@ -69,12 +69,15 @@ You can override the user for a node, see args section below
69
69
  When you connect to a host for the first time with ssh-short, it will scan your `keys_dir`
70
70
  and present you with a list of numbered keys:
71
71
 
72
+ **Update:** As of version 0.2.0 your default SSH Key (`id_rsa`) can now be used and will be presented as option `0`
73
+
72
74
  ```
73
75
  user@localhost $ sshort 16
74
76
  Select a key:
75
- 0) Dev.pem
76
- 1) Test.pem
77
- 2) Admin.pem
77
+ 0) id_rsa
78
+ 1) Dev.pem
79
+ 2) Test.pem
80
+ 3) Admin.pem
78
81
  ```
79
82
 
80
83
  Simply type the number of the key and press enter. ssh-short will connect you via `ssh`,
@@ -114,7 +117,8 @@ This forces an update to the key for a node and you will be presented with the l
114
117
  ```
115
118
  user@localhost $ sshort 16 -k
116
119
  Select a key:
117
- 0) Dev.pem
120
+ 0) id_rsa
121
+ 1) Dev.pem
118
122
  ...
119
123
  ```
120
124
 
@@ -9,11 +9,7 @@ module SshShort
9
9
  end
10
10
 
11
11
  def prompt_for_key
12
- abort "Error: Cannot find keys directory at #{@keys_dir}" unless File.exist? @keys_dir
13
- keys = Dir.glob("#{@keys_dir}/*").select{ |e| File.file? e }
14
- abort "Error: No keys found in #{@keys_dir}" unless keys.count > 0
15
-
16
- key_names = keys.collect { |key| File.basename key }
12
+ key_names = find_keys.collect { |key| File.basename key }
17
13
  key_names.unshift 'id_rsa'
18
14
 
19
15
  puts 'Select a key:'
@@ -26,11 +22,29 @@ module SshShort
26
22
  end
27
23
 
28
24
  def get_key(key_name)
29
- key = key_name.eql?('id_rsa') ? '~/.ssh/id_rsa' : "#{@keys_dir}/#{key_name}"
30
- key = File.expand_path(key)
25
+ if key_name.eql?('id_rsa')
26
+ key = File.expand_path('~/.ssh/id_rsa')
27
+ else
28
+ keys = find_keys.select { |path| File.basename(path) == key_name }
29
+ abort "Error: More than one key found called #{key_name}" if keys.count > 1
30
+ key = keys.first
31
+ end
32
+ # key = File.expand_path(key)
31
33
  abort "Error: Cannot find #{key}" unless File.exist? key
32
34
  key
33
35
  end
36
+
37
+ def find_keys
38
+ abort "Error: Cannot find keys directory at #{@keys_dir}" unless File.exist? @keys_dir
39
+
40
+ # Recursively search directory, including following symlinks
41
+ search_string = "#{File.expand_path(@keys_dir)}/**{,/*/**}/*"
42
+
43
+ keys = Dir.glob(search_string).select { |e| File.file? e }
44
+ abort "Error: No keys found in #{@keys_dir}" unless keys.count > 0
45
+
46
+ keys
47
+ end
34
48
 
35
49
  end
36
50
 
@@ -1,3 +1,3 @@
1
1
  module SshShort
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -4,7 +4,12 @@ require 'ssh_short/keyset'
4
4
  describe SshShort::KeySet do
5
5
 
6
6
  let(:keys_dir) { '/path/to/keys' }
7
- let(:keys) { [ 'key_a.pem', 'key_b.pem', 'key_c.pem', 'key_d.pem' ] }
7
+ let(:keys) { [
8
+ "#{keys_dir}/dir_a/key_a.pem",
9
+ "#{keys_dir}/dir_a/key_b.pem",
10
+ "#{keys_dir}/dir_b/key_c.pem",
11
+ "#{keys_dir}/dir_b/key_d.pem"
12
+ ] }
8
13
 
9
14
  subject(:key_set) { SshShort::KeySet.new keys_dir }
10
15
 
@@ -33,18 +38,15 @@ describe SshShort::KeySet do
33
38
  result = key_set.prompt_for_key
34
39
  expect(result).to eq 'id_rsa'
35
40
  end
36
-
37
41
  end
38
-
39
-
40
42
  end
41
43
 
42
44
  describe 'get_key' do
43
45
 
44
46
  it 'returns the key path from the name' do
45
- key_name = 'key_c.pem'
47
+ key_name = File.basename keys[2] #key_c.pem
46
48
  result = key_set.get_key key_name
47
- expect(result).to eq "#{keys_dir}/#{key_name}"
49
+ expect(result).to eq keys[2]
48
50
  end
49
51
 
50
52
  context 'when the default key name is provided' do
@@ -55,8 +57,6 @@ describe SshShort::KeySet do
55
57
  end
56
58
 
57
59
  end
58
-
59
-
60
60
  end
61
61
 
62
62
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssh-short
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Poulton
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2016-02-11 00:00:00 Z
12
+ date: 2016-03-15 00:00:00 Z
13
13
  dependencies: []
14
14
 
15
15
  description: Easy ssh