hamburgerstore 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/hamburgerstore.rb +52 -0
- data/lib/hamburgerstore.rb +69 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2a69fba01ef358225a501dfd1fdbf4da15d648a3
|
4
|
+
data.tar.gz: c0dc8be614f022483eb6a5c9c0c4cfc29f725d2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e2fd5cd46850260f17fefe71029b9a8ce40e4a40806c1a20aebb8f5aee08e1bfe5eb57e1beeebf890c88b2ed9198e137395da48f7f3de26d259e4b6b5113f5b
|
7
|
+
data.tar.gz: 7582fbd1fe5c5a0973f36286482f00385e89f76733cfe8154f7093f5775fd447cb02e330fbe127fbf7e8be26e8dfbe35e60e5727970e9ee984d1daa74d3b24df
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'hamburgerstore'
|
4
|
+
require 'aws-sdk'
|
5
|
+
require 'trollop'
|
6
|
+
|
7
|
+
SUB_COMMANDS = %w(store retrieve)
|
8
|
+
global_opts = Trollop.options do
|
9
|
+
opt :region, 'The region to look for the dynamodb in', default: 'us-east-1'
|
10
|
+
banner 'utility for storing and retrieving encrypted values
|
11
|
+
available commands:
|
12
|
+
|
13
|
+
store -- store a value in hamerburger store
|
14
|
+
retrieve -- retrieve a value from hambuger store
|
15
|
+
|
16
|
+
use --help with either command for more information.
|
17
|
+
'
|
18
|
+
stop_on SUB_COMMANDS
|
19
|
+
end
|
20
|
+
|
21
|
+
cmd = ARGV.shift
|
22
|
+
cmd_opts =
|
23
|
+
case cmd
|
24
|
+
when 'store'
|
25
|
+
Trollop.options do
|
26
|
+
opt :identifier, 'the name of the key associated with the value', required: true, type: String
|
27
|
+
opt :keyname, 'the name of the key associated with the value', required: true, type: String
|
28
|
+
opt :value, 'the value to be inserted into the keystore (required for store)', required: true, type: String
|
29
|
+
opt :kmsid, 'the kms key id to use to encrypt the data (required for store)', required: true, type: String
|
30
|
+
opt :table, 'the name of the table to perform the lookup on', required: true, type: String
|
31
|
+
end
|
32
|
+
when 'retrieve'
|
33
|
+
Trollop.options do
|
34
|
+
opt :identifier, 'the name of the key associated with the value', required: true, type: String
|
35
|
+
opt :keyname, 'the name of the key associated with the value', required: true, type: String
|
36
|
+
opt :table, 'the name of the table to perform the lookup on', required: true, type: String
|
37
|
+
end
|
38
|
+
else
|
39
|
+
Trollop.die "usage: hamburgerstore.rb [store|retrieve] [parameters]"
|
40
|
+
end
|
41
|
+
|
42
|
+
hamburger = HamburgerStore.new(table_name: cmd_opts[:table], key_id: cmd_opts[:kmsid], region: global_opts[:region])
|
43
|
+
|
44
|
+
case cmd
|
45
|
+
when 'store'
|
46
|
+
hamburger.store(cmd_opts[:identifier], cmd_opts[:keyname], cmd_opts[:value])
|
47
|
+
when 'retrieve'
|
48
|
+
result = hamburger.retrieve(cmd_opts[:identifier], cmd_opts[:keyname])
|
49
|
+
puts result
|
50
|
+
else
|
51
|
+
fail "unknown subcommand #{cmd}"
|
52
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'aws-sdk-resources'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
# Data store for pipeline instance metadata. Nothing to do with hamburgers. Sorry.
|
5
|
+
class HamburgerStore
|
6
|
+
def encrypt(value)
|
7
|
+
encrypted_value = @kms.encrypt(key_id: @key_id, plaintext: value).ciphertext_blob
|
8
|
+
Base64.encode64(encrypted_value)
|
9
|
+
end
|
10
|
+
|
11
|
+
def decrypt(value)
|
12
|
+
encrypted_value = Base64.decode64(value)
|
13
|
+
@kms.decrypt(ciphertext_blob: encrypted_value).plaintext
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_kms(options)
|
17
|
+
# fail 'need to specify kms key_id parameter' if options[:key_id].nil?
|
18
|
+
@key_id = options[:key_id]
|
19
|
+
if options[:kms].nil?
|
20
|
+
fail 'need to specify region' if options[:region].nil?
|
21
|
+
@kms = Aws::KMS::Client.new region: options[:region]
|
22
|
+
else
|
23
|
+
@kms = options[:kms]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_dynamo(options)
|
28
|
+
if options[:dynamo].nil?
|
29
|
+
fail 'need to specify region' if options[:region].nil?
|
30
|
+
@ddb = Aws::DynamoDB::Resource.new region: options[:region]
|
31
|
+
else
|
32
|
+
@ddb = options[:dynamo]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(options = {})
|
37
|
+
check_kms(options)
|
38
|
+
check_dynamo(options)
|
39
|
+
|
40
|
+
fail 'need to specify table_name parameter' if options[:table_name].nil?
|
41
|
+
@table = @ddb.table(options[:table_name])
|
42
|
+
end
|
43
|
+
|
44
|
+
def store(identifer, key, value)
|
45
|
+
fail 'need to specify kms key_id parameter' if @key_id.nil?
|
46
|
+
item = @table.get_item(key: { 'hamburger' => identifer }).item
|
47
|
+
item = { 'hamburger' => identifer } if item.nil?
|
48
|
+
item[key] = encrypt(value)
|
49
|
+
@table.put_item(item: item, return_values: :ALL_OLD)
|
50
|
+
end
|
51
|
+
|
52
|
+
def retrieve(identifier, key)
|
53
|
+
item = @table.get_item(key: { 'hamburger' => identifier }).item
|
54
|
+
fail "no values for #{identifier}" if item.nil?
|
55
|
+
decrypt(item[key])
|
56
|
+
end
|
57
|
+
|
58
|
+
def retrieve_all(identifier)
|
59
|
+
encrypted_items = @table.get_item(key: { 'hamburger' => identifier }).item
|
60
|
+
hamburger = encrypted_items.delete('hamburger')
|
61
|
+
result = { 'hamburger' => hamburger }
|
62
|
+
encrypted_items.each_pair do |key, value|
|
63
|
+
result[key] = decrypt(value)
|
64
|
+
end
|
65
|
+
result
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# store a set of parameters (?)
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hamburgerstore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonny Sywulak
|
8
|
+
- Stelligent
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-09-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: aws-sdk
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.1'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.1'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: trollop
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 2.1.2
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 2.1.2
|
42
|
+
description: Hambuger Store is an easy, lightweight way to store data about your pipeline
|
43
|
+
instances. As you go through your pipeline, you're going to produce a lot of information
|
44
|
+
that's relevant to your pipeline instance, and having to store that in a text file
|
45
|
+
or pass parameters between jobs can get very unwieldy very quickly. Hamburger Store
|
46
|
+
utilizes two AWS services (Dyanmo DB and Key Management Service) to provide an easy
|
47
|
+
way to securely store the data your pipeline needs, without the bother of having
|
48
|
+
to set it up yourself.
|
49
|
+
email: jonny@stelligent.com
|
50
|
+
executables:
|
51
|
+
- hamburgerstore.rb
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- bin/hamburgerstore.rb
|
56
|
+
- lib/hamburgerstore.rb
|
57
|
+
homepage: http://www.stelligent.com
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
- lib
|
66
|
+
- bin
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 2.2.2
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.8
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Data store for pipeline instance metadata. Nothing to do with hamburgers.
|
83
|
+
Sorry.
|
84
|
+
test_files: []
|