sekrat 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.txt +21 -0
- data/README.md +93 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sekrat.rb +26 -0
- data/lib/sekrat/crypter.rb +7 -0
- data/lib/sekrat/crypter/base.rb +26 -0
- data/lib/sekrat/crypter/passthrough.rb +27 -0
- data/lib/sekrat/errors.rb +18 -0
- data/lib/sekrat/manager.rb +80 -0
- data/lib/sekrat/version.rb +3 -0
- data/lib/sekrat/warehouse.rb +8 -0
- data/lib/sekrat/warehouse/base.rb +31 -0
- data/lib/sekrat/warehouse/memory.rb +44 -0
- data/sekrat.gemspec +29 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19ad2fb32c160d5b9a44061198b9c1a808bb8c5246d8d28bd895a9893b0fe1d4
|
4
|
+
data.tar.gz: b03bf456716f5801ded1fff08c781386f77891dc8acfce4ca321cda23e0a222a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e44464eae2d6d6855b1e3806c187e873aa39fce7bd136f41d1d353f1e072c7649454fba559b91e915daac06ab7b57507b6370bc6e5f6f839977ab676f4c627eb
|
7
|
+
data.tar.gz: b575a641081f175830949a17833b4ded23d768b3d79aa83cb69e83e7ea29aec09d0885db25654cd41dc400186b78d29376aea026172149d0fffb7219dd402637
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
sekrat
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at pooster@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
sekrat (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
docile (1.3.1)
|
11
|
+
json (2.1.0)
|
12
|
+
rake (10.5.0)
|
13
|
+
rspec (3.8.0)
|
14
|
+
rspec-core (~> 3.8.0)
|
15
|
+
rspec-expectations (~> 3.8.0)
|
16
|
+
rspec-mocks (~> 3.8.0)
|
17
|
+
rspec-core (3.8.0)
|
18
|
+
rspec-support (~> 3.8.0)
|
19
|
+
rspec-expectations (3.8.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-mocks (3.8.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-support (3.8.0)
|
26
|
+
simplecov (0.16.1)
|
27
|
+
docile (~> 1.1)
|
28
|
+
json (>= 1.8, < 3)
|
29
|
+
simplecov-html (~> 0.10.0)
|
30
|
+
simplecov-html (0.10.2)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.16)
|
37
|
+
rake (~> 10.0)
|
38
|
+
rspec (~> 3.0)
|
39
|
+
sekrat!
|
40
|
+
simplecov (~> 0.16)
|
41
|
+
|
42
|
+
BUNDLED WITH
|
43
|
+
1.16.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Dennis Walters
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Sekrat
|
2
|
+
|
3
|
+
Sekrat is an embedded key/value store for secrets. These secrets are stored in a Warehouse (Memory, Filesystem, Amazon S3, etc), and they are encrypted/decrypted with a Crypter (Passthrough, AES, etc).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'sekrat'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install sekrat
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The basic usage for Sekrat goes something like this:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'sekrat'
|
27
|
+
|
28
|
+
# Create a secret manager to put and get secrets.
|
29
|
+
confidant = Sekrat.manager
|
30
|
+
|
31
|
+
# Create a secret
|
32
|
+
confidant.put("my sausages", "supersecretkey", "turned to gold")
|
33
|
+
|
34
|
+
# Retrieve that secret
|
35
|
+
confidant.get("my sausages", "supersecretkey")
|
36
|
+
```
|
37
|
+
|
38
|
+
In the above, we don't provide a warehouse or a crypter for the manager to use to do its thing, so the defaults (respectively, in-memory hash storage of plain text data) are used. An equivalent manager could be set up like so:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require 'sekrat'
|
42
|
+
require 'sekrat/warehouse/memory'
|
43
|
+
require 'sekrat/crypter/passthrough'
|
44
|
+
|
45
|
+
confidant = Sekrat.manager(
|
46
|
+
warehouse: Sekrat::Warehouse::Memory.new,
|
47
|
+
crypter: Sekrat::Crypter::Passthrough.new
|
48
|
+
)
|
49
|
+
```
|
50
|
+
|
51
|
+
All that said, things don't really get interesting until you add in a Warehouse and a Crypter other than the defaults.
|
52
|
+
|
53
|
+
### Warehouses ###
|
54
|
+
|
55
|
+
A warehouse is any object that conforms the `Sekrat::Warehouse::Base` API:
|
56
|
+
|
57
|
+
* `ids` returns an array of all known secret IDs in the warehouse
|
58
|
+
* `store(id, data)` stores the provided data indexed by the provided ID, raising an error if there are any issues (and specifically `Sekrat::StorageFailure` if there is a problem actually storing the secret)
|
59
|
+
* `retrieve(id)` retrieves and returns the ID-indexed data, raising an error if there are any issues (and specifically `Sekrat::NotFound` if the secret is not already stored in the warehouse)
|
60
|
+
|
61
|
+
To help a bit with Warehouse development, you can `include Sekrat::Warehouse::Base` in your implementation. It contains all of the methods in the Warehouse API, all of which raise `Sekrat::NotImplemented` until you override them.
|
62
|
+
|
63
|
+
The only warehouse included in the base gem is `Sekrat::Warehouse::Memory`, which stores secrets in an in-memory hash. That's only really useful in initial testing and development, so it would be a very good idea to either create your own warehouse or maybe peruse [Warehouse Implementations](https://github.com/sekrat/sekrat-ruby/wiki/Warehouse-Implementations).
|
64
|
+
|
65
|
+
### Crypters ###
|
66
|
+
|
67
|
+
A Crypter is any object that conforms to the `Sekrat::Crypter::Base` API:
|
68
|
+
|
69
|
+
* `encrypt(key, data)` encrypts the given data with the provided key and returns that encrypted data, raising an error if there are any issues (and specifically `Sekrat::EncryptFailure` if there is a problem encrypting the data)
|
70
|
+
* `decrypt(key, data)` decrypts the given data with the provided key and returns that decrypted data, raising an error if there are any issues (and specifically `Sekrat::DecryptFailure`)
|
71
|
+
|
72
|
+
To help a bit with Crypter development, you can `include Sekrat::Warehouse::Base` in your implementation. It contains all of the methods in the Crypter API, all of which raise `Sekrat::NotImplemented` until you override them.
|
73
|
+
|
74
|
+
The only crypter included in the base gem is `Sekrat::Warehouse::Passthrough`, which doesn't actually do anything at all ... its method just return the provided data. That's only really useful in initial testing and development, so it would be a very good idea to either create your own crypter or maybe peruse [Crypter Implementations](https://github.com/sekrat/sekrat-ruby/wiki/Crypter-Implementations).
|
75
|
+
|
76
|
+
|
77
|
+
## Development
|
78
|
+
|
79
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
80
|
+
|
81
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
82
|
+
|
83
|
+
## Contributing
|
84
|
+
|
85
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sekrat/sekrat. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
86
|
+
|
87
|
+
## License
|
88
|
+
|
89
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
90
|
+
|
91
|
+
## Code of Conduct
|
92
|
+
|
93
|
+
Everyone interacting in the Sekrat project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sekrat/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sekrat"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/sekrat.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "sekrat/version"
|
2
|
+
|
3
|
+
require 'sekrat/crypter/passthrough'
|
4
|
+
require 'sekrat/manager'
|
5
|
+
require 'sekrat/warehouse/memory'
|
6
|
+
|
7
|
+
# An embedded key/value store with pluggable storage and encryption
|
8
|
+
module Sekrat
|
9
|
+
|
10
|
+
# Create a new secret manager. If a warehouse is provided, that warehouse is
|
11
|
+
# used for the manager. Otherwise, the default warehouse, Memory, is used. IF
|
12
|
+
# a crypter is provided, that crypter is used for the manager. Otherwise, the
|
13
|
+
# default crypter, Passthrough, is used.
|
14
|
+
#
|
15
|
+
# @param warehouse: [Sekrat::Warehouse::Base] the warehouse in which to store
|
16
|
+
# secrets
|
17
|
+
# @param crypter: [Sekrat::Crypter::Base] the crypter with which to encrypt
|
18
|
+
# and decrypt secrets
|
19
|
+
# @return [Sekrat::Manager]
|
20
|
+
def self.manager(warehouse: nil, crypter: nil)
|
21
|
+
Manager.new(
|
22
|
+
warehouse: warehouse || Warehouse::Memory.new,
|
23
|
+
crypter: crypter || Crypter::Passthrough.new
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'sekrat/errors'
|
2
|
+
|
3
|
+
module Sekrat
|
4
|
+
module Crypter
|
5
|
+
|
6
|
+
# A base mixin for would-be Sekrat::Crypter implementations
|
7
|
+
module Base
|
8
|
+
|
9
|
+
# A stub for incomplete warehouse implementations
|
10
|
+
# @param key [String] a key that will never get used
|
11
|
+
# @param data [String] some data that will never get used
|
12
|
+
# @raise [Sekrat::NotImplemented]
|
13
|
+
def encrypt(key, data)
|
14
|
+
raise NotImplemented.new("encrypt is not implemented")
|
15
|
+
end
|
16
|
+
|
17
|
+
# A stub for incomplete warehouse implementations
|
18
|
+
# @param key [String] a key that will never get used
|
19
|
+
# @param data [String] some data that will never get used
|
20
|
+
# @raise [Sekrat::NotImplemented]
|
21
|
+
def decrypt(key, data)
|
22
|
+
raise NotImplemented.new("decrypt is not implemented")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'sekrat/crypter/base'
|
2
|
+
|
3
|
+
module Sekrat
|
4
|
+
module Crypter
|
5
|
+
|
6
|
+
# A crypter that doesn't actually do any crypting
|
7
|
+
class Passthrough
|
8
|
+
include Base
|
9
|
+
|
10
|
+
# Given a key and some data, use that key to encrypt the data.
|
11
|
+
# @param key [String] the encryption key to use
|
12
|
+
# @param data [String] the data to encrypt
|
13
|
+
# @return [String] the original data
|
14
|
+
def encrypt(key, data)
|
15
|
+
data
|
16
|
+
end
|
17
|
+
|
18
|
+
# Given a key and some data, use that key to decrypt the data.
|
19
|
+
# @param key [String] the encryption key to use
|
20
|
+
# @param data [String] the data to decrypt
|
21
|
+
# @return [String] the decrypted data
|
22
|
+
def decrypt(key, data)
|
23
|
+
data
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Sekrat
|
2
|
+
|
3
|
+
# The base error for all other Sekrat errors
|
4
|
+
Error = Class.new(StandardError)
|
5
|
+
|
6
|
+
# An issue came up while attempting to decrypt data
|
7
|
+
DecryptFailure = Class.new(Error)
|
8
|
+
# An issue came up while attempting to encrypt data
|
9
|
+
EncryptFailure = Class.new(Error)
|
10
|
+
|
11
|
+
# An issue came up while retrieving data
|
12
|
+
NotFound = Class.new(Error)
|
13
|
+
# An issue came up while storing data
|
14
|
+
StorageFailure = Class.new(Error)
|
15
|
+
|
16
|
+
# The Warehouse or Crypter implementation is incomplete
|
17
|
+
NotImplemented = Class.new(Error)
|
18
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'sekrat/errors'
|
2
|
+
|
3
|
+
module Sekrat
|
4
|
+
|
5
|
+
# A secret manager that coordinates both storage and encryption
|
6
|
+
class Manager
|
7
|
+
|
8
|
+
# @return [Sekrat::Crypter::Base] the manager's crypter
|
9
|
+
attr_reader :crypter
|
10
|
+
|
11
|
+
# @return [Sekrat::Warehouse::Base] the manager's warehouse
|
12
|
+
attr_reader :warehouse
|
13
|
+
|
14
|
+
# Initialize a new manager
|
15
|
+
# @param warehouse: [Sekrat::Warehouse::Base] the warehouse to use for
|
16
|
+
# secret storage
|
17
|
+
# @param crypter: [Sekrat::Crypter::Base] the crypter to use for encrypting
|
18
|
+
# and decrypting secrets
|
19
|
+
def initialize(warehouse:, crypter:)
|
20
|
+
@warehouse = warehouse
|
21
|
+
@crypter = crypter
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get the IDs that the manager knows about
|
25
|
+
# @return [Array<String>] the list of secret IDs
|
26
|
+
def ids
|
27
|
+
warehouse.ids
|
28
|
+
end
|
29
|
+
|
30
|
+
# Given a secret id, an encryption key, and some data, encrypt the data and
|
31
|
+
# store it, indexed by ID
|
32
|
+
# @param id [String] the ID for the secret
|
33
|
+
# @param key [String] the key to use for encrypting the data
|
34
|
+
# @param data [String] the data to save
|
35
|
+
# @return [String] the original data
|
36
|
+
# @raise [Sekrat::EncryptFailure] if there is a problem with encrypting the
|
37
|
+
# data
|
38
|
+
# @raise [Sekrat::StorageFailure] if there is a problem storing the secret
|
39
|
+
# @raise [Sekrat::Error] if any other problem comes up
|
40
|
+
def put(id, key, data)
|
41
|
+
begin
|
42
|
+
data.tap {|data| warehouse.store(id, crypter.encrypt(key, data))}
|
43
|
+
rescue EncryptFailure
|
44
|
+
raise EncryptFailure.new("could not encrypt '#{id}'")
|
45
|
+
rescue StorageFailure
|
46
|
+
raise StorageFailure.new("could not store '#{id}'")
|
47
|
+
rescue => error
|
48
|
+
raise Error.new(
|
49
|
+
"an unknown error (#{error}) occurred trying to save '#{id}'"
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Given a secret ID and an encryption key, retrieve the decrypted secret
|
55
|
+
# @param id [String] the ID of the secret to retrieve
|
56
|
+
# @param key [String] the key to use to decrypt the secret
|
57
|
+
# @return [String] the decrypted secret
|
58
|
+
# @raise [Sekrat::DecryptFailure] if there is a problem decrypting the
|
59
|
+
# secret
|
60
|
+
# @raise [Sekrat::NotFound] if the requested secret is not known
|
61
|
+
# @raise [Sekrat::Error] if any other problem comes up
|
62
|
+
def get(id, key)
|
63
|
+
begin
|
64
|
+
crypter.decrypt(
|
65
|
+
key,
|
66
|
+
warehouse.retrieve(id)
|
67
|
+
)
|
68
|
+
rescue DecryptFailure
|
69
|
+
raise DecryptFailure.new("could not decrypt '#{id}'")
|
70
|
+
rescue NotFound
|
71
|
+
raise NotFound.new("could not retrieve '#{id}'")
|
72
|
+
rescue => error
|
73
|
+
raise Error.new(
|
74
|
+
"an unknown error (#{error}) occurred trying to load '#{id}'"
|
75
|
+
)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'sekrat/errors'
|
2
|
+
|
3
|
+
module Sekrat
|
4
|
+
module Warehouse
|
5
|
+
|
6
|
+
# A base mixin for would-be Sekrat::Warehouse implementations
|
7
|
+
module Base
|
8
|
+
|
9
|
+
# A stub for incomplete warehouse implementations
|
10
|
+
# @raise [Sekrat::NotImplemented]
|
11
|
+
def ids
|
12
|
+
raise NotImplemented.new("ids is not implemented")
|
13
|
+
end
|
14
|
+
|
15
|
+
# A stub for incomplete warehouse implementations
|
16
|
+
# @param id [String] an ID that will never get used
|
17
|
+
# @param data [String] some data that will never get used
|
18
|
+
# @raise [Sekrat::NotImplemented]
|
19
|
+
def store(id, data)
|
20
|
+
raise NotImplemented.new("store is not implemented")
|
21
|
+
end
|
22
|
+
|
23
|
+
# A stub for incomplete warehouse implementations
|
24
|
+
# @param id [String] an id that will never get used
|
25
|
+
# @raise [Sekrat::NotImplemented]
|
26
|
+
def retrieve(id)
|
27
|
+
raise NotImplemented.new("retrieve is not implemented")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'sekrat/warehouse/base'
|
2
|
+
|
3
|
+
module Sekrat
|
4
|
+
module Warehouse
|
5
|
+
|
6
|
+
# An in-memory warehouse for storing secrets
|
7
|
+
class Memory
|
8
|
+
include Base
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@storage = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
# Get the list of ids for the secrets stored in the warehouse
|
15
|
+
# @return [Array<String>] the list of keys
|
16
|
+
def ids
|
17
|
+
storage.keys
|
18
|
+
end
|
19
|
+
|
20
|
+
# Given an id and some data, store the data indexed by the id
|
21
|
+
# @param id [String] the id for the secret
|
22
|
+
# @param data [String] the data to store
|
23
|
+
# @return [String] the data stored
|
24
|
+
def store(id, data)
|
25
|
+
storage[id] = data
|
26
|
+
end
|
27
|
+
|
28
|
+
# Given an id, get its associated stored data
|
29
|
+
# @param id [String] the id of the secret
|
30
|
+
# @return [String] the secret data
|
31
|
+
# @raise [Sekrat::NotFound] if the secret does not exist
|
32
|
+
def retrieve(id)
|
33
|
+
raise NotFound.new("id '#{id}'") unless ids.include?(id)
|
34
|
+
|
35
|
+
storage[id]
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def storage
|
40
|
+
@storage
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/sekrat.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "sekrat/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sekrat"
|
8
|
+
spec.version = Sekrat::VERSION
|
9
|
+
spec.authors = ["Dennis Walters"]
|
10
|
+
spec.email = ["pooster@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{An embedded key/value store with pluggable storage and encryption}
|
13
|
+
spec.homepage = "https://github.com/sekrat/sekrat-ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
28
|
+
spec.add_development_dependency 'simplecov', '~> 0.16'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sekrat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Walters
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: simplecov
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.16'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- pooster@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
80
|
+
- ".travis.yml"
|
81
|
+
- CODE_OF_CONDUCT.md
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- bin/console
|
88
|
+
- bin/setup
|
89
|
+
- lib/sekrat.rb
|
90
|
+
- lib/sekrat/crypter.rb
|
91
|
+
- lib/sekrat/crypter/base.rb
|
92
|
+
- lib/sekrat/crypter/passthrough.rb
|
93
|
+
- lib/sekrat/errors.rb
|
94
|
+
- lib/sekrat/manager.rb
|
95
|
+
- lib/sekrat/version.rb
|
96
|
+
- lib/sekrat/warehouse.rb
|
97
|
+
- lib/sekrat/warehouse/base.rb
|
98
|
+
- lib/sekrat/warehouse/memory.rb
|
99
|
+
- sekrat.gemspec
|
100
|
+
homepage: https://github.com/sekrat/sekrat-ruby
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.7.7
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: An embedded key/value store with pluggable storage and encryption
|
124
|
+
test_files: []
|