keystore 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/keystore.rb +1 -1
  3. data/lib/keystore.rb +13 -4
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f3b5983c966c1ec3a7b7aec25c0304c4fd50fdd
4
- data.tar.gz: 33fa127ebcee194fc132019a521def29e1e2e6a1
3
+ metadata.gz: 01ad16e17212048e901879bd344c9237adff84bc
4
+ data.tar.gz: ea8f6e32c48131c746525bbd74b4cb7f6b8bc771
5
5
  SHA512:
6
- metadata.gz: 8c6db3d941dd0c5aad12d62db76c089a6e1f6a2cef4bd966423e6c8f8a5bbd9c12b7ed0368f004097e9844ece53c50e7265cc0ea1e5a2f8517ca6ba9d2f9cb88
7
- data.tar.gz: 9db49f5ceb06ea25301246d4e8dbb76021efee0f1cdd881a9eb49a4046edb4d70d480dd83de527795290355367b111da162726ac44a5a087f48a432ec7c7e9d5
6
+ metadata.gz: b9ae542e795583bbcc785002d4c3a386d791220900a170b31c769671ef9114d3d8fbd266c724f278fe009ce04e5bdefa547fc0d165d59a5dd5b094dbd5d1b047
7
+ data.tar.gz: dc9565f79c7352f75787299ea6a4901ba31763a0629f919ac85fd72f492ae73ad9fcf9fc751ca86ccfc8ea1ee5b707b77271030a71d5b769389e9ff64354b1ad
data/bin/keystore.rb CHANGED
@@ -34,7 +34,7 @@ cmd_opts =
34
34
  opt :table, 'the name of the table to perform the lookup on', required: true, type: String
35
35
  end
36
36
  else
37
- Trollop.die "usage: keystore.rb [store|retrieve] [parameters]"
37
+ Trollop.die 'usage: keystore.rb [store|retrieve] [parameters]'
38
38
  end
39
39
 
40
40
  dynamo = Aws::DynamoDB::Client.new region: global_opts[:region]
data/lib/keystore.rb CHANGED
@@ -13,8 +13,9 @@ class Keystore
13
13
  def store(params)
14
14
  # only need key id to encrypt, so check for it here
15
15
  fail 'need to specify key_id parameter' if @options[:key_id].nil?
16
- key_id = @options[:key_id]
17
- encrypted_value = @options[:kms].encrypt(key_id: key_id, plaintext: params[:value]).ciphertext_blob
16
+
17
+ value_to_encrypt = params[:value].nil? || params[:value].empty? ? ' ' : params[:value]
18
+ encrypted_value = @options[:kms].encrypt(key_id: @options[:key_id], plaintext: value_to_encrypt).ciphertext_blob
18
19
  encoded_value = Base64.encode64(encrypted_value)
19
20
  @options[:dynamo].put_item(
20
21
  table_name: @options[:table_name],
@@ -24,9 +25,17 @@ class Keystore
24
25
 
25
26
  def retrieve(params)
26
27
  item = @options[:dynamo].get_item(table_name: @options[:table_name], key: { ParameterName: params[:key] }).item
27
- fail "keyname #{params[:key]} not found" if item.nil?
28
+ fail KeyNotFoundError.new, "keyname #{params[:key]} not found" if item.nil?
29
+ fail KeyNotFoundError.new, "keyname #{params[:key]} not found" if item['Value'].nil?
28
30
  encoded_value = item['Value']
29
31
  encrypted_value = Base64.decode64(encoded_value)
30
- @options[:kms].decrypt(ciphertext_blob: encrypted_value).plaintext
32
+ result = @options[:kms].decrypt(ciphertext_blob: encrypted_value).plaintext
33
+ result.strip
31
34
  end
32
35
  end
36
+
37
+ class KeyStoreError < StandardError
38
+ end
39
+
40
+ class KeyNotFoundError < KeyStoreError
41
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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-10-02 00:00:00.000000000 Z
12
+ date: 2015-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
79
  version: '0'
80
80
  requirements: []
81
81
  rubyforge_project:
82
- rubygems_version: 2.4.8
82
+ rubygems_version: 2.4.6
83
83
  signing_key:
84
84
  specification_version: 4
85
85
  summary: Secure storage of secrets using Amazon Web Services.