bcdatabase 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ 1.0.1
2
+ =====
3
+ - Update some old syntax for ruby 1.9 compatibility (David Yip)
4
+
1
5
  1.0.0
2
6
  =====
3
7
  - Split out from NUBIC internal `bcdatabase` project.
data/README.markdown CHANGED
@@ -14,19 +14,19 @@ Ensure that [gemcutter](http://gemcutter.org) is in your gem sources list, then:
14
14
  A bog-standard rails application's `config/database.yml` file looks like this:
15
15
 
16
16
  development:
17
- adapter: oracle-enhanced
17
+ adapter: oracle_enhanced
18
18
  database: //localhost/XE
19
19
  username: cfg_animal
20
20
  password: not-important
21
21
 
22
22
  test:
23
- adapter: oracle-enhanced
23
+ adapter: oracle_enhanced
24
24
  database: //localhost/XE
25
25
  username: cfg_animal_test
26
26
  password: who-cares
27
27
 
28
28
  production:
29
- adapter: oracle-enhanced
29
+ adapter: oracle_enhanced
30
30
  database: //super/prod
31
31
  username: cfg_animal
32
32
  password: very-secret
@@ -39,13 +39,13 @@ Rails allows this file to contain [ERB][]. `bcdatabase` uses ERB to replace an
39
39
  %>
40
40
 
41
41
  development:
42
- adapter: oracle-enhanced
42
+ adapter: oracle_enhanced
43
43
  database: //localhost/XE
44
44
  username: cfg_animal
45
45
  password: not-important
46
46
 
47
47
  test:
48
- adapter: oracle-enhanced
48
+ adapter: oracle_enhanced
49
49
  database: //localhost/XE
50
50
  username: cfg_animal_test
51
51
  password: who-cares
@@ -83,7 +83,7 @@ Since each file can define a set of default properties which are shared by all t
83
83
  If you have an `/etc/nubic/db/stage.yml` file that looks like this:
84
84
 
85
85
  defaults:
86
- adapter: oracle-enhanced
86
+ adapter: oracle_enhanced
87
87
  database: //mondo/stage
88
88
  cfg_animal:
89
89
  password: secret
@@ -93,14 +93,14 @@ If you have an `/etc/nubic/db/stage.yml` file that looks like this:
93
93
 
94
94
  You have defined two configuration entries. `:stage, :cfg_animal`:
95
95
 
96
- adapter: oracle-enhanced
96
+ adapter: oracle_enhanced
97
97
  username: cfg_animal
98
98
  password: secret
99
99
  database: //mondo/stage
100
100
 
101
101
  and `:bcstage, :personnel`:
102
102
 
103
- adapter: oracle-enhanced
103
+ adapter: oracle_enhanced
104
104
  username: pers
105
105
  password: more-secret
106
106
  database: //mondo/stage
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
- ---
1
+ ---
2
2
  :major: 1
3
3
  :minor: 0
4
- :build:
5
- :patch: 0
4
+ :build:
5
+ :patch: 1
data/lib/bcdatabase.rb CHANGED
@@ -79,14 +79,14 @@ module Bcdatabase
79
79
  dbname = (args[1] or raise "Database entry name not specified for #{name}")
80
80
  n = name.to_s
81
81
  begin
82
- unseparated_yaml({ n, self[groupname, dbname] })
82
+ unseparated_yaml(n => self[groupname, dbname])
83
83
  rescue Bcdatabase::Error => e
84
84
  if defined?(RAILS_ENV) and RAILS_ENV == n
85
85
  raise e
86
86
  else
87
87
  # Not using that configuration right now, so return a dummy instead
88
88
  # of throwing an exception
89
- unseparated_yaml({ n, { 'error' => e.message } })
89
+ unseparated_yaml(n => { 'error' => e.message })
90
90
  end
91
91
  end
92
92
  end
@@ -1,38 +1,10 @@
1
1
  require File.expand_path("spec_helper", File.dirname(__FILE__))
2
2
 
3
- describe Bcdatabase, "cipherment" do
4
- before(:all) do
5
- keyfile = "/tmp/bcdb-spec-key"
6
- open(keyfile, 'w') { |f| f.write "01234567890123456789012345678901" }
7
- ENV["BCDATABASE_PASS"] = keyfile
8
- end
9
-
10
- after(:all) do
11
- FileUtils.rm ENV["BCDATABASE_PASS"]
12
- ENV["BCDATABASE_PASS"] = nil
13
- end
14
-
15
- it "should be reversible" do
16
- e = Bcdatabase.encrypt("riboflavin")
17
- Bcdatabase.decrypt(e).should == "riboflavin"
18
- end
19
-
20
- it "should permute the input" do
21
- Bcdatabase.encrypt("zanzibar").should_not == "zanzibar"
22
- end
23
-
24
- it "should do more than just encode" do
25
- Bcdatabase.encrypt("zanzibar").should_not == Base64.encode64("zanzibar")
26
- end
27
- end
28
-
29
- describe Bcdatabase, "module " do
3
+ describe Bcdatabase do
30
4
  it "should have a d.d.d version" do
31
5
  Bcdatabase::VERSION.should =~ /^\d+\.\d+\.\d+$/
32
6
  end
33
- end
34
7
 
35
- describe Bcdatabase, "loading" do
36
8
  before(:each) do
37
9
  ENV["BCDATABASE_PATH"] = "/tmp/bcdb_specs"
38
10
  FileUtils.mkdir_p ENV["BCDATABASE_PATH"]
@@ -43,158 +15,250 @@ describe Bcdatabase, "loading" do
43
15
  ENV["BCDATABASE_PATH"] = nil
44
16
  end
45
17
 
46
- it "should read simple YAML" do
47
- temporary_yaml "simple", {
48
- "single" => {
49
- "adapter" => "foo", "username" => "baz"
50
- }
51
- }
52
- bcdb = Bcdatabase.load
53
- bcdb[:simple, :single]['adapter'].should == "foo"
54
- bcdb[:simple, :single]['username'].should == "baz"
55
- end
18
+ describe "cipherment" do
19
+ before(:all) do
20
+ keyfile = "/tmp/bcdb-spec-key"
21
+ open(keyfile, 'w') { |f| f.write "01234567890123456789012345678901" }
22
+ ENV["BCDATABASE_PASS"] = keyfile
23
+ end
56
24
 
57
- it "should read and expose multiple groups from multiple files" do
58
- temporary_yaml "one", {
59
- "first" => { "dc" => "etc" }
60
- }
61
- temporary_yaml "two", {
62
- "fourth" => { "dc" => "etc" }
63
- }
64
- bcdb = Bcdatabase.load
65
- bcdb['one', 'first'].should_not be_nil
66
- bcdb['two', 'fourth'].should_not be_nil
67
- end
25
+ after(:all) do
26
+ FileUtils.rm ENV["BCDATABASE_PASS"]
27
+ ENV["BCDATABASE_PASS"] = nil
28
+ end
68
29
 
69
- it "should merge defaults from 'defaults'" do
70
- temporary_yaml "defaulted", {
71
- "defaults" => {
72
- "database" => "postgresql"
73
- },
74
- "real" => {
75
- "password" => "frood"
76
- }
77
- }
78
- bcdb = Bcdatabase.load
79
- bcdb['defaulted', 'real']['password'].should == 'frood'
80
- bcdb['defaulted', 'real']['database'].should == 'postgresql'
81
- end
30
+ it "should be reversible" do
31
+ e = Bcdatabase.encrypt("riboflavin")
32
+ Bcdatabase.decrypt(e).should == "riboflavin"
33
+ end
82
34
 
83
- it "should merge defaults from 'default'" do
84
- temporary_yaml "singular", {
85
- "default" => {
86
- "adapter" => "three-eighths"
87
- },
88
- "real" => {
89
- "password" => "frood"
90
- }
91
- }
92
- bcdb = Bcdatabase.load
93
- bcdb['singular', 'real']['adapter'].should == 'three-eighths'
35
+ it "should permute the input" do
36
+ Bcdatabase.encrypt("zanzibar").should_not == "zanzibar"
37
+ end
38
+
39
+ it "should do more than just encode" do
40
+ Bcdatabase.encrypt("zanzibar").should_not == Base64.encode64("zanzibar")
41
+ end
94
42
  end
95
43
 
96
- it "should preserve values overridden from defaults" do
97
- temporary_yaml "jam", {
98
- "default" => {
99
- "adapter" => "three-eighths"
100
- },
101
- "standard" => {
102
- "password" => "frood"
103
- },
104
- "custom" => {
105
- "adapter" => "five-sixteenths",
106
- "password" => "lazlo"
44
+ describe "loading" do
45
+ it "should read simple YAML" do
46
+ temporary_yaml "simple", {
47
+ "single" => {
48
+ "adapter" => "foo", "username" => "baz"
49
+ }
107
50
  }
108
- }
109
- bcdb = Bcdatabase.load
110
- bcdb['jam', 'standard']['adapter'].should == 'three-eighths'
111
- bcdb['jam', 'custom']['adapter'].should == 'five-sixteenths'
112
- end
51
+ bcdb = Bcdatabase.load
52
+ bcdb[:simple, :single]['adapter'].should == "foo"
53
+ bcdb[:simple, :single]['username'].should == "baz"
54
+ end
113
55
 
114
- it "should default the username to the entry name" do
115
- temporary_yaml "scran", {
116
- "jim" => { "password" => "leather" }
117
- }
118
- bcdb = Bcdatabase.load
119
- bcdb['scran', 'jim']['username'].should == 'jim'
120
- bcdb['scran', 'jim']['password'].should == 'leather'
121
- end
56
+ it "should read and expose multiple groups from multiple files" do
57
+ temporary_yaml "one", {
58
+ "first" => { "dc" => "etc" }
59
+ }
60
+ temporary_yaml "two", {
61
+ "fourth" => { "dc" => "etc" }
62
+ }
63
+ bcdb = Bcdatabase.load
64
+ bcdb['one', 'first'].should_not be_nil
65
+ bcdb['two', 'fourth'].should_not be_nil
66
+ end
122
67
 
123
- it "should default the database name to the entry name" do
124
- temporary_yaml "scran", {
125
- "jim" => { "password" => "leather" }
126
- }
127
- bcdb = Bcdatabase.load
128
- bcdb['scran', 'jim']['database'].should == 'jim'
129
- bcdb['scran', 'jim']['password'].should == 'leather'
130
- end
68
+ it "should merge defaults from 'defaults'" do
69
+ temporary_yaml "defaulted", {
70
+ "defaults" => {
71
+ "database" => "postgresql"
72
+ },
73
+ "real" => {
74
+ "password" => "frood"
75
+ }
76
+ }
77
+ bcdb = Bcdatabase.load
78
+ bcdb['defaulted', 'real']['password'].should == 'frood'
79
+ bcdb['defaulted', 'real']['database'].should == 'postgresql'
80
+ end
131
81
 
132
- it "should not default the database name if there's an explicit database name" do
133
- temporary_yaml "scran", {
134
- "jim" => {
135
- "password" => "leather",
136
- "database" => "james"
82
+ it "should merge defaults from 'default'" do
83
+ temporary_yaml "singular", {
84
+ "default" => {
85
+ "adapter" => "three-eighths"
86
+ },
87
+ "real" => {
88
+ "password" => "frood"
89
+ }
137
90
  }
138
- }
139
- bcdb = Bcdatabase.load
140
- bcdb['scran', 'jim']['database'].should == 'james'
141
- bcdb['scran', 'jim']['password'].should == 'leather'
142
- end
91
+ bcdb = Bcdatabase.load
92
+ bcdb['singular', 'real']['adapter'].should == 'three-eighths'
93
+ end
143
94
 
144
- it "should not default the database name to the entry name if there's a default database name" do
145
- temporary_yaml "scran", {
146
- "default" => {
147
- "database" => "//localhost:345/etc"
148
- },
149
- "jim" => {
150
- "password" => "leather",
95
+ it "should preserve values overridden from defaults" do
96
+ temporary_yaml "jam", {
97
+ "default" => {
98
+ "adapter" => "three-eighths"
99
+ },
100
+ "standard" => {
101
+ "password" => "frood"
102
+ },
103
+ "custom" => {
104
+ "adapter" => "five-sixteenths",
105
+ "password" => "lazlo"
106
+ }
151
107
  }
152
- }
153
- bcdb = Bcdatabase.load
154
- bcdb['scran', 'jim']['database'].should == '//localhost:345/etc'
155
- bcdb['scran', 'jim']['password'].should == 'leather'
156
- end
108
+ bcdb = Bcdatabase.load
109
+ bcdb['jam', 'standard']['adapter'].should == 'three-eighths'
110
+ bcdb['jam', 'custom']['adapter'].should == 'five-sixteenths'
111
+ end
157
112
 
158
- it "should use an explicit username instead of the entry name if provided" do
159
- temporary_yaml "scran", {
160
- "jim" => {
161
- "username" => "james",
162
- "password" => "earldom"
113
+ it "should default the username to the entry name" do
114
+ temporary_yaml "scran", {
115
+ "jim" => { "password" => "leather" }
163
116
  }
164
- }
165
- bcdb = Bcdatabase.load
166
- bcdb['scran', 'jim']['username'].should == 'james'
167
- bcdb['scran', 'jim']['password'].should == 'earldom'
168
- end
117
+ bcdb = Bcdatabase.load
118
+ bcdb['scran', 'jim']['username'].should == 'jim'
119
+ bcdb['scran', 'jim']['password'].should == 'leather'
120
+ end
169
121
 
170
- describe "with encrypted passwords" do
171
- before do
172
- enable_fake_cipherment
122
+ it "should default the database name to the entry name" do
123
+ temporary_yaml "scran", {
124
+ "jim" => { "password" => "leather" }
125
+ }
126
+ bcdb = Bcdatabase.load
127
+ bcdb['scran', 'jim']['database'].should == 'jim'
128
+ bcdb['scran', 'jim']['password'].should == 'leather'
173
129
  end
174
130
 
175
- after do
176
- disable_fake_cipherment
131
+ it "should not default the database name if there's an explicit database name" do
132
+ temporary_yaml "scran", {
133
+ "jim" => {
134
+ "password" => "leather",
135
+ "database" => "james"
136
+ }
137
+ }
138
+ bcdb = Bcdatabase.load
139
+ bcdb['scran', 'jim']['database'].should == 'james'
140
+ bcdb['scran', 'jim']['password'].should == 'leather'
177
141
  end
178
142
 
179
- it "should decrypt and expose the password" do
180
- temporary_yaml "secure", {
181
- "safe" => {
182
- "epassword" => "moof"
143
+ it "should not default the database name to the entry name if there's a default database name" do
144
+ temporary_yaml "scran", {
145
+ "default" => {
146
+ "database" => "//localhost:345/etc"
147
+ },
148
+ "jim" => {
149
+ "password" => "leather",
183
150
  }
184
151
  }
185
152
  bcdb = Bcdatabase.load
186
- bcdb['secure', 'safe']['password'].should == "foom"
153
+ bcdb['scran', 'jim']['database'].should == '//localhost:345/etc'
154
+ bcdb['scran', 'jim']['password'].should == 'leather'
187
155
  end
188
156
 
189
- it "should prefer the decrypted version of an epassword" do
190
- temporary_yaml "secure", {
191
- "safe" => {
192
- "password" => "fake",
193
- "epassword" => "moof"
157
+ it "should use an explicit username instead of the entry name if provided" do
158
+ temporary_yaml "scran", {
159
+ "jim" => {
160
+ "username" => "james",
161
+ "password" => "earldom"
194
162
  }
195
163
  }
196
164
  bcdb = Bcdatabase.load
197
- bcdb['secure', 'safe']['password'].should == "foom" # not "fake"
165
+ bcdb['scran', 'jim']['username'].should == 'james'
166
+ bcdb['scran', 'jim']['password'].should == 'earldom'
167
+ end
168
+
169
+ describe "with encrypted passwords" do
170
+ before do
171
+ enable_fake_cipherment
172
+ end
173
+
174
+ after do
175
+ disable_fake_cipherment
176
+ end
177
+
178
+ it "should decrypt and expose the password" do
179
+ temporary_yaml "secure", {
180
+ "safe" => {
181
+ "epassword" => "moof"
182
+ }
183
+ }
184
+ bcdb = Bcdatabase.load
185
+ bcdb['secure', 'safe']['password'].should == "foom"
186
+ end
187
+
188
+ it "should prefer the decrypted version of an epassword" do
189
+ temporary_yaml "secure", {
190
+ "safe" => {
191
+ "password" => "fake",
192
+ "epassword" => "moof"
193
+ }
194
+ }
195
+ bcdb = Bcdatabase.load
196
+ bcdb['secure', 'safe']['password'].should == "foom" # not "fake"
197
+ end
198
+ end
199
+ end
200
+
201
+ describe "for database.yml" do
202
+ before do
203
+ temporary_yaml "scran", {
204
+ "jim" => {
205
+ "username" => "james",
206
+ "password" => "earldom"
207
+ },
208
+
209
+ "dwide" => {
210
+ "username" => "dwight",
211
+ "password" => "help"
212
+ }
213
+ }
214
+ @bcdb = Bcdatabase.load
215
+ end
216
+
217
+ describe "the yaml for a valid reference" do
218
+ before do
219
+ @yaml = @bcdb.development(:scran, :jim)
220
+ @actual = YAML.load(@yaml)
221
+ end
222
+
223
+ it "isn't a separated YAML doc" do
224
+ @yaml.should_not =~ /---/
225
+ end
226
+
227
+ it "has a single top-level key" do
228
+ @actual.keys.should have(1).key
229
+ @actual.should have_key("development")
230
+ end
231
+
232
+ it "reflects the selected configuration" do
233
+ @actual['development']['username'].should == 'james'
234
+ @actual['development']['password'].should == 'earldom'
235
+ end
236
+ end
237
+
238
+ describe "an invalid reference" do
239
+ before do
240
+ ::RAILS_ENV = "staging"
241
+ end
242
+
243
+ after do
244
+ Object.class_eval { remove_const "RAILS_ENV" }
245
+ end
246
+
247
+ describe "for the current RAILS_ENV" do
248
+ it "allows the exception through" do
249
+ lambda { @bcdb.staging(:scran, :phil) }.should raise_error
250
+ end
251
+ end
252
+
253
+ describe "for a different RAILS_ENV" do
254
+ it "does not throw an exception" do
255
+ lambda { @bcdb.production(:scran, :phil) }.should_not raise_error
256
+ end
257
+
258
+ it "includes the error in the resulting hash" do
259
+ @bcdb.production(:scran, :phil).should =~ / error: No database entry for \"phil\" in scran/
260
+ end
261
+ end
198
262
  end
199
263
  end
200
264
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bcdatabase
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rhett Sutphin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-08 00:00:00 -06:00
12
+ date: 2009-12-20 00:00:00 -06:00
13
13
  default_executable: bcdatabase
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency