rcredstash 1.0.1 → 1.1.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/cli.rb +13 -4
- data/lib/cred_stash/repository/dynamo_db.rb +35 -20
- data/lib/cred_stash/secret.rb +2 -2
- data/lib/cred_stash/version.rb +1 -1
- data/lib/cred_stash.rb +13 -5
- data/rcredstash.gemspec +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67d409c186f9c7006ef72dca4f1f60aa350fb868dfd1057c98be393d8f2c37cb
|
4
|
+
data.tar.gz: 0af15c57f304ae9ad1227b3a014f3f966880b7b688d749fb26dcf858153794c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a54e33b123c10b28858e73705a6dafe3fca7e47f7c74d74c171cf5ae49763ebddd620c2ac550b095bd08bdcc7938bdf68940c7e3e1eb34b4398dcc233b889b9
|
7
|
+
data.tar.gz: 89a073eaa083fa4b000d422a9b9887c23ceffc5b1a7ba59662633f482597e896bcd28d25b5f7cc4429c011955ac4eea095055bb75516977f1c3be5e8c1d26027
|
data/lib/cred_stash/cli.rb
CHANGED
@@ -3,8 +3,9 @@ require 'thor'
|
|
3
3
|
module CredStash
|
4
4
|
class CLI < Thor
|
5
5
|
desc "get [key name]", "Show a value for key name"
|
6
|
+
option :version, type: :string, aliases: '-v', desc: 'Show a value for key name with their versions'
|
6
7
|
def get(name)
|
7
|
-
puts CredStash.get(name)
|
8
|
+
puts CredStash.get(name, version: options[:version])
|
8
9
|
end
|
9
10
|
|
10
11
|
desc "put [key name]", "Put a value for key name"
|
@@ -17,13 +18,21 @@ module CredStash
|
|
17
18
|
end
|
18
19
|
|
19
20
|
desc "list", "Show all stored keys"
|
20
|
-
|
21
|
-
|
21
|
+
option :version, type: :boolean, aliases: '-v', desc: 'Show all stored keys with their versions'
|
22
|
+
def list()
|
23
|
+
if options[:version]
|
24
|
+
CredStash.list_with_version.each do |hash|
|
25
|
+
puts "#{hash["name"]} --version: #{hash["version"]}"
|
26
|
+
end
|
27
|
+
else
|
28
|
+
puts CredStash.list.keys
|
29
|
+
end
|
22
30
|
end
|
23
31
|
|
24
32
|
desc "delete [key name]", "Delete a key"
|
33
|
+
option :version, type: :string, aliases: '-v', desc: 'Specify version'
|
25
34
|
def delete(name)
|
26
|
-
CredStash.delete(name)
|
35
|
+
CredStash.delete(name, version: options[:version])
|
27
36
|
puts "#{name} has deleted."
|
28
37
|
end
|
29
38
|
|
@@ -4,31 +4,20 @@ module CredStash::Repository
|
|
4
4
|
@client = client || Aws::DynamoDB::Client.new
|
5
5
|
end
|
6
6
|
|
7
|
-
def get(name)
|
8
|
-
select(name, limit: 1).first.tap do |item|
|
7
|
+
def get(name, version: nil)
|
8
|
+
select(name, limit: 1, version: version).first.tap do |item|
|
9
9
|
unless item
|
10
|
-
|
10
|
+
if version
|
11
|
+
raise CredStash::ItemNotFound, "#{name} --version: #{version} is not found"
|
12
|
+
else
|
13
|
+
raise CredStash::ItemNotFound, "#{name} is not found"
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
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
|
19
|
+
def select(name, pluck: nil, limit: nil, version: nil)
|
20
|
+
params = set_params(name, pluck: pluck, limit: limit, version: version)
|
32
21
|
|
33
22
|
@client.query(params).items.map do |item|
|
34
23
|
Item.new(
|
@@ -109,5 +98,31 @@ module CredStash::Repository
|
|
109
98
|
end
|
110
99
|
all_items
|
111
100
|
end
|
101
|
+
|
102
|
+
def set_params(name, pluck: nil, limit: nil, version: nil)
|
103
|
+
params = {
|
104
|
+
table_name: CredStash.config.table_name,
|
105
|
+
consistent_read: true,
|
106
|
+
key_condition_expression: "#name = :name",
|
107
|
+
expression_attribute_names: { "#name" => "name" },
|
108
|
+
expression_attribute_values: { ":name" => name }
|
109
|
+
}
|
110
|
+
if pluck
|
111
|
+
params[:projection_expression] = pluck
|
112
|
+
end
|
113
|
+
|
114
|
+
if limit
|
115
|
+
params[:limit] = limit
|
116
|
+
params[:scan_index_forward] = false
|
117
|
+
end
|
118
|
+
|
119
|
+
if version
|
120
|
+
params[:key_condition_expression] = "#name = :name AND #version = :version"
|
121
|
+
params[:expression_attribute_names]["#version"] = "version"
|
122
|
+
params[:expression_attribute_values][":version"] = version
|
123
|
+
end
|
124
|
+
|
125
|
+
params
|
126
|
+
end
|
112
127
|
end
|
113
128
|
end
|
data/lib/cred_stash/secret.rb
CHANGED
@@ -29,8 +29,8 @@ class CredStash::Secret
|
|
29
29
|
end
|
30
30
|
|
31
31
|
class << self
|
32
|
-
def find(name, context: {})
|
33
|
-
item = repository.get(name)
|
32
|
+
def find(name, context: {}, version: nil)
|
33
|
+
item = repository.get(name, version: version)
|
34
34
|
new(
|
35
35
|
name: name,
|
36
36
|
key: CredStash::CipherKey.decrypt(Base64.decode64(item.key), context: context),
|
data/lib/cred_stash/version.rb
CHANGED
data/lib/cred_stash.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module CredStash
|
2
2
|
class << self
|
3
|
-
def get(name, context: {}, raise_if_missing: false)
|
4
|
-
secret = Secret.find(name, context: context)
|
3
|
+
def get(name, context: {}, raise_if_missing: false, version: nil)
|
4
|
+
secret = Secret.find(name, context: context, version: version)
|
5
5
|
|
6
6
|
if secret.falsified?
|
7
7
|
raise "Invalid secret. #{name} has falsified"
|
@@ -24,10 +24,18 @@ module CredStash
|
|
24
24
|
Repository.instance.list.inject({}) {|h, item| h[item.name] = item.version; h }
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
|
27
|
+
def list_with_version
|
28
|
+
Repository.instance.list.inject([]) do |h, item|
|
29
|
+
h.push({
|
30
|
+
"name" => item.name,
|
31
|
+
"version" => item.version
|
32
|
+
})
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def delete(name, version: nil)
|
29
37
|
repository = Repository.instance
|
30
|
-
item = repository.select(name).first
|
38
|
+
item = repository.select(name, version: version).first
|
31
39
|
repository.delete(item)
|
32
40
|
end
|
33
41
|
|
data/rcredstash.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_dependency 'aws-sdk-dynamodb'
|
24
24
|
spec.add_dependency 'thor'
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.4"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
end
|
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: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- adorechic
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk-kms
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '2.4'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '2.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +128,7 @@ homepage: https://github.com/adorechic/rcredstash
|
|
128
128
|
licenses:
|
129
129
|
- MIT
|
130
130
|
metadata: {}
|
131
|
-
post_install_message:
|
131
|
+
post_install_message:
|
132
132
|
rdoc_options: []
|
133
133
|
require_paths:
|
134
134
|
- lib
|
@@ -143,8 +143,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
|
-
rubygems_version: 3.
|
147
|
-
signing_key:
|
146
|
+
rubygems_version: 3.4.9
|
147
|
+
signing_key:
|
148
148
|
specification_version: 4
|
149
149
|
summary: A Ruby port of CredStash
|
150
150
|
test_files: []
|