rcredstash 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87738b964c912763c179803996897c9e52d431026ad9973e26891d302a0ee7d6
4
- data.tar.gz: e7eee30911e02377b7bcb904d99afa57364d5406c8b38b96f3e4861c70fed636
3
+ metadata.gz: f5b4072a6a3800e27a23712bb59ee8df5b4ec5be248acd94dbd0711fec3f4f54
4
+ data.tar.gz: 9d3eafb59ea8a166a66a4a79ccf6ed3c93ddfbe110b51ca5accb61d215a79070
5
5
  SHA512:
6
- metadata.gz: 215d2946ea3197dee17ff033642de2958b4628c6f5d56f496ced7cec6be0917c8f5d3611fc3bbd6a590141fcaec75c321a95b8fa15cb002fc936d589202399a3
7
- data.tar.gz: d6cc7e2228276f47193f25ece54fddbaaaebc2aea7b8b7cef8bb7c512a13f243e581d74b56da343e8bd06a330e4cf681af89ce1b6e6fc20fc43c3ca2c9034dbe
6
+ metadata.gz: 3e011ab87a68a9022ebca726c4ee7316d2abaa39a5de721112f74199324b7fb4b5091393f70976c5947f9cf45581831bd2e5e9c035f614d838f71d793310f486
7
+ data.tar.gz: 5d19538fb21c39cdee4906cb447bb49846d3c7111d22afbe66d011846b688b8464c1d65ce1e0a214977f491e7c15d116098daf8a51da2b1ba4e8c5977449ff94
@@ -0,0 +1,28 @@
1
+ name: Ruby CI
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ strategy:
14
+ matrix:
15
+ # Currently supported Ruby versions as of 2024-04-03.
16
+ # See for current status: https://www.ruby-lang.org/en/downloads/branches/
17
+ ruby-version: ['3.3', '3.2', '3.1']
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby ${{ matrix.ruby-version }}
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby-version }}
25
+ - name: Install dependencies
26
+ run: bundle install
27
+ - name: Run tests
28
+ run: AWS_REGION=us-east-1 bundle exec rake
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in rcredstash.gemspec
4
4
  gemspec
5
+
6
+ # Needed to run tests.
7
+ # Could be any of ox, oga, libxml, nokogiri or rexml
8
+ gem 'rexml'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RCredStash [![Build Status](https://travis-ci.org/adorechic/rcredstash.svg?branch=master)](https://travis-ci.org/adorechic/rcredstash)
1
+ # RCredStash ![Build Status](https://github.com/adorechic/rcredstash/actions/workflows/ruby.yml/badge.svg)
2
2
 
3
3
  RCredStash is a ruby port of [CredStash](https://github.com/fugue/credstash)
4
4
 
@@ -56,6 +56,10 @@ RCredStash uses [aws-sdk v2](https://github.com/aws/aws-sdk-ruby), so configurat
56
56
  ```ruby
57
57
  CredStash.configure do |config|
58
58
  config.table_name = 'your_dynamodb_table_name'
59
+
60
+ # Optional, if you want to modify them, like for Localstack.
61
+ config.dynamo_client = Aws::DynamoDB::Client.new
62
+ config.kms_client = Aws::KMS::Client.new
59
63
  end
60
64
  ```
61
65
 
@@ -5,7 +5,7 @@ class CredStash::CipherKey
5
5
 
6
6
  attr_reader :data_key, :hmac_key, :wrapped_key
7
7
 
8
- def self.generate(client: Aws::KMS::Client.new, kms_key_id: nil,
8
+ def self.generate(client: CredStash.config.kms_client, kms_key_id: nil,
9
9
  context: {})
10
10
  res = client.generate_data_key(
11
11
  key_id: kms_key_id || DEFAULT_KMS_KEY_ID,
@@ -19,7 +19,7 @@ class CredStash::CipherKey
19
19
  )
20
20
  end
21
21
 
22
- def self.decrypt(wrapped_key, client: Aws::KMS::Client.new, context: {})
22
+ def self.decrypt(wrapped_key, client: CredStash.config.kms_client, context: {})
23
23
  res = client.decrypt(ciphertext_blob: wrapped_key, encryption_context: context)
24
24
  new(
25
25
  data_key: res.plaintext[0...32],
@@ -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
- def list
21
- puts CredStash.list.keys
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
 
@@ -10,7 +10,7 @@ module CredStash
10
10
  end
11
11
 
12
12
  class Config
13
- attr_accessor :table_name, :storage
13
+ attr_accessor :table_name, :storage, :kms_client, :dynamo_client
14
14
 
15
15
  def initialize
16
16
  reset!
@@ -19,6 +19,8 @@ module CredStash
19
19
  def reset!
20
20
  @table_name = 'credential-store'
21
21
  @storage = :dynamodb
22
+ @kms_client = Aws::KMS::Client.new
23
+ @dynamo_client = Aws::DynamoDB::Client.new
22
24
  end
23
25
  end
24
26
  end
@@ -1,34 +1,23 @@
1
1
  module CredStash::Repository
2
2
  class DynamoDB
3
3
  def initialize(client: nil)
4
- @client = client || Aws::DynamoDB::Client.new
4
+ @client = client || CredStash.config.dynamo_client
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
- raise CredStash::ItemNotFound, "#{name} is not found"
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
@@ -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),
@@ -1,3 +1,3 @@
1
1
  module CredStash
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
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 delete(name)
28
- # TODO needs delete target version option
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", "~> 1.12"
27
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "bundler"
27
+ spec.add_development_dependency "rake"
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.1
4
+ version: 2.0.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: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2024-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-kms
@@ -56,30 +56,30 @@ dependencies:
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.12'
61
+ version: '0'
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: '1.12'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -102,9 +102,9 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".github/workflows/ruby.yml"
105
106
  - ".gitignore"
106
107
  - ".rspec"
107
- - ".travis.yml"
108
108
  - Gemfile
109
109
  - README.md
110
110
  - Rakefile
@@ -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.0.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: []
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.3.1
5
- - 2.2.5
6
- before_install: gem install bundler -v 1.12.5