secret_data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +18 -0
- data/Gemfile +24 -0
- data/Guardfile +38 -0
- data/LICENSE +22 -0
- data/README.md +58 -0
- data/Rakefile +2 -0
- data/config.yml +4 -0
- data/lib/secret_data.rb +9 -0
- data/lib/secret_data/silencer.rb +70 -0
- data/lib/secret_data/version.rb +3 -0
- data/secret_data.gemspec +21 -0
- data/spec/lib/secret_data/silencer_spec.rb +65 -0
- data/spec/lib/secret_data/version_spec.rb +5 -0
- data/spec/lib/secret_data_spec.rb +7 -0
- data/spec/spec_helper.rb +30 -0
- metadata +75 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without development darwin linux
|
3
|
+
rvm:
|
4
|
+
- 1.9.3
|
5
|
+
- 1.9.2
|
6
|
+
- jruby-18mode
|
7
|
+
- jruby-19mode
|
8
|
+
- rbx-18mode
|
9
|
+
- rbx-19mode
|
10
|
+
- ruby-head
|
11
|
+
- jruby-head
|
12
|
+
- ree
|
13
|
+
script:
|
14
|
+
- bundle exec rspec
|
15
|
+
branch:
|
16
|
+
only:
|
17
|
+
- master
|
18
|
+
- develop
|
data/Gemfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in secret_data.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test, :development do
|
7
|
+
gem 'rspec'
|
8
|
+
gem 'fakefs'
|
9
|
+
end
|
10
|
+
|
11
|
+
group :development do
|
12
|
+
gem 'rake'
|
13
|
+
gem 'simplecov'
|
14
|
+
gem 'redcarpet'
|
15
|
+
|
16
|
+
gem 'guard-bundler'
|
17
|
+
gem 'guard-rspec'
|
18
|
+
gem 'guard-yard'
|
19
|
+
|
20
|
+
# Watch file change events instead of polling
|
21
|
+
gem 'rb-fsevent', :require => false, :group => :darwin # OSX
|
22
|
+
gem 'rb-inotify', :require => false, :group => :linux # Linux
|
23
|
+
gem 'wdm', :require => false, :platforms => [:mswin, :mingw] # Windows
|
24
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# A sample Guardfile
|
4
|
+
# More info at https://github.com/guard/guard#readme
|
5
|
+
|
6
|
+
guard 'bundler' do
|
7
|
+
watch('Gemfile')
|
8
|
+
# Uncomment next line if Gemfile contain `gemspec' command
|
9
|
+
# watch(/^.+\.gemspec/)
|
10
|
+
end
|
11
|
+
|
12
|
+
guard 'rspec' do
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
|
17
|
+
# Rails example
|
18
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
19
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
20
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
21
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
22
|
+
watch('config/routes.rb') { "spec/routing" }
|
23
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
24
|
+
|
25
|
+
# Capybara request specs
|
26
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
27
|
+
|
28
|
+
# Turnip features and steps
|
29
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
30
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
guard 'yard' do
|
35
|
+
watch(%r{app/.+\.rb})
|
36
|
+
watch(%r{lib/.+\.rb})
|
37
|
+
watch(%r{ext/.+\.c})
|
38
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Alexander Wenzowski
|
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,58 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/wenzowski/secret-data.png)](http://travis-ci.org/wenzowski/secret-data)
|
2
|
+
|
3
|
+
SecretData
|
4
|
+
==========
|
5
|
+
|
6
|
+
A helper class for silencing secret data.
|
7
|
+
|
8
|
+
|
9
|
+
Installation
|
10
|
+
------------
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'secret_data'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install secret_data
|
23
|
+
|
24
|
+
|
25
|
+
Usage
|
26
|
+
-----
|
27
|
+
|
28
|
+
Example usage with VCR gem to silence api credentials.
|
29
|
+
|
30
|
+
require 'secret_data'
|
31
|
+
require 'vcr'
|
32
|
+
|
33
|
+
secret_data = SecretData.new(:yml_path => 'your_config.yml')
|
34
|
+
VCR.configure do |c|
|
35
|
+
secret_data.silence! do |find, replace|
|
36
|
+
c.filter_sensitive_data(replace) { find }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Configuration via block is also allowed.
|
41
|
+
|
42
|
+
SecretData.new.configure {|config|
|
43
|
+
config.message = '~*~GOODBYE_{{var}}~*~' # optional
|
44
|
+
config.add_from_env('API_SECRET') # reads ENV['API_SECRET']
|
45
|
+
}.silence!{|secret, message|
|
46
|
+
puts "Have some ultra-confidential data: #{secret}!"
|
47
|
+
puts "...whoops, I should have shown you #{message}."
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
Contributing
|
52
|
+
------------
|
53
|
+
|
54
|
+
1. Fork it
|
55
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
56
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
57
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
58
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/config.yml
ADDED
data/lib/secret_data.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
class SecretData
|
5
|
+
attr_accessor :message
|
6
|
+
|
7
|
+
def initialize(opts={})
|
8
|
+
@message = '____SILENCED_{{var}}____'
|
9
|
+
@secrets = {}
|
10
|
+
|
11
|
+
load_yaml!(opts[:yml_path]) if opts[:yml_path]
|
12
|
+
end
|
13
|
+
|
14
|
+
def configure(&block)
|
15
|
+
block.call(self)
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Iterates through each secret and display message pair.
|
21
|
+
#
|
22
|
+
def silence(&block)
|
23
|
+
@secrets.each_pair do |secret, message|
|
24
|
+
block.call secret, message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Loads a secret from ENV using the environment variable name
|
30
|
+
# to generate an appropriate display message.
|
31
|
+
def add_from_env(var_name)
|
32
|
+
recursive_load(var_name => ENV[var_name])
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Loads secrets from a hash of variable name keys and
|
37
|
+
# corresponding secrets.
|
38
|
+
def add(hash)
|
39
|
+
recursive_load(nested_hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
# Loads secrets from a YAML file of nested hashes, eg.
|
44
|
+
#
|
45
|
+
# ---
|
46
|
+
# variable_name: secret_value
|
47
|
+
# nested_hash:
|
48
|
+
# another_variable: another_secret
|
49
|
+
def load_yaml!(yml_path)
|
50
|
+
nested_hash = YAML.load(ERB.new(File.read(yml_path)).result)
|
51
|
+
recursive_load(nested_hash)
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def recursive_load(nested_hash, context='')
|
57
|
+
nested_hash.each_pair do |key, val|
|
58
|
+
case val
|
59
|
+
when String
|
60
|
+
@secrets[val] = message_for("#{context}#{key}")
|
61
|
+
when Hash
|
62
|
+
recursive_load(val, "#{context}#{key}_")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def message_for(key)
|
68
|
+
@message.gsub /\{\{var\}\}/, "#{key.to_s}"
|
69
|
+
end
|
70
|
+
end
|
data/secret_data.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/secret_data/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Alexander Wenzowski"]
|
6
|
+
gem.email = ["alexander@wenzowski.com"]
|
7
|
+
gem.description = %q{A helper class for silencing secret data.}
|
8
|
+
gem.summary = <<-EOF
|
9
|
+
SecretData loads sensitives strings from YAML, ENV, or Hash and
|
10
|
+
automatically generates a placeholder string that is safe to publsh
|
11
|
+
publicly, yet descriptive enough not to inhibit debugging.
|
12
|
+
EOF
|
13
|
+
gem.homepage = "https://github.com/wenzowski/secret_data"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($\)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.name = "secret_data"
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.version = SecretData::VERSION
|
21
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SecretData do
|
4
|
+
|
5
|
+
context '#initialize' do
|
6
|
+
context 'with YAML', :fakefs do
|
7
|
+
subject { SecretData.new :yml_path => 'config.yml' }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
File.open('config.yml', 'w') do |f|
|
11
|
+
f.write({
|
12
|
+
'description' => 'secret',
|
13
|
+
'nested' => {
|
14
|
+
'another' => 'secret2'
|
15
|
+
}
|
16
|
+
}.to_yaml)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it do
|
21
|
+
subject.instance_variable_get('@secrets').should == {
|
22
|
+
'secret' => "____SILENCED_description____",
|
23
|
+
'secret2' => "____SILENCED_nested_another____"
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context '#silence' do
|
30
|
+
subject {
|
31
|
+
ENV['VAR'] = 'secret data'
|
32
|
+
SecretData.new.configure{|c| c.add_from_env('VAR') }
|
33
|
+
}
|
34
|
+
|
35
|
+
it do
|
36
|
+
subject.silence {|secret, message|
|
37
|
+
secret.should == 'secret data'
|
38
|
+
message.should == '____SILENCED_VAR____'
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#message_for' do
|
44
|
+
subject { SecretData.new }
|
45
|
+
|
46
|
+
context 'default message' do
|
47
|
+
it do
|
48
|
+
subject.send(
|
49
|
+
:message_for, 'FOO'
|
50
|
+
).should == '____SILENCED_FOO____'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'custom message' do
|
55
|
+
it do
|
56
|
+
subject.configure do |config|
|
57
|
+
config.message = '{{var}}'
|
58
|
+
end
|
59
|
+
subject.send(:message_for, 'FOO').should == 'FOO'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'simplecov'
|
10
|
+
SimpleCov.start
|
11
|
+
rescue LoadError
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'secret_data'
|
15
|
+
require 'fakefs/safe'
|
16
|
+
require 'fakefs/spec_helpers'
|
17
|
+
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
config.filter_run :focus
|
22
|
+
|
23
|
+
# Run specs in random order to surface order dependencies. If you find an
|
24
|
+
# order dependency and want to debug it, you can fix the order by providing
|
25
|
+
# the seed, which is printed after each run.
|
26
|
+
# --seed 1234
|
27
|
+
config.order = 'random'
|
28
|
+
|
29
|
+
config.include FakeFS::SpecHelpers, :fakefs => true
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: secret_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Wenzowski
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-02 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: A helper class for silencing secret data.
|
15
|
+
email:
|
16
|
+
- alexander@wenzowski.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- .travis.yml
|
24
|
+
- Gemfile
|
25
|
+
- Guardfile
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- config.yml
|
30
|
+
- lib/secret_data.rb
|
31
|
+
- lib/secret_data/silencer.rb
|
32
|
+
- lib/secret_data/version.rb
|
33
|
+
- secret_data.gemspec
|
34
|
+
- spec/lib/secret_data/silencer_spec.rb
|
35
|
+
- spec/lib/secret_data/version_spec.rb
|
36
|
+
- spec/lib/secret_data_spec.rb
|
37
|
+
- spec/spec_helper.rb
|
38
|
+
homepage: https://github.com/wenzowski/secret_data
|
39
|
+
licenses: []
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
hash: -2849534964713371609
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
hash: -2849534964713371609
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.24
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: SecretData loads sensitives strings from YAML, ENV, or Hash and automatically
|
68
|
+
generates a placeholder string that is safe to publsh publicly, yet descriptive
|
69
|
+
enough not to inhibit debugging.
|
70
|
+
test_files:
|
71
|
+
- spec/lib/secret_data/silencer_spec.rb
|
72
|
+
- spec/lib/secret_data/version_spec.rb
|
73
|
+
- spec/lib/secret_data_spec.rb
|
74
|
+
- spec/spec_helper.rb
|
75
|
+
has_rdoc:
|