pct 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pct/version.rb +1 -1
- data/lib/pct.rb +23 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1f3eda427a8c6faa05bde5f37b542a2025c3adaf1b4e00b5ede5499a5805fc0
|
4
|
+
data.tar.gz: c8c11080fc227c4ab87e81553c805656c0c0ed247c32fce534233493f619e4a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b8ab87ae536ac1fe4c19eb5726d5141f2616103f27d06fd2803144575c31d382840780f74476ce03ca0b98bc6ba4a31ba68155abd25ac2a77faaebf9c28d1b5
|
7
|
+
data.tar.gz: 03d92501baf2b58e796bd0f8e3722951ec6c6d33a313f5bb7e983f08e902a15dcc59834ccfd7384fdfcdae2a561ae22a408afc555604a08fe9469d55eef84df1
|
data/lib/pct/version.rb
CHANGED
data/lib/pct.rb
CHANGED
@@ -7,6 +7,19 @@ require 'aws-sdk-kms'
|
|
7
7
|
module Pct
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
|
+
class Decryptable
|
11
|
+
def initialize(client, crypted)
|
12
|
+
@client = client
|
13
|
+
@crypted = crypted
|
14
|
+
end
|
15
|
+
|
16
|
+
def decrypted
|
17
|
+
@decrypted ||= client.decrypt({
|
18
|
+
ciphertext_blob: Base64.decode64(@crypted)
|
19
|
+
}).plaintext
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
10
23
|
DEFAULT = <<~EOS
|
11
24
|
configuration:
|
12
25
|
example_key: "some value that should be encrypted"
|
@@ -28,6 +41,16 @@ module Pct
|
|
28
41
|
to_decrypted(config['configuration'])
|
29
42
|
end
|
30
43
|
|
44
|
+
def to_usable(configuration)
|
45
|
+
Hash[configuration.map do |k, v|
|
46
|
+
if v.is_a?(Hash)
|
47
|
+
[k, to_usable(v)]
|
48
|
+
else
|
49
|
+
[k, Decryptable.new(client, v)]
|
50
|
+
end
|
51
|
+
end]
|
52
|
+
end
|
53
|
+
|
31
54
|
def self.encrypt(value, key)
|
32
55
|
raise ArgumentError, "all values for encryption must be a string" if !value.is_a?(String)
|
33
56
|
|