hamburgerstore 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/hamburgerstore.rb +14 -3
- data/lib/hamburgerstore.rb +31 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 970ec2d1d03637ef0a3e1f82b3a55fe0981d6357
|
4
|
+
data.tar.gz: 5921782e5db9df5d3b623680c2b6af1808ad82e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a0e5df33291ef61ad5287534b844f779883114c7d63dcbcfd3d8cc469d6f07e9c28969d9605753ce6e5895832f6d45ba36219298019ec4c2cc2bf6c2bbfea3
|
7
|
+
data.tar.gz: 085526d46b2de869b5d35d1de9249799ac7d224c714727dfbb7bb677f146d77a565f90caa3d57e0a287c0e9f852702a11ffdd2be3d9cc398fdd8a11167ae678e
|
data/bin/hamburgerstore.rb
CHANGED
@@ -36,16 +36,27 @@ cmd_opts =
|
|
36
36
|
opt :table, 'the name of the table to perform the lookup on', required: true, type: String
|
37
37
|
end
|
38
38
|
else
|
39
|
-
Trollop.die
|
39
|
+
Trollop.die 'usage: hamburgerstore.rb [store|retrieve] [parameters]'
|
40
40
|
end
|
41
41
|
|
42
42
|
hamburger = HamburgerStore.new(table_name: cmd_opts[:table], key_id: cmd_opts[:kmsid], region: global_opts[:region])
|
43
43
|
|
44
44
|
case cmd
|
45
45
|
when 'store'
|
46
|
-
|
46
|
+
begin
|
47
|
+
hamburger.store(cmd_opts[:identifier], cmd_opts[:keyname], cmd_opts[:value])
|
48
|
+
rescue Exception => e
|
49
|
+
puts "#{e.class.name}: #{e.message}"
|
50
|
+
exit 1
|
51
|
+
end
|
47
52
|
when 'retrieve'
|
48
|
-
|
53
|
+
begin
|
54
|
+
result = hamburger.retrieve(cmd_opts[:identifier], cmd_opts[:keyname])
|
55
|
+
rescue Exception => e
|
56
|
+
msg = "Failed to retrieve value for key #{cmd_opts[:keyname]} and hamburger #{cmd_opts[:identifier]}"
|
57
|
+
puts "#{e.class.name}: #{msg}"
|
58
|
+
exit 1
|
59
|
+
end
|
49
60
|
puts result
|
50
61
|
else
|
51
62
|
fail "unknown subcommand #{cmd}"
|
data/lib/hamburgerstore.rb
CHANGED
@@ -4,13 +4,15 @@ require 'base64'
|
|
4
4
|
# Data store for pipeline instance metadata. Nothing to do with hamburgers. Sorry.
|
5
5
|
class HamburgerStore
|
6
6
|
def encrypt(value)
|
7
|
+
value = ' ' if value.length < 1
|
7
8
|
encrypted_value = @kms.encrypt(key_id: @key_id, plaintext: value).ciphertext_blob
|
8
9
|
Base64.encode64(encrypted_value)
|
9
10
|
end
|
10
11
|
|
11
12
|
def decrypt(value)
|
13
|
+
fail HamburgerKeyNotFoundInItemError, 'The key' if value.nil?
|
12
14
|
encrypted_value = Base64.decode64(value)
|
13
|
-
@kms.decrypt(ciphertext_blob: encrypted_value).plaintext
|
15
|
+
@kms.decrypt(ciphertext_blob: encrypted_value).plaintext.strip
|
14
16
|
end
|
15
17
|
|
16
18
|
def check_kms(options)
|
@@ -49,14 +51,29 @@ class HamburgerStore
|
|
49
51
|
@table.put_item(item: item, return_values: :ALL_OLD)
|
50
52
|
end
|
51
53
|
|
52
|
-
def
|
54
|
+
def ddb_get_item(identifier)
|
53
55
|
item = @table.get_item(key: { 'hamburger' => identifier }).item
|
54
|
-
|
56
|
+
if item.nil?
|
57
|
+
fail HamburgerNoItemInTableError, "No values for '#{identifier}' found in table."
|
58
|
+
end
|
59
|
+
item
|
60
|
+
end
|
61
|
+
|
62
|
+
def retrieve(identifier, key)
|
63
|
+
error = nil
|
64
|
+
begin
|
65
|
+
item = ddb_get_item(identifier)
|
66
|
+
rescue Exception => e
|
67
|
+
error = e
|
68
|
+
end
|
69
|
+
if !error.nil? || item.nil? || item[key].nil?
|
70
|
+
fail HamburgerKeyNotFoundInItemError, "The key '#{key}' was not found in '#{identifier}' hamburger store."
|
71
|
+
end
|
55
72
|
decrypt(item[key])
|
56
73
|
end
|
57
74
|
|
58
75
|
def retrieve_all(identifier)
|
59
|
-
encrypted_items =
|
76
|
+
encrypted_items = ddb_get_item(identifier)
|
60
77
|
hamburger = encrypted_items.delete('hamburger')
|
61
78
|
result = { 'hamburger' => hamburger }
|
62
79
|
encrypted_items.each_pair do |key, value|
|
@@ -66,4 +83,14 @@ class HamburgerStore
|
|
66
83
|
end
|
67
84
|
end
|
68
85
|
|
86
|
+
# Top level exception so we can catch our exceptions explicitly
|
87
|
+
class HamburgerException < Exception
|
88
|
+
end
|
89
|
+
|
90
|
+
class HamburgerNoItemInTableError < HamburgerException
|
91
|
+
end
|
92
|
+
|
93
|
+
class HamburgerKeyNotFoundInItemError < HamburgerException
|
94
|
+
end
|
95
|
+
|
69
96
|
# store a set of parameters (?)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamburgerstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonny Sywulak
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -68,7 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: 2.
|
71
|
+
version: 2.1.0
|
72
72
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
74
|
- - ">="
|