conf_conf 1.0.2 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README.md +227 -39
- data/bin/conf_conf +136 -0
- data/conf_conf.gemspec +18 -10
- data/lib/conf_conf.rb +51 -42
- data/lib/conf_conf/cli.rb +9 -0
- data/lib/conf_conf/cli/developers.rb +48 -0
- data/lib/conf_conf/cli/environments.rb +61 -0
- data/lib/conf_conf/cli/root.rb +72 -0
- data/lib/conf_conf/cli/variables.rb +85 -0
- data/lib/conf_conf/configuration.rb +57 -0
- data/lib/conf_conf/project.rb +20 -0
- data/lib/conf_conf/project/developer.rb +38 -0
- data/lib/conf_conf/project/developers.rb +48 -0
- data/lib/conf_conf/project/environment.rb +53 -0
- data/lib/conf_conf/project/environment/storage.rb +58 -0
- data/lib/conf_conf/project/environments.rb +24 -0
- data/lib/conf_conf/remote.rb +40 -0
- data/lib/conf_conf/user.rb +38 -0
- data/spec/project/developers_spec.rb +25 -0
- data/spec/project/environment/storage_spec.rb +91 -0
- data/spec/project/environment_spec.rb +21 -0
- data/spec/spec_helper.rb +163 -0
- metadata +126 -9
- data/spec/conf_conf_spec.rb +0 -68
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ConfConf::Project::Environment do
|
4
|
+
subject { described_class.new(project, environment_name) }
|
5
|
+
let(:project) { ConfConf::Project.new }
|
6
|
+
let(:environment_name) { 'test' }
|
7
|
+
|
8
|
+
it 'sets encrypted environment variable' do
|
9
|
+
subject.set('VARIABLE_NAME', 'abcd')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'gets and decrypts environment variable' do
|
13
|
+
subject.set('VARIABLE_NAME', 'abcd')
|
14
|
+
subject.get('VARIABLE_NAME')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'removes environment variable' do
|
18
|
+
subject.set('VARIABLE_NAME', 'abcd')
|
19
|
+
subject.remove('VARIABLE_NAME')
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'conf_conf'
|
2
|
+
|
1
3
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
4
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
5
|
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
@@ -76,3 +78,164 @@ RSpec.configure do |config|
|
|
76
78
|
end
|
77
79
|
=end
|
78
80
|
end
|
81
|
+
|
82
|
+
class MockStore < Struct.new(:path)
|
83
|
+
def write(data)
|
84
|
+
@data = data
|
85
|
+
end
|
86
|
+
|
87
|
+
def read
|
88
|
+
@data
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class MockFile
|
93
|
+
@@fs = {}
|
94
|
+
|
95
|
+
def self.write(path, content)
|
96
|
+
@@fs[path] = content
|
97
|
+
end
|
98
|
+
|
99
|
+
def self.read(path)
|
100
|
+
if @@fs[path]
|
101
|
+
@@fs[path]
|
102
|
+
else
|
103
|
+
raise Errno::ENOENT.new("No such file or directory - #{path}")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.fs
|
108
|
+
@@fs
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.exists?(path)
|
112
|
+
!@@fs[path].nil?
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.expand_path(path, *args)
|
116
|
+
path
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.join(*parts)
|
120
|
+
parts.join('/')
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.file?(path)
|
124
|
+
false
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.directory?(path)
|
128
|
+
false
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.dirname(path)
|
132
|
+
parts = path.split('/')
|
133
|
+
parts.pop
|
134
|
+
parts.join('/')
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
module MockRbNaCl
|
139
|
+
def self.instance_index
|
140
|
+
@instance_index ||= 0
|
141
|
+
@instance_index += 1
|
142
|
+
end
|
143
|
+
|
144
|
+
class Info
|
145
|
+
def initialize(content)
|
146
|
+
@content = MultiJson.load(content)
|
147
|
+
end
|
148
|
+
|
149
|
+
def encrypted?
|
150
|
+
secret_key_encrypted? || public_key_encrypted?
|
151
|
+
end
|
152
|
+
|
153
|
+
def secret_key_encrypted?
|
154
|
+
!secret_key.nil? && !content.nil?
|
155
|
+
end
|
156
|
+
|
157
|
+
def public_key_encrypted?
|
158
|
+
!content.nil? && !public_key.nil? && !private_key.nil?
|
159
|
+
end
|
160
|
+
|
161
|
+
def content
|
162
|
+
@content['content']
|
163
|
+
end
|
164
|
+
|
165
|
+
def public_key
|
166
|
+
@content['public_key']
|
167
|
+
end
|
168
|
+
|
169
|
+
def private_key
|
170
|
+
@content['private_key']
|
171
|
+
end
|
172
|
+
|
173
|
+
def secret_key
|
174
|
+
@content['secret_key']
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
def encrypted_content_details(content)
|
179
|
+
MultiJson.load(content)
|
180
|
+
end
|
181
|
+
|
182
|
+
class Random
|
183
|
+
def self.random_bytes(length)
|
184
|
+
"rand-#{length}"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
class SecretBox
|
189
|
+
def self.key_bytes
|
190
|
+
32
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
class Key
|
195
|
+
def to_s
|
196
|
+
@key_to_s ||= [self.class.name.to_s,
|
197
|
+
MockRbNaCl.instance_index.to_s].join('-')
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
class PrivateKey < Key
|
202
|
+
def self.generate
|
203
|
+
PrivateKey.new
|
204
|
+
end
|
205
|
+
|
206
|
+
def public_key
|
207
|
+
@public_key ||= Key.new
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
class SimpleBox
|
212
|
+
attr_accessor :public_key, :private_key, :secret_key
|
213
|
+
|
214
|
+
def self.from_keypair(public_key, private_key)
|
215
|
+
box = SimpleBox.new
|
216
|
+
box.public_key = public_key
|
217
|
+
box.private_key = private_key
|
218
|
+
box
|
219
|
+
end
|
220
|
+
|
221
|
+
def self.from_secret_key(secret_key)
|
222
|
+
box = SimpleBox.new
|
223
|
+
box.secret_key = secret_key
|
224
|
+
box
|
225
|
+
end
|
226
|
+
|
227
|
+
def encrypt(content)
|
228
|
+
MultiJson.dump({
|
229
|
+
public_key: self.public_key,
|
230
|
+
private_key: self.private_key,
|
231
|
+
secret_key: self.secret_key,
|
232
|
+
content: content
|
233
|
+
}.delete_if { |k,v| v.nil? })
|
234
|
+
end
|
235
|
+
|
236
|
+
def decrypt(content)
|
237
|
+
decoded = MultiJson.load(content)
|
238
|
+
decoded['content']
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
metadata
CHANGED
@@ -1,42 +1,159 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: conf_conf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Kassemi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httpi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.19.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.19.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.7.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.7.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: highline
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.6.21
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.21
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rbnacl-libsodium
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.5.0.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.5.0.1
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: multi_json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.10.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.10.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: dotenv
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.11.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.11.1
|
13
111
|
- !ruby/object:Gem::Dependency
|
14
112
|
name: rspec
|
15
113
|
requirement: !ruby/object:Gem::Requirement
|
16
114
|
requirements:
|
17
|
-
- -
|
115
|
+
- - ~>
|
18
116
|
- !ruby/object:Gem::Version
|
19
117
|
version: '3.0'
|
20
118
|
type: :development
|
21
119
|
prerelease: false
|
22
120
|
version_requirements: !ruby/object:Gem::Requirement
|
23
121
|
requirements:
|
24
|
-
- -
|
122
|
+
- - ~>
|
25
123
|
- !ruby/object:Gem::Version
|
26
124
|
version: '3.0'
|
27
125
|
description: Verify correctness of environment variables
|
28
126
|
email:
|
29
127
|
- jkassemi@gmail.com
|
30
|
-
executables:
|
128
|
+
executables:
|
129
|
+
- conf_conf
|
31
130
|
extensions: []
|
32
131
|
extra_rdoc_files: []
|
33
132
|
files:
|
133
|
+
- .gitignore
|
34
134
|
- Gemfile
|
35
135
|
- LICENSE
|
36
136
|
- README.md
|
137
|
+
- bin/conf_conf
|
37
138
|
- conf_conf.gemspec
|
38
139
|
- lib/conf_conf.rb
|
39
|
-
-
|
140
|
+
- lib/conf_conf/cli.rb
|
141
|
+
- lib/conf_conf/cli/developers.rb
|
142
|
+
- lib/conf_conf/cli/environments.rb
|
143
|
+
- lib/conf_conf/cli/root.rb
|
144
|
+
- lib/conf_conf/cli/variables.rb
|
145
|
+
- lib/conf_conf/configuration.rb
|
146
|
+
- lib/conf_conf/project.rb
|
147
|
+
- lib/conf_conf/project/developer.rb
|
148
|
+
- lib/conf_conf/project/developers.rb
|
149
|
+
- lib/conf_conf/project/environment.rb
|
150
|
+
- lib/conf_conf/project/environment/storage.rb
|
151
|
+
- lib/conf_conf/project/environments.rb
|
152
|
+
- lib/conf_conf/remote.rb
|
153
|
+
- lib/conf_conf/user.rb
|
154
|
+
- spec/project/developers_spec.rb
|
155
|
+
- spec/project/environment/storage_spec.rb
|
156
|
+
- spec/project/environment_spec.rb
|
40
157
|
- spec/spec_helper.rb
|
41
158
|
homepage: https://github.com/jkassemi/conf_conf
|
42
159
|
licenses:
|
@@ -48,17 +165,17 @@ require_paths:
|
|
48
165
|
- lib
|
49
166
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
167
|
requirements:
|
51
|
-
- -
|
168
|
+
- - '>='
|
52
169
|
- !ruby/object:Gem::Version
|
53
170
|
version: '0'
|
54
171
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
172
|
requirements:
|
56
|
-
- -
|
173
|
+
- - '>='
|
57
174
|
- !ruby/object:Gem::Version
|
58
175
|
version: '0'
|
59
176
|
requirements: []
|
60
177
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.
|
178
|
+
rubygems_version: 2.0.14
|
62
179
|
signing_key:
|
63
180
|
specification_version: 4
|
64
181
|
summary: A simple pattern and utility for verifying the correctness of the environment
|
data/spec/conf_conf_spec.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'conf_conf'
|
2
|
-
|
3
|
-
module Rails; end;
|
4
|
-
|
5
|
-
describe ConfConf do
|
6
|
-
context "#configuration" do
|
7
|
-
it "sets a value from the environment" do
|
8
|
-
ENV["TEST_KEY"] = "hey"
|
9
|
-
|
10
|
-
configuration = ConfConf.configuration {
|
11
|
-
config :test_key
|
12
|
-
}
|
13
|
-
|
14
|
-
expect(configuration.test_key).to eq("hey")
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
context "#rails_configuration" do
|
19
|
-
let(:configuration){ double() }
|
20
|
-
before { allow(Rails).to receive(:configuration).and_return(configuration) }
|
21
|
-
|
22
|
-
it "sets a value from the environment" do
|
23
|
-
ENV["TEST_KEY"] = "hey"
|
24
|
-
expect(configuration).to receive(:test_key=).with("hey")
|
25
|
-
|
26
|
-
ConfConf.rails_configuration do
|
27
|
-
config :test_key
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it "sets the default value when key not present" do
|
32
|
-
expect(configuration).to receive(:key_not_present=).with("hey")
|
33
|
-
|
34
|
-
ConfConf.rails_configuration do
|
35
|
-
config :key_not_present, default: "hey"
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
it "sets value from specified environment key" do
|
40
|
-
ENV["TEST_KEY"] = "hey"
|
41
|
-
expect(configuration).to receive(:other_key=).with("hey")
|
42
|
-
|
43
|
-
ConfConf.rails_configuration do
|
44
|
-
config :other_key, from: "TEST_KEY"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
it "throws an exception when required key not present" do
|
49
|
-
expect {
|
50
|
-
ConfConf.rails_configuration do
|
51
|
-
config :key_not_present
|
52
|
-
end
|
53
|
-
}.to raise_error(ConfConf::MissingConfigurationValueError)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "evaluates a block to establish the actual configuration value" do
|
57
|
-
ENV["INTEGER_VALUE"] = "2"
|
58
|
-
|
59
|
-
expect(configuration).to receive(:integer_value=).with(2)
|
60
|
-
|
61
|
-
ConfConf.rails_configuration do
|
62
|
-
config :integer_value do |value|
|
63
|
-
value.to_i
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|