dbi-dbrc 1.4.1 → 1.5.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.
@@ -0,0 +1,5 @@
1
+ require 'rspec'
2
+
3
+ RSpec.configure do |config|
4
+ config.filter_run_excluding(:windows) if RbConfig::CONFIG['host_os'] !~ /mswin|win32|dos|mingw|cygwin/i
5
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbi-dbrc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Berger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -35,10 +35,10 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date:
38
+ date:
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
- name: test-unit
41
+ name: rake
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
@@ -52,19 +52,33 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  - !ruby/object:Gem::Dependency
55
- name: rake
55
+ name: rspec
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: '3.9'
61
61
  type: :development
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: '3.9'
68
+ - !ruby/object:Gem::Dependency
69
+ name: fakefs
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.3'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.3'
68
82
  description: |2
69
83
  The dbi-dbrc library provides an interface for storing database
70
84
  connection information, including passwords, in a locally secure
@@ -77,44 +91,43 @@ description: |2
77
91
  email: djberg96@gmail.com
78
92
  executables: []
79
93
  extensions: []
80
- extra_rdoc_files:
81
- - README
82
- - CHANGES
83
- - MANIFEST
94
+ extra_rdoc_files: []
84
95
  files:
85
- - CHANGES
86
- - test
87
- - test/test_dbi_dbrc_xml.rb
88
- - test/test_dbi_dbrc.rb
89
- - test/test_dbi_dbrc_yml.rb
96
+ - dbi-dbrc.gemspec
97
+ - spec
98
+ - spec/spec_helper.rb
99
+ - spec/dbi_dbrc_yml_spec.rb
100
+ - spec/dbi_dbrc_spec.rb
101
+ - spec/dbi_dbrc_xml_spec.rb
102
+ - README.md
103
+ - Rakefile
104
+ - MANIFEST.md
105
+ - certs
106
+ - certs/djberg96_pub.pem
90
107
  - examples
91
- - examples/xml
92
- - examples/xml/test_xml.rb
93
108
  - examples/plain
94
109
  - examples/plain/test.rb
110
+ - examples/xml
111
+ - examples/xml/test_xml.rb
95
112
  - examples/yml
96
113
  - examples/yml/test_yml.rb
97
- - README
98
- - Rakefile
99
- - MANIFEST
100
114
  - lib
101
115
  - lib/dbi
102
116
  - lib/dbi/dbrc.rb
103
117
  - lib/dbi-dbrc.rb
104
- - dbi-dbrc.gemspec
105
- - certs
106
- - certs/djberg96_pub.pem
118
+ - Gemfile
119
+ - CHANGES.md
107
120
  homepage: https://github.com/djberg96/dbi-dbrc
108
121
  licenses:
109
122
  - Apache-2.0
110
123
  metadata:
111
124
  homepage_uri: https://github.com/djberg96/dbi-dbrc
112
125
  bug_tracker_uri: https://github.com/djberg96/dbi-dbrc/issues
113
- changelog_uri: https://github.com/djberg96/dbi-dbrc/blob/master/CHANGES
126
+ changelog_uri: https://github.com/djberg96/dbi-dbrc/blob/main/CHANGES
114
127
  documentation_uri: https://github.com/djberg96/dbi-dbrc/wiki
115
128
  source_code_uri: https://github.com/djberg96/dbi-dbrc
116
129
  wiki_uri: https://github.com/djberg96/dbi-dbrc/wiki
117
- post_install_message:
130
+ post_install_message:
118
131
  rdoc_options: []
119
132
  require_paths:
120
133
  - lib
@@ -122,18 +135,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
135
  requirements:
123
136
  - - ">="
124
137
  - !ruby/object:Gem::Version
125
- version: 1.9.3
138
+ version: '0'
126
139
  required_rubygems_version: !ruby/object:Gem::Requirement
127
140
  requirements:
128
141
  - - ">="
129
142
  - !ruby/object:Gem::Version
130
143
  version: '0'
131
144
  requirements: []
132
- rubygems_version: 3.0.2
133
- signing_key:
145
+ rubygems_version: 3.2.15
146
+ signing_key:
134
147
  specification_version: 4
135
148
  summary: A simple way to avoid hard-coding passwords with DBI
136
- test_files:
137
- - test/test_dbi_dbrc_xml.rb
138
- - test/test_dbi_dbrc.rb
139
- - test/test_dbi_dbrc_yml.rb
149
+ test_files: []
metadata.gz.sig CHANGED
Binary file
data/README DELETED
@@ -1,265 +0,0 @@
1
- == Description
2
- This is a supplement to the dbi module, allowing you to avoid hard-coding
3
- passwords in your programs that make database connections. It can also
4
- be used as a general password storage mechanism for other types of
5
- connections, e.g. ssh, ftp, etc.
6
-
7
- == Requirements
8
- MS Windows users have these additional requirements:
9
-
10
- * sys-admin
11
- * win32-file-attributes
12
- * win32-dir
13
- * win32-process
14
-
15
- == Installation
16
- gem install dbi-dbrc
17
-
18
- == Synopsis
19
- require 'dbi/dbrc'
20
- include DBI
21
-
22
- dbrc = DBRC.new('mydb')
23
-
24
- or
25
-
26
- dbrc = DBRC.new('mydb', 'someUser')
27
-
28
- puts dbrc.db
29
- puts dbrc.user
30
- puts dbrc.driver
31
- puts dbrc.timeout
32
- puts dbrc.max_reconn
33
- puts dbrc.interval
34
- puts dbrc.dsn
35
-
36
- == Notes on the .dbrc file
37
- This module relies on a file in your home directory called ".dbrc", and it
38
- is meant to be analogous to the ".netrc" file used by programs such as
39
- telnet. The .dbrc file has several conditions that must be met by the
40
- module or it will fail:
41
-
42
- * Permissions must be set to 600 (Unix only).
43
- * Must be hidden (MS Windows only).
44
- * Must be owned by the current user.
45
- * Must have database, user and password. Other fields are optional.
46
- * Must be in the following space-separated format (in the 'plain' version):
47
-
48
- database user password driver timeout maximum_reconnects interval
49
-
50
- e.g. mydb dan mypass oracle 10 2 30
51
-
52
- You may include comments in the .dbrc file by starting the line with a
53
- "#" symbol.
54
-
55
- A failure in any of the rules mentioned above will result in a DBRC::Error
56
- being raised. In addition, the file may also be encrypted on MS Windows
57
- systems, in which case the file will automatically be (temporarily)
58
- decrypted.
59
-
60
- The format for XML (using the example above) is as follows:
61
-
62
- <dbrc>
63
- <database name="mydb">
64
- <user>dan</user>
65
- <password>mypass</password>
66
- <driver>oracle</driver>
67
- <interval>30</interval>
68
- <timeout>10</timeout>
69
- <maximum_reconnects>2</maximum_reconnects>
70
- </database>
71
- </dbrc>
72
-
73
- The format for YAML is as follows:
74
-
75
- - mydb:
76
- user: dan
77
- password: mypass
78
- driver: oracle
79
- interval: 30
80
- timeout: 10
81
- max_reconn: 2
82
-
83
- == Constants
84
- VERSION
85
- The current version of this library, returned as a String.
86
-
87
- == Class Methods
88
- DBRC.new(db, user=nil, dir=nil)
89
- The constructor takes one to three arguments. The first argument is the
90
- database name. This *must* be provided. If only the database name is
91
- passed, the module will look for the first database entry in the .dbrc
92
- file that matches.
93
-
94
- The second argument, a user name, is optional. If it is passed, the
95
- module will look for the first entry in the .dbrc file where both the
96
- database *and* user name match.
97
-
98
- The third argument, also optional, specifies the directory where DBRC will
99
- look for the .dbrc file. By default, it looks in the pwuid (present
100
- working user id) home directory. The rules for a .dbrc file still apply.
101
-
102
- MS Windows users should read the "Notes" section for how your home directory
103
- is determined.
104
-
105
- == Instance Methods
106
- DBRC#database
107
- The name of the database. Note that the same entry can appear more than
108
- once, presumably because you have multiple user id's for the same
109
- database.
110
-
111
- DBRC#db
112
- An alias for DBRC#database.
113
-
114
- DBRC#database=(database)
115
- Sets the database to +database+. This is generally discouraged because
116
- it does not automatically reset the dsn.
117
-
118
- DBRC#db=(database)
119
- An alias for DBRC#database=.
120
-
121
- DBRC#user
122
- A valid user name for that database.
123
-
124
- DBRC#user=(user)
125
- Sets the user name to +user+.
126
-
127
- DBRC#password
128
- The password for that user.
129
-
130
- DBRC#passwd
131
- An alias for DBRC#password.
132
-
133
- DBRC#password=(password)
134
- Sets the password to +password+.
135
-
136
- DBRC#passwd=(password)
137
- An alias for DBRC#password=.
138
-
139
- DBRC#driver
140
- The driver type for that database (Oracle, MySql, etc).
141
-
142
- DBRC#driver=(driver)
143
- Sets the driver to +driver+. This use is discouraged because it does
144
- not reset the dsn.
145
-
146
- DBRC#timeout
147
- The timeout period for a connection before the attempt is dropped.
148
-
149
- DBRC#time_out
150
- An alias for DBRC#timeout, provided purely for the sake of backwards
151
- compatability.
152
-
153
- DBRC#timeout=(int)
154
- Sets the timeout value to +int+.
155
-
156
- DBRC#maximum_reconnects
157
- The maximum number of reconnect attempts that should be made for the the
158
- database. Presumablly, you would use this with a "retry" within a rescue
159
- block.
160
-
161
- DBRC#max_reconn
162
- An alias for DBRC#maximum_reconnects.
163
-
164
- DBRC#maximum_reconnects=(max)
165
- Sets the maximum number of reconnect attempts to +max+.
166
-
167
- DBRC#max_reconn=(max)
168
- An alias for DBRC#maximum_reconnects.
169
-
170
- DBRC#interval
171
- The number of seconds to wait before attempting to reconnect to the database
172
- again should a network/database glitch occur.
173
-
174
- DBRC#interval=(int)
175
- Sets the interval seconds between connection attempts.
176
-
177
- DBRC#dsn
178
- Returns a string in "dbi:<driver>:<database>" format.
179
-
180
- DBRC#dsn=(dsn)
181
- Sets the dsn string to +dsn+. This method is discouraged because it does
182
- not automatically reset the driver or database.
183
-
184
- == Canonical Example
185
- # This is a basic template for how I do things:
186
-
187
- require 'dbi/dbrc'
188
- require 'timeout'
189
-
190
- db = DBI::DBRC.new("somedb")
191
- n = db.max_reconn
192
-
193
- begin
194
- Timeout.timeout(db.timeout){
195
- DBI.connect(db.dsn, db.user, db.passwd)
196
- }
197
- rescue DBI::Error
198
- n -= 1
199
- if n > 0
200
- sleep db.interval
201
- retry
202
- end
203
- raise
204
- rescue TimeoutError
205
- # handle timeout error
206
- end
207
-
208
- == Notes for MS Windows Users
209
- The 'home' directory for Win32 users is determined by ENV['USERPROFILE'].
210
- If that is not set, ENV['HOME'] is used. If that is not set, then
211
- the directory found by the sys-admin library is used.
212
-
213
- To make your file hidden, right click on the .dbrc file in your Explorer
214
- window, select "Properties" and check the "Hidden" checkbox.
215
-
216
- I was going to require that the .dbrc file be encrypted on MS Windows,
217
- but that may require an official "certificate", assigned to you by a third
218
- party, which is a bit much to expect. However, if the file is encrypted,
219
- DBRC will attempt to decrypt it, parse it, and encrypt it again when done
220
- parsing.
221
-
222
- == Notes on running the test suite
223
- I cannot guarantee that the .dbrc files under the +examples+
224
- subdirectories maintain the appropriate properties. This can cause
225
- failures for the test suite (which uses these files).
226
-
227
- The only solution is to perform a 'chmod 600 .dbrc' (on Unix) or set
228
- the properties to 'hidden' (on MS Windows) manually, for the file in
229
- question.
230
-
231
- == Summary
232
- These "methods" don't really do anything. They're simply meant as a
233
- convenience mechanism for you dbi connections, plus a little bit of
234
- obfuscation (for passwords).
235
-
236
- == Adding your own configuration
237
- If you want to add your own type of configuration file, you can still use
238
- the dbi-dbrc library. All you need to do is:
239
-
240
- * subclass DBRC
241
- * redefine the +parse_dbrc_config_file+ method (a private method).
242
-
243
- Take a look at the XML and YML subclasses in dbrc.rb for two examples that
244
- you can work from.
245
-
246
- == Future Plans
247
- Add DBI::DBRC::JSON.
248
-
249
- == Known Bugs
250
- I'm not positive about the dsn strings for databases other than Oracle.
251
- If it's not correct, please let me know.
252
-
253
- == Copyright
254
- (C) Copyright 2002-2019, Daniel J. Berger, all rights reserved.
255
-
256
- == License
257
- Apache-2.0
258
-
259
- = Warranty
260
- This package is provided "as is" and without any express or
261
- implied warranties, including, without limitation, the implied
262
- warranties of merchantability and fitness for a particular purpose
263
-
264
- == Author
265
- Daniel J. Berger
@@ -1,199 +0,0 @@
1
- #########################################################################
2
- # test_dbi_dbrc.rb
3
- #
4
- # Test suite for the base class of DBI::DBRC. This test case should be
5
- # run via the 'rake test' task.
6
- #########################################################################
7
- require 'dbi/dbrc'
8
- require 'test-unit'
9
- include DBI
10
-
11
- class TC_DBI_DBRC < Test::Unit::TestCase
12
- def self.startup
13
- @@windows = File::ALT_SEPARATOR
14
- end
15
-
16
- def setup
17
- @dir = File.join(Dir.pwd, 'examples/plain')
18
- @file = File.join(@dir, '.dbrc')
19
- @db1 = 'foo'
20
- @db2 = 'bar'
21
- @user1 = 'user1'
22
- @user2 = 'user2'
23
- @db_bad = 'blah' # Doesn't exist
24
- @user_bad = 'user8' # Doesn't exist
25
-
26
- if @@windows && File.respond_to?(:set_attr)
27
- File.set_attr(@file, File::HIDDEN)
28
- else
29
- File.chmod(0600, @file)
30
- end
31
-
32
- @dbrc = DBRC.new(@db1, nil, @dir)
33
- end
34
-
35
- def test_version
36
- assert_equal('1.4.1', DBRC::VERSION)
37
- assert_true(DBRC::VERSION.frozen?)
38
- end
39
-
40
- def test_bad_dbrc_properties
41
- if @@windows
42
- File.unset_attr(@file, File::HIDDEN)
43
- assert_raises(DBRC::Error){ DBRC.new(@db1, @user1, @dir) }
44
- else
45
- File.chmod(0555,@file)
46
- assert_raises(DBRC::Error){ DBRC.new(@db1, @user1, @dir) }
47
- end
48
- end
49
-
50
- def test_constructor
51
- assert_raises(ArgumentError){ DBRC.new }
52
- assert_nothing_raised{ DBRC.new(@db1, @user1, @dir) }
53
- assert_nothing_raised{ DBRC.new(@db1, nil, @dir) }
54
- end
55
-
56
- def test_bad_database
57
- assert_raise(DBRC::Error){ DBRC.new(@db_bad, nil, @dir) }
58
- end
59
-
60
- def test_bad_user
61
- assert_raise(DBRC::Error){ DBRC.new(@db1, @user_bad, @dir) }
62
- end
63
-
64
- def test_bad_dir
65
- assert_raise(DBI::DBRC::Error){ DBI::DBRC.new(@db1, @user1, '/bogusXX') }
66
- end
67
-
68
- def test_database
69
- assert_respond_to(@dbrc, :database)
70
- assert_respond_to(@dbrc, :database=)
71
- assert_respond_to(@dbrc, :db)
72
- assert_respond_to(@dbrc, :db=)
73
- assert_kind_of(String, @dbrc.db)
74
- end
75
-
76
- def test_host_alias
77
- assert_respond_to(@dbrc, :host)
78
- assert_equal(true, @dbrc.method(:host) == @dbrc.method(:database))
79
- end
80
-
81
- def test_dbrc_dir
82
- assert_respond_to(@dbrc, :dbrc_dir)
83
- assert_equal(@dir, @dbrc.dbrc_dir)
84
- end
85
-
86
- def test_dbrc_file
87
- assert_respond_to(@dbrc, :dbrc_file)
88
- assert_equal('.dbrc', File.basename(@dbrc.dbrc_file))
89
- end
90
-
91
- def test_dsn
92
- assert_respond_to(@dbrc, :dsn)
93
- assert_respond_to(@dbrc, :dsn=)
94
- end
95
-
96
- def test_user
97
- assert_respond_to(@dbrc, :user)
98
- assert_respond_to(@dbrc, :user=)
99
- assert_kind_of(String, @dbrc.user)
100
- end
101
-
102
- def test_password
103
- assert_respond_to(@dbrc, :password)
104
- assert_respond_to(@dbrc, :password=)
105
- assert_respond_to(@dbrc, :passwd)
106
- assert_respond_to(@dbrc, :passwd=)
107
- assert_kind_of(String, @dbrc.password)
108
- end
109
-
110
- def test_driver
111
- assert_respond_to(@dbrc, :driver)
112
- assert_respond_to(@dbrc, :driver=)
113
- assert_kind_of(String, @dbrc.driver)
114
- end
115
-
116
- def test_interval
117
- assert_respond_to(@dbrc, :interval)
118
- assert_respond_to(@dbrc, :interval=)
119
- assert_kind_of(Numeric, @dbrc.interval)
120
- end
121
-
122
- def test_timeout
123
- assert_respond_to(@dbrc, :timeout)
124
- assert_respond_to(@dbrc, :timeout=)
125
- assert_respond_to(@dbrc, :time_out)
126
- assert_respond_to(@dbrc, :time_out=)
127
- assert_kind_of(Numeric, @dbrc.timeout)
128
- end
129
-
130
- def test_max_reconn
131
- assert_respond_to(@dbrc, :max_reconn)
132
- assert_respond_to(@dbrc, :max_reconn=)
133
- assert_respond_to(@dbrc, :maximum_reconnects)
134
- assert_respond_to(@dbrc, :maximum_reconnects=)
135
- assert_kind_of(Numeric, @dbrc.maximum_reconnects)
136
- end
137
-
138
- def test_sample_values
139
- assert_equal("foo", @dbrc.database)
140
- assert_equal("user1", @dbrc.user)
141
- assert_equal("pwd1", @dbrc.passwd)
142
- assert_equal("Oracle", @dbrc.driver)
143
- assert_equal(60, @dbrc.interval)
144
- assert_equal(40, @dbrc.timeout)
145
- assert_equal(3, @dbrc.max_reconn)
146
- assert_equal("dbi:Oracle:foo", @dbrc.dsn)
147
- end
148
-
149
- # Same database, different user
150
- def test_duplicate_database
151
- db = DBRC.new("foo", "user2", @dir)
152
- assert_equal("user2", db.user)
153
- assert_equal("pwd2", db.passwd)
154
- assert_equal("OCI8", db.driver)
155
- assert_equal(60, db.interval)
156
- assert_equal(60, db.timeout)
157
- assert_equal(4, db.max_reconn)
158
- assert_equal("dbi:OCI8:foo", db.dsn)
159
- end
160
-
161
- # Different database, different user
162
- def test_different_database
163
- db = DBRC.new("bar", "user1", @dir)
164
- assert_equal("user1", db.user)
165
- assert_equal("pwd3", db.passwd)
166
- assert_equal("Oracle", db.driver)
167
- assert_equal(30, db.interval)
168
- assert_equal(30, db.timeout)
169
- assert_equal(2, db.max_reconn)
170
- assert_equal("dbi:Oracle:bar", db.dsn)
171
- end
172
-
173
- # A database with only a couple fields defined
174
- def test_nil_values
175
- db = DBRC.new("baz", "user3", @dir)
176
- assert_equal("user3", db.user)
177
- assert_equal("pwd4", db.passwd)
178
- assert_nil(db.driver)
179
- assert_nil(db.interval)
180
- assert_nil(db.timeout)
181
- assert_nil(db.max_reconn)
182
- assert_nil(db.dsn)
183
- end
184
-
185
- def teardown
186
- @dir = nil
187
- @db1 = nil
188
- @db2 = nil
189
- @user1 = nil
190
- @user2 = nil
191
- @db_bad = nil
192
- @user_bad = nil
193
- @dbrc = nil
194
- end
195
-
196
- def self.shutdown
197
- @@windows = nil
198
- end
199
- end