strongspace 0.0.8 → 0.0.9
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/lib/strongspace/commands/help.rb +8 -1
- data/lib/strongspace/commands/keys.rb +21 -1
- data/lib/strongspace/helpers.rb +108 -1
- data/lib/strongspace/version.rb +1 -1
- metadata +4 -4
@@ -41,7 +41,14 @@ module Strongspace::Command
|
|
41
41
|
|
42
42
|
group 'SSH Keys' do |group|
|
43
43
|
group.command 'keys', 'show your user\'s public keys'
|
44
|
-
|
44
|
+
|
45
|
+
if not RUBY_PLATFORM =~ /mswin32|mingw32/
|
46
|
+
group.command 'keys:add [<path to keyfile>]', 'Add an public key or generate a new SSH keypair and add'
|
47
|
+
group.command 'keys:generate', 'Generate a new SSH keypair'
|
48
|
+
else
|
49
|
+
group.command 'keys:add [<path to keyfile>]', 'Add an public key'
|
50
|
+
end
|
51
|
+
|
45
52
|
group.command 'keys:remove <id> ', 'remove a key by id'
|
46
53
|
group.command 'keys:clear', 'remove all keys'
|
47
54
|
end
|
@@ -14,6 +14,12 @@ module Strongspace::Command
|
|
14
14
|
end
|
15
15
|
alias :index :list
|
16
16
|
|
17
|
+
def generate
|
18
|
+
`ssh-keygen`
|
19
|
+
return ($? == 0)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
17
23
|
def add
|
18
24
|
keyfile = args.first || find_key
|
19
25
|
key = File.read(keyfile)
|
@@ -39,7 +45,21 @@ module Strongspace::Command
|
|
39
45
|
keyfile = "#{home_directory}/.ssh/id_#{key_type}.pub"
|
40
46
|
return keyfile if File.exists? keyfile
|
41
47
|
end
|
42
|
-
|
48
|
+
|
49
|
+
|
50
|
+
display "No ssh public key found in #{home_directory}/.ssh/id_[rd]sa.pub"
|
51
|
+
if not running_on_windows?
|
52
|
+
display " Generate a new key? [yes/no]: ", false
|
53
|
+
answer = ask("no")
|
54
|
+
if answer.downcase == "yes" or answer.downcase == "y"
|
55
|
+
r = Strongspace::Command.run_internal("keys:generate", nil)
|
56
|
+
if r
|
57
|
+
return find_key
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
raise CommandFailed, "No ssh public key available"
|
43
63
|
end
|
44
64
|
|
45
65
|
def format_key_for_display(key)
|
data/lib/strongspace/helpers.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module Strongspace
|
2
2
|
module Helpers
|
3
|
+
|
4
|
+
def command_name
|
5
|
+
self.class.name.split("::").last
|
6
|
+
end
|
7
|
+
|
3
8
|
def home_directory
|
4
9
|
running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
|
5
10
|
end
|
@@ -24,6 +29,72 @@ module Strongspace
|
|
24
29
|
"#{home_directory}/.strongspace/bin"
|
25
30
|
end
|
26
31
|
|
32
|
+
def launchd_agents_folder
|
33
|
+
"#{home_directory}/Library/LaunchAgents"
|
34
|
+
end
|
35
|
+
|
36
|
+
def pid_file_path(name)
|
37
|
+
"#{pids_folder}/#{name}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def pid_from_pid_file(name)
|
41
|
+
if File.exist?(pid_file_path(name))
|
42
|
+
|
43
|
+
f = File.open(pid_file_path(name))
|
44
|
+
existing_pid = Integer(f.gets)
|
45
|
+
f.close
|
46
|
+
|
47
|
+
return existing_pid
|
48
|
+
end
|
49
|
+
|
50
|
+
return nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def process_running?(name)
|
54
|
+
existing_pid = pid_from_pid_file(name)
|
55
|
+
|
56
|
+
if not existing_pid
|
57
|
+
return false
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
# This process is running
|
62
|
+
Process.kill(0, existing_pid)
|
63
|
+
return true
|
64
|
+
rescue Errno::EPERM
|
65
|
+
error "No longer have permissions to check this PID"
|
66
|
+
rescue Errno::ESRCH
|
67
|
+
# Cleanup orphaned pid file and continue on as normal
|
68
|
+
File.unlink(pid_file_path(name))
|
69
|
+
rescue
|
70
|
+
error "Unable to determine status for #{existing_pid} : #{$!}"
|
71
|
+
end
|
72
|
+
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_pid_file(name, pid)
|
77
|
+
|
78
|
+
if process_running?(name)
|
79
|
+
return nil
|
80
|
+
end
|
81
|
+
|
82
|
+
if not File.exist?(pids_folder)
|
83
|
+
FileUtils.mkdir_p(pids_folder)
|
84
|
+
end
|
85
|
+
|
86
|
+
file = File.new(pid_file_path(name), "w")
|
87
|
+
file.puts "#{pid}"
|
88
|
+
file.close
|
89
|
+
|
90
|
+
return true
|
91
|
+
end
|
92
|
+
|
93
|
+
def delete_pid_file(name)
|
94
|
+
if File.exist?(pid_file_path(name))
|
95
|
+
File.unlink(pid_file_path(name))
|
96
|
+
end
|
97
|
+
end
|
27
98
|
|
28
99
|
def display(msg, newline=true)
|
29
100
|
if newline
|
@@ -82,7 +153,7 @@ module Strongspace
|
|
82
153
|
|
83
154
|
def ask(default=nil)
|
84
155
|
r = gets.strip
|
85
|
-
if
|
156
|
+
if r.blank?
|
86
157
|
return default
|
87
158
|
else
|
88
159
|
return r
|
@@ -95,6 +166,34 @@ module Strongspace
|
|
95
166
|
end
|
96
167
|
end
|
97
168
|
|
169
|
+
unless Object.method_defined?(:blank?)
|
170
|
+
class Object
|
171
|
+
def blank?
|
172
|
+
respond_to?(:empty?) ? empty? : !self
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
unless String.method_defined?(:starts_with?)
|
178
|
+
class String
|
179
|
+
def starts_with?(str)
|
180
|
+
str = str.to_str
|
181
|
+
head = self[0, str.length]
|
182
|
+
head == str
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
unless String.method_defined?(:ends_with?)
|
188
|
+
class String
|
189
|
+
def ends_with?(str)
|
190
|
+
str = str.to_str
|
191
|
+
tail = self[-str.length, str.length]
|
192
|
+
tail == str
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
98
197
|
unless String.method_defined?(:shellescape)
|
99
198
|
class String
|
100
199
|
def shellescape
|
@@ -109,4 +208,12 @@ unless String.method_defined?(:camelize)
|
|
109
208
|
self.split(/[^a-z0-9]/i).map{|w| w.capitalize}.join
|
110
209
|
end
|
111
210
|
end
|
211
|
+
end
|
212
|
+
|
213
|
+
unless String.method_defined?(:underscore)
|
214
|
+
class String
|
215
|
+
def underscore
|
216
|
+
self.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
|
217
|
+
end
|
218
|
+
end
|
112
219
|
end
|
data/lib/strongspace/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strongspace
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Strongspace
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-16 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|