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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f6b5ce6241b3a2e31d877266c322b800cbf1427
4
- data.tar.gz: 38c618ea10492077a13f94011c0597a3b48e2be3
3
+ metadata.gz: db704ac8d5884864a89de4f643ba092008f0a769
4
+ data.tar.gz: 5163382ff06f1df66af5c57347de20a9c943bb50
5
5
  SHA512:
6
- metadata.gz: 4ef7958c782c70ba73ebfd36dfd62c1fd301c3070fab5e2148ccc11ece273ded8fb797459f013406c4637ab23c30ddbdbe256bf692171758faebde63d868c7f4
7
- data.tar.gz: 7e720bd809a9631d669f7b5b55bc4def972b67449f7f45d57ff9da639ef634e4811030e05f250222cf8e51f81f30c95cd6277b9cabbb92bf0cb827a0b29053d1
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, :file, :exists?
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
- set_roles_from_file if roles.nil?
17
- set_notes_from_file if notes.nil?
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
- file.transaction do |f|
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 set_roles_from_file
40
- file.transaction do |f|
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 set_notes_from_file
46
- file.transaction do |f|
45
+ def set_notes_from_store
46
+ store.transaction do |f|
47
47
  @notes = f[name][:notes]
48
48
  end
49
49
  end
@@ -1,3 +1,3 @@
1
1
  module KeyStore
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
data/lib/key_store.rb CHANGED
@@ -14,10 +14,10 @@ module KeyStore
14
14
  @file_path = value
15
15
  end
16
16
 
17
- def file
18
- if @file.nil? || modified?
17
+ def store
18
+ if @store.nil? || modified?
19
19
  Mutex.new.synchronize do
20
- @file = begin
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
- @file
28
+ @store
29
29
  end
30
30
 
31
31
  def exists?(name)
32
- !!(file.transaction { |f| f[name.to_s] })
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
- file.transaction { |f| f.delete(name.to_s) }
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
@@ -18,7 +18,7 @@ class KeyStoreTest < MicroTest::Test
18
18
  end
19
19
 
20
20
  begin
21
- assert KeyStore.file
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.file
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins