encrypted_yaml 0.0.1
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 +21 -0
- data/.rspec +4 -0
- data/.simplecov +7 -0
- data/Gaurdfile +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +17 -0
- data/bin/enctools +4 -0
- data/encrypted_yaml.gemspec +32 -0
- data/lib/encrypted_yaml.rb +11 -0
- data/lib/encrypted_yaml/cli.rb +7 -0
- data/lib/encrypted_yaml/cli/cli.rb +40 -0
- data/lib/encrypted_yaml/cli/encrypt.rb +51 -0
- data/lib/encrypted_yaml/configurator.rb +62 -0
- data/lib/encrypted_yaml/decrypt.rb +34 -0
- data/lib/encrypted_yaml/version.rb +3 -0
- data/spec/assets/foo.yaml +4 -0
- data/spec/assets/foo.yaml.enc +0 -0
- data/spec/assets/iv +1 -0
- data/spec/assets/key +1 -0
- data/spec/assets/two.yaml +4 -0
- data/spec/assets/two.yaml.enc +1 -0
- data/spec/assets/two_iv +1 -0
- data/spec/assets/two_key +1 -0
- data/spec/lib/encrypted_config/cli/cli_spec.rb +0 -0
- data/spec/lib/encrypted_config/cli/encrypt_spec.rb +0 -0
- data/spec/lib/encrypted_config/cli_spec.rb +0 -0
- data/spec/lib/encrypted_config/configurator_spec.rb +159 -0
- data/spec/lib/encrypted_config/decrypt_spec.rb +0 -0
- data/spec/spec_helper.rb +7 -0
- metadata +231 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0ca0206a6e482598c335e1f57c931795fce27984
|
|
4
|
+
data.tar.gz: be82fb031349c02f3984255c20d2b63673a62eb7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3b2a5000da3c35d85f200aed84d605e5f6c405f2f27ff740536421b99edd27763db25c72cafae63d43268c6fe468296f617c43f07c9605e1c2c2c45c470a3f7d
|
|
7
|
+
data.tar.gz: d19c6407774a3d77e56e973386e634e65b70ef0bca80618bbfc385d6dd1095f2f13ceb143df848898b019431307f1347ac539c071d6b9ded8d4188ca8b7dcd4a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.simplecov
ADDED
data/Gaurdfile
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2014 Brandon Mills
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# EncryptedYaml
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'encrypted_yaml'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install encrypted_yaml
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
TODO: Write usage instructions here
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/encrypted_yaml/fork )
|
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
require 'rspec/core/rake_task'
|
|
3
|
+
|
|
4
|
+
desc 'Run all tests'
|
|
5
|
+
task :test => [:coverage]
|
|
6
|
+
|
|
7
|
+
desc 'Run all rspec tests'
|
|
8
|
+
RSpec::Core::RakeTask.new 'spec' do |t|
|
|
9
|
+
t.pattern = 'spec/**/*_spec.rb'
|
|
10
|
+
t.rspec_opts = '-fd -c'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
task :coverage do
|
|
14
|
+
ENV['COVERAGE'] = 'true'
|
|
15
|
+
Rake::Task['spec'].invoke
|
|
16
|
+
end
|
|
17
|
+
|
data/bin/enctools
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'encrypted_yaml/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "encrypted_yaml"
|
|
8
|
+
spec.version = EncryptedYaml::VERSION
|
|
9
|
+
spec.authors = ["Brandon Mills"]
|
|
10
|
+
spec.email = ["bmillsofthesky@gmail.com"]
|
|
11
|
+
spec.description = %q{Tool for working with encrypted yaml files}
|
|
12
|
+
spec.summary = %q{Tool for working with encrypted yaml files}
|
|
13
|
+
spec.homepage = "https://github.com/RESTful-Forest/Encrypted-YAML"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency 'thor'
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
|
24
|
+
spec.add_development_dependency 'rake'
|
|
25
|
+
spec.add_development_dependency 'rspec'
|
|
26
|
+
spec.add_development_dependency 'guard'
|
|
27
|
+
spec.add_development_dependency 'guard-rspec'
|
|
28
|
+
spec.add_development_dependency 'rb-fsevent'
|
|
29
|
+
spec.add_development_dependency 'simplecov'
|
|
30
|
+
spec.add_development_dependency 'yard'
|
|
31
|
+
spec.add_development_dependency 'redcarpet'
|
|
32
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require 'thor'
|
|
2
|
+
require 'encrypted_yaml/configurator'
|
|
3
|
+
require 'encrypted_yaml/cli/encrypt'
|
|
4
|
+
|
|
5
|
+
module EncryptedYaml::CLI
|
|
6
|
+
class CLI < Thor
|
|
7
|
+
desc 'encrypt YAMLFILE', 'Encrypts the given yaml file with the keys available in the current directory. The keys do not exist, they will be auto-generated.'
|
|
8
|
+
option :key, :default => "key"
|
|
9
|
+
option :iv, :default => "iv"
|
|
10
|
+
def encrypt(filename)
|
|
11
|
+
raise "File does not exist" unless File.exists? filename
|
|
12
|
+
|
|
13
|
+
enc_options = {
|
|
14
|
+
filename: filename,
|
|
15
|
+
keyfile: options[:key],
|
|
16
|
+
ivfile: options[:iv]
|
|
17
|
+
}
|
|
18
|
+
encrypter = EncryptedYaml::CLI::Encrypt.new enc_options
|
|
19
|
+
encrypted_copy = encrypter.encrypt
|
|
20
|
+
|
|
21
|
+
new_filename = "#{filename}.enc"
|
|
22
|
+
File.open(new_filename, 'wb') { |f| f.write encrypted_copy }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
desc 'decrypt YAMLFILE', 'Decrypts the given yaml file with the keys available in the current directory.'
|
|
26
|
+
option :key
|
|
27
|
+
option :iv
|
|
28
|
+
def decrypt(filename)
|
|
29
|
+
raise "File does not exist" unless File.exists? filename
|
|
30
|
+
|
|
31
|
+
decrypt_options = {
|
|
32
|
+
keyfile: options[:key],
|
|
33
|
+
ivfile: options[:iv]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
conf = EncryptedYaml::Configurator.new filename, decrypt_options
|
|
37
|
+
puts conf
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'openssl'
|
|
2
|
+
|
|
3
|
+
module EncryptedYaml
|
|
4
|
+
module CLI
|
|
5
|
+
class Encrypt
|
|
6
|
+
def initialize(options)
|
|
7
|
+
@keyfile = options[:keyfile]
|
|
8
|
+
@ivfile = options[:ivfile]
|
|
9
|
+
@filename = options[:filename]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def encrypt
|
|
13
|
+
data = File.read(@filename)
|
|
14
|
+
|
|
15
|
+
cipher = get_cipher
|
|
16
|
+
cipher.update(data) + cipher.final
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def get_cipher
|
|
22
|
+
cipher = OpenSSL::Cipher::AES256.new :CBC
|
|
23
|
+
cipher.encrypt
|
|
24
|
+
set_key cipher
|
|
25
|
+
set_iv cipher
|
|
26
|
+
|
|
27
|
+
cipher
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def set_key(cipher)
|
|
31
|
+
if File.exists? @keyfile
|
|
32
|
+
cipher.key = File.read(@keyfile)
|
|
33
|
+
return
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
key = cipher.random_key
|
|
37
|
+
File.open(@keyfile, 'wb') { |f| f.write key }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def set_iv(cipher)
|
|
41
|
+
if File.exists? @ivfile
|
|
42
|
+
cipher.iv = File.read(@ivfile)
|
|
43
|
+
return
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
iv = cipher.random_iv
|
|
47
|
+
File.open(@ivfile, 'wb') { |f| f.write iv }
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require 'encrypted_yaml/decrypt'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
|
|
4
|
+
module EncryptedYaml
|
|
5
|
+
# represents an encrypted YAML file as a Hash
|
|
6
|
+
class Configurator < Hash
|
|
7
|
+
# @note The options param has some sane defaults:
|
|
8
|
+
# * for both key and iv, it will prefer the string blob over the filename
|
|
9
|
+
# * if neither the key/iv or filename is defined, it will default to a file named 'key' or 'iv'
|
|
10
|
+
# in the current directory
|
|
11
|
+
# @param [String] filename path to the encrypted
|
|
12
|
+
# @param [Hash] options optional settings for how to find the key and iv
|
|
13
|
+
# @option options [String] :key the encryption key (as a string blob)
|
|
14
|
+
# @option options [String] :iv the encryption iv (as a string blob)
|
|
15
|
+
# @option options [String] :keyfile path to the key file
|
|
16
|
+
# @option options [String] :ivfile path to the iv file
|
|
17
|
+
def initialize(filename, options = {})
|
|
18
|
+
@key = if options[:key]
|
|
19
|
+
options[:key]
|
|
20
|
+
else
|
|
21
|
+
keyfile = options[:keyfile] || File.dirname(filename) + '/key'
|
|
22
|
+
File.read keyfile
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
@iv = if options[:iv]
|
|
26
|
+
options[:iv]
|
|
27
|
+
else
|
|
28
|
+
ivfile = options[:ivfile] || File.dirname(filename) + '/iv'
|
|
29
|
+
File.read ivfile
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
@filename = filename
|
|
33
|
+
load_config
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# returns a new copy with the current values in the configuration file
|
|
37
|
+
# @note does not reload the key or iv
|
|
38
|
+
# @return [EncryptedConfig::Configurator] new copy with the config file reloaded
|
|
39
|
+
def reload_config
|
|
40
|
+
EncryptedYaml::Configurator.new(@filename, {
|
|
41
|
+
:key => @key,
|
|
42
|
+
:iv => @iv
|
|
43
|
+
})
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# reloads the configuration file
|
|
47
|
+
# @note does not reload the key or iv
|
|
48
|
+
def reload_config!
|
|
49
|
+
self.clear
|
|
50
|
+
load_config
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def load_config
|
|
56
|
+
encrypted_data = File.read @filename
|
|
57
|
+
decrypt = EncryptedYaml::Decrypt.new(@key, @iv)
|
|
58
|
+
data = decrypt.decrypt encrypted_data
|
|
59
|
+
self.replace YAML.load(data)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'openssl'
|
|
2
|
+
|
|
3
|
+
module EncryptedYaml
|
|
4
|
+
# Handles decryption
|
|
5
|
+
# @note uses AES256
|
|
6
|
+
class Decrypt
|
|
7
|
+
# @param key [String] encryption key
|
|
8
|
+
# @param iv [String] encyption iv
|
|
9
|
+
def initialize(key, iv)
|
|
10
|
+
@key = key
|
|
11
|
+
@iv = iv
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @param data [String] encrypted data
|
|
15
|
+
# @return [String] decrypted data
|
|
16
|
+
def decrypt(data)
|
|
17
|
+
cipher = get_cipher
|
|
18
|
+
cipher.update(data) + cipher.final
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# @return [OpenSSL::Cipher] initialized cipher ready for decryption
|
|
24
|
+
def get_cipher
|
|
25
|
+
cipher = OpenSSL::Cipher::AES256.new :CBC
|
|
26
|
+
cipher.decrypt
|
|
27
|
+
cipher.key = @key
|
|
28
|
+
cipher.iv = @iv
|
|
29
|
+
|
|
30
|
+
cipher
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
Binary file
|
data/spec/assets/iv
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
A47=g��(M�P��D
|
data/spec/assets/key
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
�1�DGt�,AA�#֒�������V-�m��f
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
��.���F�
|
data/spec/assets/two_iv
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
B�����Q"�J�����
|
data/spec/assets/two_key
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
���]v�x�Ӊ�A�J��3aȔ�5�
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'encrypted_yaml/configurator'
|
|
3
|
+
|
|
4
|
+
describe EncryptedYaml::Configurator do
|
|
5
|
+
before :all do
|
|
6
|
+
Dir.chdir File.join(File.dirname(__FILE__), '..', '..', 'assets')
|
|
7
|
+
|
|
8
|
+
@key = File.read 'two_key'
|
|
9
|
+
@iv = File.read 'two_iv'
|
|
10
|
+
@encfile = File.read 'two.yaml.enc'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
describe :initialize do
|
|
14
|
+
it 'is a Hash' do
|
|
15
|
+
conf = EncryptedYaml::Configurator.new 'foo.yaml.enc'
|
|
16
|
+
expect(conf).to be_a_kind_of(Hash)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'returns a decrypted version of the encrypted YAML' do
|
|
20
|
+
conf = EncryptedYaml::Configurator.new 'foo.yaml.enc'
|
|
21
|
+
expect(conf[:foo]).to eq([:bar, :baz])
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
context 'no options are provided' do
|
|
25
|
+
it 'defaults to loading a keyfile named "key" and an ivfile named "iv"' do
|
|
26
|
+
expect(File).to receive(:read).with('./key').ordered.and_return(@key)
|
|
27
|
+
expect(File).to receive(:read).with('./iv').ordered.and_return(@iv)
|
|
28
|
+
expect(File).to receive(:read).with('foo.yaml.enc').ordered.and_return(@encfile)
|
|
29
|
+
|
|
30
|
+
conf = EncryptedYaml::Configurator.new 'foo.yaml.enc'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
context ':keyfile is provided' do
|
|
35
|
+
it 'loads the key from the provided keyfile' do
|
|
36
|
+
expect(File).to receive(:read).with('two_key').ordered.and_return(@key)
|
|
37
|
+
expect(File).to receive(:read).with('./iv').ordered.and_return(@iv)
|
|
38
|
+
expect(File).to receive(:read).with('two.yaml.enc').ordered.and_return(@encfile)
|
|
39
|
+
|
|
40
|
+
EncryptedYaml::Configurator.new 'two.yaml.enc', keyfile: 'two_key'
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
context ':ivfile is provided' do
|
|
44
|
+
it 'loads the iv from the provided ivfile' do
|
|
45
|
+
expect(File).to receive(:read).with('two_key').ordered.and_return(@key)
|
|
46
|
+
expect(File).to receive(:read).with('two_iv').ordered.and_return(@iv)
|
|
47
|
+
expect(File).to receive(:read).with('two.yaml.enc').ordered.and_return(@encfile)
|
|
48
|
+
|
|
49
|
+
EncryptedYaml::Configurator.new 'two.yaml.enc', keyfile: 'two_key', ivfile: 'two_iv'
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context ':iv is provided' do
|
|
54
|
+
it 'uses the provided string as the iv' do
|
|
55
|
+
expect(File).to receive(:read).with('two_key').ordered.and_return(@key)
|
|
56
|
+
expect(File).to receive(:read).with('two.yaml.enc').ordered.and_return(@encfile)
|
|
57
|
+
expect(File).to_not receive(:read).with('two_iv')
|
|
58
|
+
expect(File).to_not receive(:read).with('iv')
|
|
59
|
+
|
|
60
|
+
EncryptedYaml::Configurator.new 'two.yaml.enc', keyfile: 'two_key', iv: @iv
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
context ':key is provided' do
|
|
65
|
+
it 'prefers the key string and does not attempt to load the keyfile' do
|
|
66
|
+
expect(File).to receive(:read).with('two.yaml.enc').ordered.and_return(@encfile)
|
|
67
|
+
expect(File).to_not receive(:read).with('two_key')
|
|
68
|
+
expect(File).to_not receive(:read).with('key')
|
|
69
|
+
|
|
70
|
+
EncryptedYaml::Configurator.new 'two.yaml.enc', keyfile: 'two_key', key: @key, iv: @iv
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
context ':key is provided' do
|
|
76
|
+
it 'uses the provided string as the key' do
|
|
77
|
+
expect(File).to receive(:read).with('two.yaml.enc').ordered.and_return(@encfile)
|
|
78
|
+
expect(File).to_not receive(:read).with('two_key')
|
|
79
|
+
expect(File).to_not receive(:read).with('key')
|
|
80
|
+
|
|
81
|
+
EncryptedYaml::Configurator.new 'two.yaml.enc', key: @key, iv: @iv
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
context ':keyfile is provided' do
|
|
85
|
+
it 'prefers :key over :keyfile' do
|
|
86
|
+
expect(File).to receive(:read).with('two.yaml.enc').ordered.and_return(@encfile)
|
|
87
|
+
expect(File).to_not receive(:read).with('two_key')
|
|
88
|
+
expect(File).to_not receive(:read).with('key')
|
|
89
|
+
|
|
90
|
+
EncryptedYaml::Configurator.new 'two.yaml.enc', key: @key, iv: @iv, keyfile: 'two_key'
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context ':ivfile is provided' do
|
|
96
|
+
it 'loads the ivfile and uses it as the iv' do
|
|
97
|
+
expect(File).to receive(:read).with('two_iv').ordered.and_return(@iv)
|
|
98
|
+
expect(File).to receive(:read).with('two.yaml.enc').ordered.and_return(@encfile)
|
|
99
|
+
|
|
100
|
+
EncryptedYaml::Configurator.new 'two.yaml.enc', key: @key, ivfile: 'two_iv'
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
context ':iv is provided' do
|
|
104
|
+
it 'prefers :iv over :ivfile' do
|
|
105
|
+
expect(File).to receive(:read).with('two.yaml.enc').ordered.and_return(@encfile)
|
|
106
|
+
expect(File).to_not receive(:read).with('two_iv')
|
|
107
|
+
expect(File).to_not receive(:read).with('iv')
|
|
108
|
+
|
|
109
|
+
EncryptedYaml::Configurator.new 'two.yaml.enc', key: @key, ivfile: 'two_iv', iv: @iv
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
describe :reload_config do
|
|
117
|
+
it 'reloads the configuration file' do
|
|
118
|
+
expected_config = {:hello => [:world, :murica]}
|
|
119
|
+
conf = EncryptedYaml::Configurator.new 'two.yaml.enc', key: @key, iv: @iv
|
|
120
|
+
expect(conf).to eq(expected_config) # did it load?
|
|
121
|
+
|
|
122
|
+
conf.clear
|
|
123
|
+
expect(conf).to eq({}) # is it empty now?
|
|
124
|
+
|
|
125
|
+
new_conf = conf.reload_config
|
|
126
|
+
expect(new_conf).to eq(expected_config) # did it load?
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
it 'returns a new copy' do
|
|
130
|
+
expected_config = {:hello => [:world, :murica]}
|
|
131
|
+
conf = EncryptedYaml::Configurator.new 'two.yaml.enc', key: @key, iv: @iv
|
|
132
|
+
expect(conf).to eq(expected_config) # did it load?
|
|
133
|
+
|
|
134
|
+
new_conf = conf.reload_config
|
|
135
|
+
expect(new_conf).to_not be(conf) # is it a new object?
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
describe :reload_config! do
|
|
140
|
+
it 'reloads the configuration file' do
|
|
141
|
+
expected_config = {:hello => [:world, :murica]}
|
|
142
|
+
conf = EncryptedYaml::Configurator.new 'two.yaml.enc', key: @key, iv: @iv
|
|
143
|
+
expect(conf).to eq(expected_config)
|
|
144
|
+
|
|
145
|
+
conf.clear
|
|
146
|
+
expect(conf).to eq({})
|
|
147
|
+
|
|
148
|
+
conf.reload_config!
|
|
149
|
+
expect(conf).to eq(expected_config)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'is the same object' do
|
|
153
|
+
conf = EncryptedYaml::Configurator.new 'two.yaml.enc', key: @key, iv: @iv
|
|
154
|
+
new_conf = conf.reload_config!
|
|
155
|
+
expect(new_conf).to be(conf)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
end
|
|
File without changes
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: encrypted_yaml
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Brandon Mills
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: thor
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.3'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.3'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: guard
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: guard-rspec
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rb-fsevent
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: simplecov
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
- !ruby/object:Gem::Dependency
|
|
126
|
+
name: yard
|
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: '0'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - ">="
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: redcarpet
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - ">="
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0'
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
153
|
+
description: Tool for working with encrypted yaml files
|
|
154
|
+
email:
|
|
155
|
+
- bmillsofthesky@gmail.com
|
|
156
|
+
executables:
|
|
157
|
+
- enctools
|
|
158
|
+
extensions: []
|
|
159
|
+
extra_rdoc_files: []
|
|
160
|
+
files:
|
|
161
|
+
- ".gitignore"
|
|
162
|
+
- ".rspec"
|
|
163
|
+
- ".simplecov"
|
|
164
|
+
- Gaurdfile
|
|
165
|
+
- Gemfile
|
|
166
|
+
- LICENSE.txt
|
|
167
|
+
- README.md
|
|
168
|
+
- Rakefile
|
|
169
|
+
- bin/enctools
|
|
170
|
+
- encrypted_yaml.gemspec
|
|
171
|
+
- lib/encrypted_yaml.rb
|
|
172
|
+
- lib/encrypted_yaml/cli.rb
|
|
173
|
+
- lib/encrypted_yaml/cli/cli.rb
|
|
174
|
+
- lib/encrypted_yaml/cli/encrypt.rb
|
|
175
|
+
- lib/encrypted_yaml/configurator.rb
|
|
176
|
+
- lib/encrypted_yaml/decrypt.rb
|
|
177
|
+
- lib/encrypted_yaml/version.rb
|
|
178
|
+
- spec/assets/foo.yaml
|
|
179
|
+
- spec/assets/foo.yaml.enc
|
|
180
|
+
- spec/assets/iv
|
|
181
|
+
- spec/assets/key
|
|
182
|
+
- spec/assets/two.yaml
|
|
183
|
+
- spec/assets/two.yaml.enc
|
|
184
|
+
- spec/assets/two_iv
|
|
185
|
+
- spec/assets/two_key
|
|
186
|
+
- spec/lib/encrypted_config/cli/cli_spec.rb
|
|
187
|
+
- spec/lib/encrypted_config/cli/encrypt_spec.rb
|
|
188
|
+
- spec/lib/encrypted_config/cli_spec.rb
|
|
189
|
+
- spec/lib/encrypted_config/configurator_spec.rb
|
|
190
|
+
- spec/lib/encrypted_config/decrypt_spec.rb
|
|
191
|
+
- spec/spec_helper.rb
|
|
192
|
+
homepage: https://github.com/RESTful-Forest/Encrypted-YAML
|
|
193
|
+
licenses:
|
|
194
|
+
- MIT
|
|
195
|
+
metadata: {}
|
|
196
|
+
post_install_message:
|
|
197
|
+
rdoc_options: []
|
|
198
|
+
require_paths:
|
|
199
|
+
- lib
|
|
200
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
201
|
+
requirements:
|
|
202
|
+
- - ">="
|
|
203
|
+
- !ruby/object:Gem::Version
|
|
204
|
+
version: '0'
|
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
|
+
requirements:
|
|
207
|
+
- - ">="
|
|
208
|
+
- !ruby/object:Gem::Version
|
|
209
|
+
version: '0'
|
|
210
|
+
requirements: []
|
|
211
|
+
rubyforge_project:
|
|
212
|
+
rubygems_version: 2.4.4
|
|
213
|
+
signing_key:
|
|
214
|
+
specification_version: 4
|
|
215
|
+
summary: Tool for working with encrypted yaml files
|
|
216
|
+
test_files:
|
|
217
|
+
- spec/assets/foo.yaml
|
|
218
|
+
- spec/assets/foo.yaml.enc
|
|
219
|
+
- spec/assets/iv
|
|
220
|
+
- spec/assets/key
|
|
221
|
+
- spec/assets/two.yaml
|
|
222
|
+
- spec/assets/two.yaml.enc
|
|
223
|
+
- spec/assets/two_iv
|
|
224
|
+
- spec/assets/two_key
|
|
225
|
+
- spec/lib/encrypted_config/cli/cli_spec.rb
|
|
226
|
+
- spec/lib/encrypted_config/cli/encrypt_spec.rb
|
|
227
|
+
- spec/lib/encrypted_config/cli_spec.rb
|
|
228
|
+
- spec/lib/encrypted_config/configurator_spec.rb
|
|
229
|
+
- spec/lib/encrypted_config/decrypt_spec.rb
|
|
230
|
+
- spec/spec_helper.rb
|
|
231
|
+
has_rdoc:
|