rcredstash 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cred_stash/config.rb +2 -1
- data/lib/cred_stash/repository/dynamo_db.rb +96 -0
- data/lib/cred_stash/repository/item.rb +13 -0
- data/lib/cred_stash/repository.rb +9 -106
- data/lib/cred_stash/secret.rb +2 -2
- data/lib/cred_stash/version.rb +1 -1
- data/lib/cred_stash.rb +7 -3
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af1edb53839064594e20faac9a3763659e715973
|
4
|
+
data.tar.gz: eea86d0447ff13342b6945b773ddd526f55d430b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d75896d2100518f478f4befc553b54a224371e6df97c2f0c79b3ea0aaeb930f9c11c44a70c8a7f510e7a114e8187bd1607e09a1b9510a57ade3607d1a3933dc0
|
7
|
+
data.tar.gz: 2b7fc0bcc9d905e3b3fac36dc392715099fd1b473ce240b62cf98653ffe6cb3bd22019aa2c1ba26edaf7b249031cfb9fd13f5b5403479672810d478b5eb76173
|
data/lib/cred_stash/config.rb
CHANGED
@@ -10,7 +10,7 @@ module CredStash
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class Config
|
13
|
-
attr_accessor :table_name
|
13
|
+
attr_accessor :table_name, :storage
|
14
14
|
|
15
15
|
def initialize
|
16
16
|
reset!
|
@@ -18,6 +18,7 @@ module CredStash
|
|
18
18
|
|
19
19
|
def reset!
|
20
20
|
@table_name = 'credential-store'
|
21
|
+
@storage = :dynamodb
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module CredStash::Repository
|
2
|
+
class DynamoDB
|
3
|
+
def initialize(client: nil)
|
4
|
+
@client = client || Aws::DynamoDB::Client.new
|
5
|
+
end
|
6
|
+
|
7
|
+
def get(name)
|
8
|
+
select(name, limit: 1).first.tap do |item|
|
9
|
+
unless item
|
10
|
+
raise CredStash::ItemNotFound, "#{name} is not found"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def select(name, pluck: nil, limit: nil)
|
16
|
+
params = {
|
17
|
+
table_name: CredStash.config.table_name,
|
18
|
+
consistent_read: true,
|
19
|
+
key_condition_expression: "#name = :name",
|
20
|
+
expression_attribute_names: { "#name" => "name"},
|
21
|
+
expression_attribute_values: { ":name" => name }
|
22
|
+
}
|
23
|
+
|
24
|
+
if pluck
|
25
|
+
params[:projection_expression] = pluck
|
26
|
+
end
|
27
|
+
|
28
|
+
if limit
|
29
|
+
params[:limit] = limit
|
30
|
+
params[:scan_index_forward] = false
|
31
|
+
end
|
32
|
+
|
33
|
+
@client.query(params).items.map do |item|
|
34
|
+
Item.new(
|
35
|
+
key: item["key"],
|
36
|
+
contents: item["contents"],
|
37
|
+
name: item["name"],
|
38
|
+
version: item["version"]
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def put(item)
|
44
|
+
@client.put_item(
|
45
|
+
table_name: CredStash.config.table_name,
|
46
|
+
item: {
|
47
|
+
name: item.name,
|
48
|
+
version: item.version,
|
49
|
+
key: item.key,
|
50
|
+
contents: item.contents,
|
51
|
+
hmac: item.hmac
|
52
|
+
},
|
53
|
+
condition_expression: "attribute_not_exists(#name)",
|
54
|
+
expression_attribute_names: { "#name" => "name" },
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def list
|
59
|
+
@client.scan(
|
60
|
+
table_name: CredStash.config.table_name,
|
61
|
+
projection_expression: '#name, version',
|
62
|
+
expression_attribute_names: { "#name" => "name" },
|
63
|
+
).items.map do |item|
|
64
|
+
Item.new(name: item['name'], version: item['version'])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete(item)
|
69
|
+
@client.delete_item(
|
70
|
+
table_name: CredStash.config.table_name,
|
71
|
+
key: {
|
72
|
+
name: item.name,
|
73
|
+
version: item.version
|
74
|
+
}
|
75
|
+
)
|
76
|
+
end
|
77
|
+
|
78
|
+
def setup
|
79
|
+
@client.create_table(
|
80
|
+
table_name: CredStash.config.table_name,
|
81
|
+
key_schema: [
|
82
|
+
{ attribute_name: 'name', key_type: 'HASH' },
|
83
|
+
{ attribute_name: 'version', key_type: 'RANGE' },
|
84
|
+
],
|
85
|
+
attribute_definitions: [
|
86
|
+
{ attribute_name: 'name', attribute_type: 'S' },
|
87
|
+
{ attribute_name: 'version', attribute_type: 'S' },
|
88
|
+
],
|
89
|
+
provisioned_throughput: {
|
90
|
+
read_capacity_units: 1,
|
91
|
+
write_capacity_units: 1,
|
92
|
+
},
|
93
|
+
)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module CredStash::Repository
|
2
|
+
class Item
|
3
|
+
attr_reader :key, :contents, :name, :version, :hmac
|
4
|
+
|
5
|
+
def initialize(key: nil, contents: nil, name: nil, version: nil, hmac: nil)
|
6
|
+
@key = key
|
7
|
+
@contents = contents
|
8
|
+
@name = name
|
9
|
+
@version = version
|
10
|
+
@hmac = hmac
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,110 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
attr_reader :key, :contents, :name, :version, :hmac
|
1
|
+
require 'cred_stash/repository/item'
|
2
|
+
require 'cred_stash/repository/dynamo_db'
|
4
3
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
module CredStash::Repository
|
5
|
+
def self.instance
|
6
|
+
case CredStash.config.storage
|
7
|
+
when :dynamodb
|
8
|
+
DynamoDB.new
|
9
|
+
else
|
10
|
+
raise ArgumentError, "Unknown storage #{CredStash.config.storage}"
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
14
|
-
class DynamoDB
|
15
|
-
def initialize(client: nil)
|
16
|
-
@client = client || Aws::DynamoDB::Client.new
|
17
|
-
end
|
18
|
-
|
19
|
-
def get(name)
|
20
|
-
select(name, limit: 1).first.tap do |item|
|
21
|
-
unless item
|
22
|
-
raise CredStash::ItemNotFound, "#{name} is not found"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def select(name, pluck: nil, limit: nil)
|
28
|
-
params = {
|
29
|
-
table_name: CredStash.config.table_name,
|
30
|
-
consistent_read: true,
|
31
|
-
key_condition_expression: "#name = :name",
|
32
|
-
expression_attribute_names: { "#name" => "name"},
|
33
|
-
expression_attribute_values: { ":name" => name }
|
34
|
-
}
|
35
|
-
|
36
|
-
if pluck
|
37
|
-
params[:projection_expression] = pluck
|
38
|
-
end
|
39
|
-
|
40
|
-
if limit
|
41
|
-
params[:limit] = limit
|
42
|
-
params[:scan_index_forward] = false
|
43
|
-
end
|
44
|
-
|
45
|
-
@client.query(params).items.map do |item|
|
46
|
-
Item.new(
|
47
|
-
key: item["key"],
|
48
|
-
contents: item["contents"],
|
49
|
-
name: item["name"],
|
50
|
-
version: item["version"]
|
51
|
-
)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def put(item)
|
56
|
-
@client.put_item(
|
57
|
-
table_name: CredStash.config.table_name,
|
58
|
-
item: {
|
59
|
-
name: item.name,
|
60
|
-
version: item.version,
|
61
|
-
key: item.key,
|
62
|
-
contents: item.contents,
|
63
|
-
hmac: item.hmac
|
64
|
-
},
|
65
|
-
condition_expression: "attribute_not_exists(#name)",
|
66
|
-
expression_attribute_names: { "#name" => "name" },
|
67
|
-
)
|
68
|
-
end
|
69
|
-
|
70
|
-
def list
|
71
|
-
@client.scan(
|
72
|
-
table_name: CredStash.config.table_name,
|
73
|
-
projection_expression: '#name, version',
|
74
|
-
expression_attribute_names: { "#name" => "name" },
|
75
|
-
).items.map do |item|
|
76
|
-
Item.new(name: item['name'], version: item['version'])
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def delete(item)
|
81
|
-
@client.delete_item(
|
82
|
-
table_name: CredStash.config.table_name,
|
83
|
-
key: {
|
84
|
-
name: item.name,
|
85
|
-
version: item.version
|
86
|
-
}
|
87
|
-
)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def self.default_storage
|
92
|
-
DynamoDB.new
|
93
|
-
end
|
94
|
-
|
95
|
-
def initialize(storage: CredStash::Repository.default_storage)
|
96
|
-
@storage = storage
|
97
|
-
end
|
98
|
-
|
99
|
-
def get(name)
|
100
|
-
@storage.get(name)
|
101
|
-
end
|
102
|
-
|
103
|
-
def put(item)
|
104
|
-
@storage.put(item)
|
105
|
-
end
|
106
|
-
|
107
|
-
def select(name, pluck: nil, limit: nil)
|
108
|
-
@storage.select(name, pluck: pluck, limit: limit)
|
109
|
-
end
|
110
13
|
end
|
data/lib/cred_stash/secret.rb
CHANGED
@@ -39,7 +39,7 @@ class CredStash::Secret
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def repository
|
42
|
-
CredStash::Repository.
|
42
|
+
CredStash::Repository.instance
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -57,7 +57,7 @@ class CredStash::Secret
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def current_version
|
60
|
-
item = CredStash::Repository.
|
60
|
+
item = CredStash::Repository.instance.select(name, pluck: 'version', limit: 1).first
|
61
61
|
if item
|
62
62
|
item.version.to_i
|
63
63
|
else
|
data/lib/cred_stash/version.rb
CHANGED
data/lib/cred_stash.rb
CHANGED
@@ -22,20 +22,24 @@ module CredStash
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def list
|
25
|
-
Repository.
|
25
|
+
Repository.instance.list.inject({}) {|h, item| h[item.name] = item.version; h }
|
26
26
|
end
|
27
27
|
|
28
28
|
def delete(name)
|
29
29
|
# TODO needs delete target version option
|
30
|
-
repository = Repository.
|
30
|
+
repository = Repository.instance
|
31
31
|
item = repository.select(name).first
|
32
32
|
repository.delete(item)
|
33
33
|
end
|
34
34
|
|
35
|
+
def setup
|
36
|
+
Repository.instance.setup
|
37
|
+
end
|
38
|
+
|
35
39
|
private
|
36
40
|
|
37
41
|
def get_highest_version(name)
|
38
|
-
item = Repository.
|
42
|
+
item = Repository.instance.select(name, pluck: 'version', limit: 1).first
|
39
43
|
if item
|
40
44
|
item.version.to_i
|
41
45
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcredstash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- adorechic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -89,6 +89,8 @@ files:
|
|
89
89
|
- lib/cred_stash/config.rb
|
90
90
|
- lib/cred_stash/error.rb
|
91
91
|
- lib/cred_stash/repository.rb
|
92
|
+
- lib/cred_stash/repository/dynamo_db.rb
|
93
|
+
- lib/cred_stash/repository/item.rb
|
92
94
|
- lib/cred_stash/secret.rb
|
93
95
|
- lib/cred_stash/version.rb
|
94
96
|
- lib/rcredstash.rb
|
@@ -113,9 +115,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
115
|
version: '0'
|
114
116
|
requirements: []
|
115
117
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
118
|
+
rubygems_version: 2.6.8
|
117
119
|
signing_key:
|
118
120
|
specification_version: 4
|
119
121
|
summary: A Ruby port of CredStash
|
120
122
|
test_files: []
|
121
|
-
has_rdoc:
|