dbi-dbrc 1.3.0 → 1.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 67a3a14643684c577916f199d8e356d33392390a
4
- data.tar.gz: d846477c348cc70e508da67600a74d6f1e8f5808
2
+ SHA256:
3
+ metadata.gz: 813eb7a49bd78983624e1e91031b3f93d83a872a1edea9bc2a1bced57985af9a
4
+ data.tar.gz: f9a2a4b40d14ecdc5e36b02c8c8c14c5e5bf47cf34400f365b9e4b23b03a540c
5
5
  SHA512:
6
- metadata.gz: f56a3dbcdab4caaf4bdd33996d8939c3a607a01238fde3819b214f5836cdc018c6cc62a806ad63a3716c1af9cd33383e2e186e5b704cf93f10305ed2e5259e61
7
- data.tar.gz: fb15eb083cad740e86d68174db035b11b182bee5a5cdd6a75e77b016311460a43cddace9b5786885e058c4f916faaa966f6bbe7870982055aae3f2f998a9ab4b
6
+ metadata.gz: b46c7b59855bfa381213fa8ce30d31dbe4646811a6fd085ec698a1d6d3504eda6838a9693355ee958fd13e5aad679b6f2f5a060050cfaa64a45ec5214e84c4ab
7
+ data.tar.gz: 7f222c7eda45b449a59ecff9fb6c9631ac3dd54e59f3c12a858333ba478a1fa1f4e0269bd96a4453c320a56c47826e49da2994656caa1e61bebbde78e5d54a80
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,34 +1,68 @@
1
- == 1.3.0 - 3-Oct-2015
1
+ ## 1.7.0 - 19-Jun-2021
2
+ * Added a DBI::DBRC::JSON subclass, and corresponding specs, so you can now
3
+ store information in JSON format.
4
+ * Updated and/or removed old information from the README file.
5
+
6
+ ## 1.6.0 - 9-Jun-2021
7
+ * Now supports gpg encrypted files, with a 4th optional parameter where you
8
+ can pass gpg options (usually a password, but whatever gpgme supports).
9
+ * Added gpgme as a dependency.
10
+ * Updated specs for MS Windows.
11
+ * The "home" handling is now a bit simpler, as it was originally written
12
+ before that method existed in core Ruby.
13
+
14
+ ## 1.5.0 - 12-Apr-2021
15
+ * Switched from test-unit to rspec, with corresponding changes in the
16
+ gemspec and Rakefile.
17
+ * Switched doc files to markdown format.
18
+ * Added a Gemfile.
19
+
20
+ ## 1.4.1 - 14-Jan-2018
21
+ * Fixed some test warnings.
22
+ * Added metadata to gemspec.
23
+ * The VERSION constant is now frozen.
24
+ * Updated the cert, should be good for about 10 years.
25
+
26
+ ## 1.4.0 - 6-Dec-2015
27
+ * Use Dir.home to calculate the home directory on Unixy platforms. Therefore
28
+ Ruby 1.9.3 or later is now required.
29
+ * The DBI::DBRC::YML class looks for "maximum_reconnects" instead of
30
+ "max_reconn" to be consistent with the other classes.
31
+ * Aliases are now universal for all classes.
32
+ * Some gemspec and Rakefile updates.
33
+ * Added a dbi-dbrc.rb file for convenience.
34
+
35
+ ## 1.3.0 - 3-Oct-2015
2
36
  * License changed to Apache 2.0.
3
37
  * Rakefile gem related tasks now assume Rubygems 2.x.
4
38
  * Added a certs file. This gem is now signed.
5
39
 
6
- == 1.2.0 - 8-Nov-2014
40
+ ## 1.2.0 - 8-Nov-2014
7
41
  * Updated dependency for MS Windows. Now uses win32-file-attributes instead
8
42
  of win32-file.
9
43
  * Minor updates to the Rakefile and gemspec.
10
44
 
11
- == 1.1.9 - 10-Jan-2013
45
+ ## 1.1.9 - 10-Jan-2013
12
46
  * Fixed an unused variable warning.
13
47
  * Changed the way I check for MS Windows.
14
48
 
15
- == 1.1.8 - 7-Oct-2010
49
+ ## 1.1.8 - 7-Oct-2010
16
50
  * Fixed a logic bug in the constructor that primarily affected MS Windows with
17
51
  regards to determining the user's home directory.
18
52
 
19
- == 1.1.7 - 6-Oct-2010
53
+ ## 1.1.7 - 6-Oct-2010
20
54
  * More robust file decryption/encryption for MS Windows.
21
55
  * Better platform checking for MS Windows.
22
56
  * Refactored the Rakefile. Removed the old installation tasks and replaced
23
57
  them with a series of gem tasks.
24
58
  * Updated the win32 library dependencies.
25
59
 
26
- == 1.1.6 - 10-Sep-2009
60
+ ## 1.1.6 - 10-Sep-2009
27
61
  * Fixed validation for dbrc_dir argument.
28
62
  * Added a test for bogus dbrc_dir arguments.
29
63
 
30
- == 1.1.5 - 3-Sep-2009
31
- * License changed to Artistic 2.0.
64
+ ## 1.1.5 - 3-Sep-2009
65
+ * License changed to Artistic-2.0.
32
66
  * Some gemspec updates, including the license and description.
33
67
  * Renamed the test files. The ts_all.rb file was removed.
34
68
  * Added win32-process as a dependency on MS Windows.
@@ -38,24 +72,24 @@
38
72
  * Refactored the main test task.
39
73
  * Added explicit copyright and warranty to the README file.
40
74
 
41
- == 1.1.4 - 10-Nov-2008
75
+ ## 1.1.4 - 10-Nov-2008
42
76
  * Added a custom inspect method which filters the password.
43
77
 
44
- == 1.1.3 - 21-Jul-2008
78
+ ## 1.1.3 - 21-Jul-2008
45
79
  * More RUBY_PLATFORM changes that I missed in the last release.
46
80
  * Added inline RDOC for the accessors and updated the documentation
47
81
  for the constructor.
48
82
  * Added the DBI::DBRC#dbrc_dir and DBI::DBRC#dbrc_file methods.
49
83
  * More tests.
50
84
 
51
- == 1.1.2 - 18-Jul-2008
85
+ ## 1.1.2 - 18-Jul-2008
52
86
  * Changed platform checking from RUBY_PLATFORM to Config::CONFIG['host_os']
53
87
  so that other implementations won't choke.
54
88
  * Updated the gemspec to add the sys-admin dependency.
55
89
  * Added a rubyforge_project to the gemspec.
56
90
  * Now has a separate gem for MS Windows.
57
91
 
58
- == 1.1.1 - 2-Aug-2007
92
+ ## 1.1.1 - 2-Aug-2007
59
93
  * DBRCError is now DBRC::Error.
60
94
  * Added a Rakefile with tasks for installation and testing.
61
95
  * Added the win32-dir library as a prerequisite for MS Windows.
@@ -64,21 +98,21 @@
64
98
  warnings that appeared when run with -w.
65
99
  * Some doc and test updates.
66
100
 
67
- == 1.1.0 - 19-Oct-2005
101
+ ## 1.1.0 - 19-Oct-2005
68
102
  * Bug fix for MS Windows (there's no Win32 namespace for win32/file).
69
103
  * Changed platform detection mechanism.
70
104
 
71
- == 1.0.1 - 7-Oct-2005
105
+ ## 1.0.1 - 7-Oct-2005
72
106
  * Improved the error message when an entry isn't found.
73
107
 
74
- == 1.0.0 - 15-Jun-2005
108
+ ## 1.0.0 - 15-Jun-2005
75
109
  * Ditches the use of 'etc'. Now requires the 'sys-admin' package as its
76
110
  replacement (for all platforms).
77
111
  * Moved project to RubyForge.
78
112
  * Minor updates to tests, README and gemspec.
79
113
  * Now hosted on RubyForge.
80
114
 
81
- == 0.5.1 - 17-Mar-2005
115
+ ## 0.5.1 - 17-Mar-2005
82
116
  * Removed the 'doc' directory completely, and moved the primary
83
117
  documentation into the README file.
84
118
  * Removed the INSTALL file. Moved the installation directions into the
@@ -87,7 +121,7 @@
87
121
  * Made the README and CHANGES files rdoc friendly.
88
122
  * Added a gemspec.
89
123
 
90
- == 0.5.0 - 15-Oct-2004
124
+ ## 0.5.0 - 15-Oct-2004
91
125
  * Added a YAML subclass. Use this if you want to store your information in
92
126
  the .dbrc file in YAML format.
93
127
  * On Win32 systems, the .dbrc file must now be "hidden". Also, it will
@@ -104,19 +138,19 @@
104
138
  using rdtool.
105
139
  * Test suite changes.
106
140
 
107
- == 0.4.0 - 3-Sep-2004
141
+ ## 0.4.0 - 3-Sep-2004
108
142
  * Removed redundant error handling for cases when the database and/or login
109
143
  are not found.
110
144
  * Added an XML subclass. Use this if you want to store your information in
111
145
  the .dbrc file in XML format.
112
146
 
113
- == 0.3.0 - 26-Oct-2003
147
+ ## 0.3.0 - 26-Oct-2003
114
148
  * Win32 support added. Requires the win32-etc package.
115
149
  * rd doc separated from source. Moved to 'doc' directory.
116
150
  * Documentation updates and corrections.
117
151
  * Minor test suite tweaks for Win32 systems.
118
152
 
119
- == 0.2.1 - 28-Aug-2003
153
+ ## 0.2.1 - 28-Aug-2003
120
154
  * Removed VERSION class method. Just use the constant.
121
155
  * Bug fix with regards to split and Ruby 1.8. Thanks Michael Garriss.
122
156
  * Changed 'changelog' to 'CHANGES'.
@@ -125,7 +159,7 @@
125
159
  * Test unit cleanup
126
160
  * Minor internal directory layout and doc changes
127
161
 
128
- == 0.2.0 - 13-Jan-2003
162
+ ## 0.2.0 - 13-Jan-2003
129
163
  * DBRC class now under the DBI module namespace
130
164
  * Changed "timeout" to "time_out" to avoid confusion with the timeout
131
165
  module.
@@ -147,9 +181,9 @@
147
181
  * Install script improved
148
182
  * Documentation additions, including plain text doc
149
183
 
150
- == 0.1.1 - 26-Jul-2002
184
+ ## 0.1.1 - 26-Jul-2002
151
185
  * Added 'dsn()' method
152
186
  * Minor documentation additions
153
187
 
154
- == 0.1.0 - 26-Jul-2002
188
+ ## 0.1.0 - 26-Jul-2002
155
189
  * Initial release
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org' do
2
+ gemspec
3
+ end
@@ -1,16 +1,20 @@
1
- * MANIFEST
2
- * CHANGES
3
- * README
1
+ * CHANGES.md
2
+ * MANIFEST.md
3
+ * README.md
4
4
  * Rakefile
5
5
  * dbi-dbrc.gemspec
6
6
  * certs/djberg96_pub.pem
7
7
  * lib/dbi/dbrc.rb
8
+ * lib/dbi/dbrc/json.rb
9
+ * lib/dbi/dbrc/xml.rb
10
+ * lib/dbi/dbrc/yaml.rb
8
11
  * examples/plain/.dbrc
9
12
  * examples/plain/test.rb
10
13
  * examples/xml_examples/.dbrc
11
14
  * examples/xml_examples/test_xml.rb
12
15
  * examples/yml_examples/.dbrc
13
16
  * examples/yml_examples/test_yml.rb
14
- * test/test_dbi_dbrc.rb
15
- * test/test_dbi_dbrc_xml.rb
16
- * test/test_dbi_dbrc_yml.rb
17
+ * spec/dbi_dbrc_spec.rb
18
+ * spec/dbi_dbrc_json_spec.rb
19
+ * spec/dbi_dbrc_xml_spec.rb
20
+ * spec/dbi_dbrc_yml_spec.rb
data/README.md ADDED
@@ -0,0 +1,307 @@
1
+ ## Description
2
+ This is essentially a database connection configuration library, allowing you
3
+ to avoid hard-coding passwords in your programs, and store other generalized
4
+ information, when making database connections.
5
+
6
+ It can also be used as a general password storage manager for other types of
7
+ connections, e.g. ssh, ftp, etc.
8
+
9
+ The name was originally based on the old DBI library (which in turn was based
10
+ on the Perl library of the same name), and was originally meant as a supplement
11
+ to that library. The DBI library is now defunct, but it not necessary to use
12
+ this library. But, that explains why there's an outer "DBI" namespace module.
13
+
14
+ ## Requirements
15
+ * gpgme - For GPG encrypted files (which you should be doing).
16
+
17
+ For MS Windows there are these additional requirements:
18
+
19
+ * sys-admin
20
+ * win32-file-attributes
21
+ * win32-dir
22
+ * win32-process
23
+
24
+ ## Installation
25
+ `gem install dbi-dbrc`
26
+
27
+ ## Synopsis
28
+ ```ruby
29
+ require 'dbi/dbrc'
30
+
31
+ dbrc = DBI::DBRC.new('mydb') # or...
32
+ dbrc = DBI::DBRC.new('mydb', 'someUser')
33
+
34
+ puts dbrc.db
35
+ puts dbrc.user
36
+ puts dbrc.driver
37
+ puts dbrc.timeout
38
+ puts dbrc.max_reconn
39
+ puts dbrc.interval
40
+ puts dbrc.dsn
41
+ ```
42
+
43
+ ## Notes on the .dbrc file
44
+ This module relies on a file somewhere on your filesystem (normally your home
45
+ directory) called ".dbrc", and it is meant to be analogous to the ".netrc" file
46
+ used by programs such as telnet. The .dbrc file has several conditions that
47
+ must be met by the module or it will fail:
48
+
49
+ * Permissions must be set to 600 (Unix only).
50
+ * Must be hidden (MS Windows only).
51
+ * Must be owned by the current user.
52
+ * Must have database, user and password. Other fields are optional.
53
+ * Must be in the following space-separated format (in the 'plain' version):
54
+
55
+ ```
56
+ database user password driver timeout maximum_reconnects interval
57
+ # e.g. mydb dan mypass oracle 10 2 30
58
+ ```
59
+
60
+ You may include comments in the .dbrc file by starting the line with a
61
+ "#" symbol.
62
+
63
+ A failure in any of the rules mentioned above will result in a `DBRC::Error`
64
+ being raised. In addition, the file may also be encrypted on MS Windows
65
+ systems, in which case the file will automatically be (temporarily) decrypted.
66
+
67
+ The format for XML (using the example above) is as follows:
68
+
69
+ ```xml
70
+ <dbrc>
71
+ <database name="mydb">
72
+ <user>dan</user>
73
+ <password>mypass</password>
74
+ <driver>oracle</driver>
75
+ <interval>30</interval>
76
+ <timeout>10</timeout>
77
+ <maximum_reconnects>2</maximum_reconnects>
78
+ </database>
79
+ </dbrc>
80
+ ```
81
+
82
+ The format for YAML is as follows:
83
+
84
+ ```yaml
85
+ - mydb:
86
+ user: dan
87
+ password: mypass
88
+ driver: oracle
89
+ interval: 30
90
+ timeout: 10
91
+ max_reconn: 2
92
+ ```
93
+
94
+ The format for JSON is as follows:
95
+
96
+ ```json
97
+ [
98
+ {
99
+ "foo": {
100
+ "user": "dan",
101
+ "password": "mypass",
102
+ "driver": "oracle",
103
+ "interval": 30,
104
+ "timeout": 10,
105
+ "maximum_reconnects": 2
106
+ }
107
+ }
108
+ ]
109
+ ```
110
+
111
+ ## Constants
112
+ `VERSION`
113
+
114
+ The current version of this library, returned as a String.
115
+
116
+ ## Class Methods
117
+ `DBRC.new(db, user = nil, dir = nil, gpg_options = nil)`
118
+
119
+ The constructor takes one to three arguments. The first argument is the
120
+ database name. This *must* be provided. If only the database name is
121
+ passed, the module will look for the first database entry in the .dbrc
122
+ file that matches.
123
+
124
+ The second argument, a user name, is optional. If it is passed, the
125
+ module will look for the first entry in the .dbrc file where both the
126
+ database *and* user name match.
127
+
128
+ The third argument, also optional, specifies the directory where DBRC will
129
+ look for the .dbrc file. By default, it looks in the pwuid (present
130
+ working user id) home directory. The rules for a .dbrc file still apply.
131
+
132
+ The fourth argument, if present, are options that are forwarded to the
133
+ `GPGME::Crypto.new` constructor for GPG encrypted files. Typically this
134
+ would at least be the :password option, but YMMV.
135
+
136
+ MS Windows users should read the "Notes" section for how your home directory
137
+ is determined.
138
+
139
+ ## Instance Methods
140
+ `DBRC#database`
141
+
142
+ The name of the database. Note that the same entry can appear more than
143
+ once, presumably because you have multiple user id's for the same database.
144
+
145
+ `DBRC#db`
146
+
147
+ An alias for DBRC#database.
148
+
149
+ `DBRC#database=(database)`
150
+
151
+ Sets the database to +database+. This is generally discouraged because
152
+ it does not automatically reset the dsn.
153
+
154
+ `DBRC#db=(database)`
155
+
156
+ An alias for DBRC#database=.
157
+
158
+ `DBRC#user`
159
+
160
+ A valid user name for that database.
161
+
162
+ `DBRC#user=(user)`
163
+
164
+ Sets the user name to +user+.
165
+
166
+ `DBRC#password`
167
+
168
+ The password for that user.
169
+
170
+ `DBRC#passwd`
171
+
172
+ An alias for DBRC#password.
173
+
174
+ `DBRC#password=(password)`
175
+
176
+ Sets the password to +password+.
177
+
178
+ `DBRC#passwd=(password)`
179
+
180
+ An alias for DBRC#password=.
181
+
182
+ `DBRC#driver`
183
+
184
+ The driver type for that database (Oracle, MySql, etc).
185
+
186
+ `DBRC#driver=(driver)`
187
+
188
+ Sets the driver to +driver+. This use is discouraged because it does not reset the dsn.
189
+
190
+ `DBRC#timeout`
191
+
192
+ The timeout period for a connection before the attempt is dropped.
193
+
194
+ `DBRC#time_out`
195
+
196
+ An alias for DBRC#timeout, provided purely for the sake of backwards compatability.
197
+
198
+ `DBRC#timeout=(int)`
199
+
200
+ Sets the timeout value to +int+.
201
+
202
+ `DBRC#maximum_reconnects`
203
+
204
+ The maximum number of reconnect attempts that should be made for the the
205
+ database. Presumablly, you would use this with a "retry" within a rescue block.
206
+
207
+ `DBRC#max_reconn`
208
+
209
+ An alias for DBRC#maximum_reconnects.
210
+
211
+ `DBRC#maximum_reconnects=(max)`
212
+
213
+ Sets the maximum number of reconnect attempts to +max+.
214
+
215
+ `DBRC#max_reconn=(max)`
216
+
217
+ An alias for DBRC#maximum_reconnects.
218
+
219
+ `DBRC#interval`
220
+
221
+ The number of seconds to wait before attempting to reconnect to the database
222
+ again should a network/database glitch occur.
223
+
224
+ `DBRC#interval=(int)`
225
+
226
+ Sets the interval seconds between connection attempts.
227
+
228
+ `DBRC#dsn`
229
+
230
+ Returns a string in "dbi:<driver>:<database>" format.
231
+
232
+ `DBRC#dsn=(dsn)`
233
+
234
+ Sets the dsn string to +dsn+. This method is discouraged because it does
235
+ not automatically reset the driver or database.
236
+
237
+ ## Canonical Example
238
+ ```ruby
239
+ # This is a basic template for how I do things:
240
+ require 'dbi'
241
+ require 'dbi/dbrc'
242
+ require 'timeout'
243
+
244
+ db = DBI::DBRC.new("somedb")
245
+ n = db.max_reconn
246
+
247
+ begin
248
+ Timeout.timeout(db.timeout){
249
+ DBI.connect(db.dsn, db.user, db.passwd)
250
+ }
251
+ rescue DBI::Error
252
+ n -= 1
253
+ if n > 0
254
+ sleep db.interval
255
+ retry
256
+ end
257
+ raise
258
+ rescue TimeoutError
259
+ # handle timeout error
260
+ end
261
+ ```
262
+
263
+ ## Notes for MS Windows Users
264
+ To make your file hidden, right click on the .dbrc file in your Explorer
265
+ window, select "Properties" and check the "Hidden" checkbox.
266
+
267
+ I was going to require that the .dbrc file be encrypted on MS Windows,
268
+ but that may require an official "certificate", assigned to you by a third
269
+ party, which is a bit much to expect. However, if the file is encrypted,
270
+ DBRC will attempt to decrypt it, parse it, and encrypt it again when done
271
+ parsing.
272
+
273
+ ## Summary
274
+ These methods don't really "do" anything. They're simply meant as a
275
+ convenience mechanism for your database connections, plus a little bit of
276
+ obfuscation (for passwords).
277
+
278
+ ## Adding your own configuration
279
+ If you want to add your own type of configuration file, you can still use
280
+ the dbi-dbrc library. All you need to do is:
281
+
282
+ * subclass DBRC
283
+ * redefine the `parse_dbrc_config_file` method (a private method).
284
+
285
+ Take a look at the XML and YML subclasses in dbrc.rb for two examples that
286
+ you can work from.
287
+
288
+ ## Future Plans
289
+ None at this time.
290
+
291
+ ## Known Bugs
292
+ I'm not positive about the dsn strings for databases other than Oracle.
293
+ If it's not correct, please let me know.
294
+
295
+ ## Copyright
296
+ (C) Copyright 2002-2021, Daniel J. Berger, all rights reserved.
297
+
298
+ ## License
299
+ Apache-2.0
300
+
301
+ ## Warranty
302
+ This package is provided "as is" and without any express or
303
+ implied warranties, including, without limitation, the implied
304
+ warranties of merchantability and fitness for a particular purpose
305
+
306
+ ## Author
307
+ Daniel J. Berger