pisec 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 +18 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +2 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/bin/pisec +25 -0
- data/lib/pisec.rb +5 -0
- data/lib/pisec/settings.rb +89 -0
- data/lib/pisec/version.rb +3 -0
- data/pisec.gemspec +24 -0
- data/spec/lib/pisec/settings_spec.rb +100 -0
- data/spec/spec_helper.rb +3 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7866f0bdc963ff9e013c1f3c014e6a5db670974b
|
4
|
+
data.tar.gz: eda9e1cb227c8b3a936924f1330f35b74b530b39
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ef8c52c8c9d5e6cf5632ae039435280f6b8289c15db1194926170fc6af0b6e40fdb695e4be96a9800fc5f079504f7fd6e517fd49b5933ee3c1ef03b8c1fdfade
|
7
|
+
data.tar.gz: 2c1b21ce79d05c617dafd8d48ad5f665ec3b4aa9e4b634679d8630110a7c0583e79aa9b7164ea461f114ea1341fcd533e107ffc5e1b41ba06ec6464692c16f06
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-2.0.0-p195@pisec --create
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# PISEC
|
2
|
+
|
3
|
+
Write your secure settings in environment variable that are formatted in a Platform Independent format (JSON) that can be used to configure your software
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'pisec'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install pisec
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
configure it:
|
22
|
+
vi config/secure_settings.sh:
|
23
|
+
# The format for this file is essentially:
|
24
|
+
# export <NAMESPACE>_<UPPERCASE_KEY_NAME>={<lowercase_key_name> => <val>}.to_json
|
25
|
+
# e.g.
|
26
|
+
# export PISEC_DEV_DB_USER="{\"dev_db_user\":\"pisec\"}"
|
27
|
+
|
28
|
+
initialize it:
|
29
|
+
vi config/initializers/pisec.rb:
|
30
|
+
Settings = Pisec::Support.load_file(
|
31
|
+
"#{RAILS_ROOT}/config/secure_settings.sh", # data-file
|
32
|
+
"PISEC" # namespace
|
33
|
+
)
|
34
|
+
|
35
|
+
use it:
|
36
|
+
Settings.get("dev_db_user")
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/pisec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'net/ssh/gateway'
|
4
|
+
require 'json'
|
5
|
+
require 'mysql2'
|
6
|
+
require_relative '../lib/stat_fetcher/client'
|
7
|
+
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
opt_parser = OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: #{$0} [OPTIONS]..."
|
13
|
+
|
14
|
+
#opts.on( "-a", "--all", "show all params") do |a|
|
15
|
+
# options[:mode] = :all
|
16
|
+
#end
|
17
|
+
|
18
|
+
opts.on_tail( '-h', '--help', 'This help screen' ) do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end
|
23
|
+
opt_parser.parse!
|
24
|
+
|
25
|
+
puts StatFetcher::Client.fetch
|
data/lib/pisec.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'json'
|
2
|
+
module Pisec
|
3
|
+
class Settings
|
4
|
+
|
5
|
+
def self.load_file yaml, into
|
6
|
+
_data = _parse_file( yaml )
|
7
|
+
load( _data, into )
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.load _data, into=nil
|
11
|
+
opts = {}
|
12
|
+
opts[:namespace] = into if into
|
13
|
+
new( _data, opts )
|
14
|
+
end
|
15
|
+
|
16
|
+
class << self
|
17
|
+
#def source_file yaml, into
|
18
|
+
# _data = _parse_source( yaml, into )
|
19
|
+
# load( _data, into )
|
20
|
+
#end
|
21
|
+
|
22
|
+
#def _parse_source( yaml, namespace )
|
23
|
+
# `source #{yaml}`
|
24
|
+
# ENV.select{|k,v| k.upcase =~ /^#{into.upcase}\_/}
|
25
|
+
#end
|
26
|
+
#private :_parse_source
|
27
|
+
|
28
|
+
def _open_file( file_name )
|
29
|
+
File.open( file_name, "r" )
|
30
|
+
end
|
31
|
+
private :_open_file
|
32
|
+
|
33
|
+
def _parse_file( yaml )
|
34
|
+
data_hash = {}
|
35
|
+
yaml_io = _open_file( yaml )
|
36
|
+
while !yaml_io.eof?
|
37
|
+
l = yaml_io.readline
|
38
|
+
next if l.match(/^\s*#/)
|
39
|
+
m = l.chomp.match(/^\s*export\s+(.+)$/)
|
40
|
+
next unless m && m[1]
|
41
|
+
kv = m[1].split(/=/)
|
42
|
+
#puts "got kv: #{kv.inspect}"
|
43
|
+
hash_key = kv.first
|
44
|
+
hash_value = JSON.parse(eval(kv.last))
|
45
|
+
data_hash[hash_key] = hash_value
|
46
|
+
end
|
47
|
+
return data_hash
|
48
|
+
ensure
|
49
|
+
yaml_io.close if yaml_io.respond_to?(:close)
|
50
|
+
end
|
51
|
+
private :_parse_file
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_reader :namespace, :data
|
55
|
+
def initialize( _data = {}, args = {} )
|
56
|
+
@namespace = args[:namespace].to_s || ''
|
57
|
+
load( _data )
|
58
|
+
end
|
59
|
+
|
60
|
+
def ==(other)
|
61
|
+
( other.namespace == self.namespace ) &&
|
62
|
+
( other.data == self.data )
|
63
|
+
end
|
64
|
+
|
65
|
+
def load _data
|
66
|
+
if _data.respond_to?(:[])
|
67
|
+
@data = _data
|
68
|
+
else
|
69
|
+
fail(RuntimeError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def get key='', _namespace = namespace
|
74
|
+
result = nil
|
75
|
+
if data && hash = data[_env_key_for(key, _namespace)]
|
76
|
+
if hash.respond_to?(:[])
|
77
|
+
result = hash[ key ]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
result || fail(RuntimeError)
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def _env_key_for key='', _namespace = namespace
|
86
|
+
"#{_namespace}_#{key}".upcase
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/pisec.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'pisec/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "pisec"
|
8
|
+
gem.version = Pisec::VERSION
|
9
|
+
gem.authors = ["jayteesf"]
|
10
|
+
gem.email = ["buyer+jayteesf AT his-service DOT net"]
|
11
|
+
gem.description = %q{all rights reserved; for internal use only}
|
12
|
+
gem.summary = %q{Platform Independent (json based) Secure Env-var Configs}
|
13
|
+
gem.homepage = ""
|
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.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
gem.add_dependency 'json'
|
22
|
+
|
23
|
+
gem.add_development_dependency "rspec", ">= 2.13.0"
|
24
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
# given
|
5
|
+
describe Pisec::Settings do
|
6
|
+
let(:namespace) { "Pisec" }
|
7
|
+
#let(:config_file_dir) { "#{Rails.root}/spec/support/config" }
|
8
|
+
#let(:config_file_name) { "settings.sh" }
|
9
|
+
|
10
|
+
def key(name, space=nil)
|
11
|
+
space ? "#{space}_#{name}" : name.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:renamed_data) {
|
15
|
+
{
|
16
|
+
key("foo", "otherspace").upcase => {key("foo") => "foo value"},
|
17
|
+
key("bar", "otherspace").upcase => {key("bar") => "bar value"},
|
18
|
+
key("baz", "otherspace").upcase => {key("baz") => "baz value"}
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
let(:default_data) {
|
23
|
+
{
|
24
|
+
key("foo", namespace).upcase => {key("foo") => "foo value"},
|
25
|
+
key("bar", namespace).upcase => {key("bar") => "bar value"},
|
26
|
+
key("baz", namespace).upcase => {key("baz") => "baz value"}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
|
30
|
+
let(:default_args) { default_data }
|
31
|
+
let(:settings) { Pisec::Settings.new(default_args) }
|
32
|
+
|
33
|
+
context "compare settings" do
|
34
|
+
it "recognizes setting objects with same namespaces" do
|
35
|
+
expect( Pisec::Settings.load({}, :ns1) ).to eq(
|
36
|
+
Pisec::Settings.load({}, :ns1)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "distinguishes setting objects with different namespaces" do
|
41
|
+
expect( Pisec::Settings.load({}, :ns1) ).to_not eq(
|
42
|
+
Pisec::Settings.load({}, :ns2)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "create settings" do
|
48
|
+
it "loads an equivalent settings object" do
|
49
|
+
expect( Pisec::Settings.load(default_data) ).to eq(Pisec::Settings.new(default_args))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:blank_settings) { Pisec::Settings.new }
|
54
|
+
#when
|
55
|
+
context "invalid config" do
|
56
|
+
let(:invalid_config) { nil }
|
57
|
+
it "loads an equivalent settings object" do
|
58
|
+
blank_settings.load( default_data )
|
59
|
+
expect( blank_settings ).to eq(Pisec::Settings.new(default_args))
|
60
|
+
end
|
61
|
+
|
62
|
+
it "raises a RuntimeError when loading invalid config" do
|
63
|
+
expect { blank_settings.load( invalid_config ) }.to raise_error(RuntimeError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "valid config" do
|
68
|
+
context "that is escaped" do
|
69
|
+
let(:config_string) { %Q{export #{key('ADMIN_ROLE_NAME', namespace).upcase}=%Q/{\"#{key('admin_role_name')}\":\"admin\"}/} }
|
70
|
+
let(:yaml) { StringIO.new(config_string) }
|
71
|
+
let(:expected_data) {
|
72
|
+
{
|
73
|
+
key("ADMIN_ROLE_NAME", namespace).upcase => {key("admin_role_name") => "admin"},
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
it "loads correctly" do
|
78
|
+
expected = Pisec::Settings.new(expected_data, :namespace => namespace)
|
79
|
+
|
80
|
+
Pisec::Settings.should_receive(:_open_file).and_return( yaml )
|
81
|
+
got = Pisec::Settings.load_file( :yaml_file_name, namespace )
|
82
|
+
expect(got).to eq(expected)
|
83
|
+
end
|
84
|
+
|
85
|
+
context "getting values" do
|
86
|
+
it "retrieves the key's value" do
|
87
|
+
settings_object = Pisec::Settings.new(expected_data, :namespace => namespace)
|
88
|
+
expect(settings_object.get("admin_role_name")).to eq("admin")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "that is empty" do
|
94
|
+
it "raises a RuntimeError for an unknown key" do
|
95
|
+
expect { blank_settings.get( :unknown_key, :namespace => namespace ) }.to raise_error(RuntimeError)
|
96
|
+
expect { blank_settings.get( :unknown_key ) }.to raise_error(RuntimeError)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pisec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jayteesf
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
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: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.13.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.13.0
|
41
|
+
description: all rights reserved; for internal use only
|
42
|
+
email:
|
43
|
+
- buyer+jayteesf AT his-service DOT net
|
44
|
+
executables:
|
45
|
+
- pisec
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- .rspec
|
51
|
+
- .rvmrc
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/pisec
|
57
|
+
- lib/pisec.rb
|
58
|
+
- lib/pisec/settings.rb
|
59
|
+
- lib/pisec/version.rb
|
60
|
+
- pisec.gemspec
|
61
|
+
- spec/lib/pisec/settings_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
homepage: ''
|
64
|
+
licenses: []
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.0.3
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Platform Independent (json based) Secure Env-var Configs
|
86
|
+
test_files:
|
87
|
+
- spec/lib/pisec/settings_spec.rb
|
88
|
+
- spec/spec_helper.rb
|