key_store 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/key_store/key.rb +8 -8
- data/lib/key_store/version.rb +1 -1
- data/lib/key_store.rb +10 -6
- data/test/key_store_test.rb +12 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db704ac8d5884864a89de4f643ba092008f0a769
|
4
|
+
data.tar.gz: 5163382ff06f1df66af5c57347de20a9c943bb50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db300a825f6dc87fda1847d8f5a9719b108399f82ce020030c208c10f1176fd40e85e3b9f28ee36cd5a62a41e673603d2a9852b7060ef3a0cc2b64eacf3e3e78
|
7
|
+
data.tar.gz: 70a64aaf1267183cea626b41167210c22475c0e13d5c992854d6e4268799754bd7ac53557d7e9ede549afa582b30df71b11f1b86ff0428ff47d9a6cae6025eaa
|
data/lib/key_store/key.rb
CHANGED
@@ -4,7 +4,7 @@ module KeyStore
|
|
4
4
|
class Key
|
5
5
|
extend Forwardable
|
6
6
|
|
7
|
-
def_delegators :KeyStore, :
|
7
|
+
def_delegators :KeyStore, :store, :exists?
|
8
8
|
attr_reader :name, :roles
|
9
9
|
attr_accessor :notes
|
10
10
|
alias_method :to_s, :name
|
@@ -13,8 +13,8 @@ module KeyStore
|
|
13
13
|
@name = name.to_s
|
14
14
|
|
15
15
|
if exists?(name)
|
16
|
-
|
17
|
-
|
16
|
+
set_roles_from_store if roles.nil?
|
17
|
+
set_notes_from_store if notes.nil?
|
18
18
|
end
|
19
19
|
|
20
20
|
@roles ||= (roles || []).map(&:to_s)
|
@@ -26,7 +26,7 @@ module KeyStore
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def save!
|
29
|
-
|
29
|
+
store.transaction do |f|
|
30
30
|
f[name] ||= {}
|
31
31
|
f[name][:roles] = roles.map(&:to_s)
|
32
32
|
f[name][:notes] = notes.to_s
|
@@ -36,14 +36,14 @@ module KeyStore
|
|
36
36
|
|
37
37
|
private
|
38
38
|
|
39
|
-
def
|
40
|
-
|
39
|
+
def set_roles_from_store
|
40
|
+
store.transaction do |f|
|
41
41
|
@roles = f[name][:roles]
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
|
45
|
+
def set_notes_from_store
|
46
|
+
store.transaction do |f|
|
47
47
|
@notes = f[name][:notes]
|
48
48
|
end
|
49
49
|
end
|
data/lib/key_store/version.rb
CHANGED
data/lib/key_store.rb
CHANGED
@@ -14,10 +14,10 @@ module KeyStore
|
|
14
14
|
@file_path = value
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
if @
|
17
|
+
def store
|
18
|
+
if @store.nil? || modified?
|
19
19
|
Mutex.new.synchronize do
|
20
|
-
@
|
20
|
+
@store = begin
|
21
21
|
raise "file_path not set" if file_path.nil?
|
22
22
|
FileUtils.touch(file_path) unless File.exists?(file_path)
|
23
23
|
self.mtime = File.mtime(file_path)
|
@@ -25,11 +25,11 @@ module KeyStore
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
|
-
@
|
28
|
+
@store
|
29
29
|
end
|
30
30
|
|
31
31
|
def exists?(name)
|
32
|
-
!!(
|
32
|
+
!!(store.transaction { |f| f.root?(name.to_s) })
|
33
33
|
end
|
34
34
|
|
35
35
|
def find(name)
|
@@ -37,7 +37,11 @@ module KeyStore
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def delete!(name)
|
40
|
-
|
40
|
+
store.transaction { |f| f.delete(name.to_s) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_hash
|
44
|
+
YAML.load(File.read(file_path))
|
41
45
|
end
|
42
46
|
|
43
47
|
private
|
data/test/key_store_test.rb
CHANGED
@@ -18,7 +18,7 @@ class KeyStoreTest < MicroTest::Test
|
|
18
18
|
end
|
19
19
|
|
20
20
|
begin
|
21
|
-
assert KeyStore.
|
21
|
+
assert KeyStore.store
|
22
22
|
rescue Exception => e
|
23
23
|
error = e
|
24
24
|
end
|
@@ -27,7 +27,7 @@ class KeyStoreTest < MicroTest::Test
|
|
27
27
|
end
|
28
28
|
|
29
29
|
test "file success with valid file_path" do
|
30
|
-
assert KeyStore.
|
30
|
+
assert KeyStore.store
|
31
31
|
end
|
32
32
|
|
33
33
|
test "unknown key does not exist" do
|
@@ -42,4 +42,14 @@ class KeyStoreTest < MicroTest::Test
|
|
42
42
|
assert KeyStore.delete!(:foobar).nil?
|
43
43
|
end
|
44
44
|
|
45
|
+
test "to_hash" do
|
46
|
+
KeyStore::Key.new(:foobar, roles: [:a, :b], notes: "a note").save!
|
47
|
+
assert KeyStore.to_hash == {
|
48
|
+
"foobar" => {
|
49
|
+
:roles => ["a", "b"],
|
50
|
+
:notes => "a note",
|
51
|
+
:http_header => "Authorization: Token token=\"foobar\""}
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
45
55
|
end
|