shh 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/shh/cli.rb +21 -9
- metadata +2 -2
data/lib/shh/cli.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'pathname2'
|
3
3
|
require 'highline/import'
|
4
|
+
require 'uuid'
|
4
5
|
require 'shh/crypt'
|
5
6
|
require 'yaml'
|
7
|
+
require 'pathname2' # don't ask why i'm loading this twice
|
6
8
|
|
7
9
|
module Shh
|
8
10
|
class Cli
|
9
11
|
def execute *args
|
10
12
|
passphrase = ask('Enter your passphrase') { |q| q.echo = false }
|
11
13
|
|
14
|
+
@uuid = UUID.new
|
12
15
|
@folder = Pathname.new('secret')
|
13
16
|
@folder.mkdir_p
|
14
17
|
@crypt = Crypt.new(passphrase)
|
@@ -27,18 +30,17 @@ module Shh
|
|
27
30
|
end
|
28
31
|
|
29
32
|
def list
|
30
|
-
|
31
|
-
say(child) unless ['.','..'].include?(child.to_s)
|
32
|
-
end
|
33
|
+
each_entry {|entry| say "#{entry['name']} - #{entry['id']}" }
|
33
34
|
end
|
34
35
|
|
35
36
|
def create name=''
|
36
|
-
|
37
|
+
hash = {'name' => check_name(name), 'id' => @uuid.generate}
|
38
|
+
persist_entry prompt_loop(hash)
|
37
39
|
end
|
38
40
|
|
39
41
|
def edit name=''
|
40
42
|
name = check_name(name)
|
41
|
-
persist_entry
|
43
|
+
persist_entry prompt_loop(find_entry(name))
|
42
44
|
end
|
43
45
|
|
44
46
|
def view name=''
|
@@ -47,18 +49,28 @@ module Shh
|
|
47
49
|
|
48
50
|
private
|
49
51
|
|
52
|
+
def each_entry
|
53
|
+
@folder.children.each do |child|
|
54
|
+
yield load_entry(child)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
50
58
|
def check_name name
|
51
59
|
name = ask('Enter the entry name') unless name.size > 0
|
52
60
|
name
|
53
61
|
end
|
54
62
|
|
55
|
-
def
|
56
|
-
|
63
|
+
def find_entry name
|
64
|
+
each_entry {|e| return e if e['name'] == name}
|
65
|
+
end
|
66
|
+
|
67
|
+
def load_entry path
|
68
|
+
entry = path.open('r') {|io| @crypt.decrypt(io) }
|
57
69
|
YAML::load(entry)
|
58
70
|
end
|
59
71
|
|
60
|
-
def persist_entry
|
61
|
-
(@folder +
|
72
|
+
def persist_entry entry
|
73
|
+
(@folder + entry['id']).open('w') {|io| @crypt.encrypt(entry.to_yaml, io) }
|
62
74
|
end
|
63
75
|
|
64
76
|
def prompt_loop hash, read_only=false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Ryall
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-08 00:00:00 +11:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|