dbi-dbrc 1.1.2-x86-mswin32-60 → 1.1.3-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/README +10 -8
- data/lib/dbi/dbrc.rb +73 -21
- data/test/tc_dbrc.rb +16 -1
- metadata +2 -2
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 1.1.3 - 21-Jul-2008
|
2
|
+
* More RUBY_PLATFORM changes that I missed in the last release.
|
3
|
+
* Added inline RDOC for the accessors and updated the documentation
|
4
|
+
for the constructor.
|
5
|
+
* Added the DBI::DBRC#dbrc_dir and DBI::DBRC#dbrc_file methods.
|
6
|
+
* More tests.
|
7
|
+
|
1
8
|
== 1.1.2 - 18-Jul-2008
|
2
9
|
* Changed platform checking from RUBY_PLATFORM to Config::CONFIG['host_os']
|
3
10
|
so that other implementations won't choke.
|
data/README
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
== Description
|
2
2
|
This is a supplement to the dbi module, allowing you to avoid hard-coding
|
3
|
-
passwords in your programs that make database connections.
|
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.
|
4
6
|
|
5
7
|
== Requirements
|
6
8
|
* Ruby 1.8.2 or later
|
@@ -26,8 +28,6 @@
|
|
26
28
|
puts dbrc.interval
|
27
29
|
puts dbrc.dsn
|
28
30
|
|
29
|
-
dbh = DBI.connect(dbrc.dsn, dbrc.user, dbrc.password)
|
30
|
-
|
31
31
|
== Installation
|
32
32
|
rake test (optional)
|
33
33
|
rake install (non-gem) or rake install_gem (gem)
|
@@ -81,7 +81,7 @@
|
|
81
81
|
|
82
82
|
== Constants
|
83
83
|
VERSION
|
84
|
-
The current version of this
|
84
|
+
The current version of this library, returned as a String.
|
85
85
|
|
86
86
|
== Class Methods
|
87
87
|
DBRC.new(db, user=nil, dir=nil)
|
@@ -190,13 +190,15 @@ DBRC#dsn=(dsn)
|
|
190
190
|
n = db.max_reconn
|
191
191
|
|
192
192
|
begin
|
193
|
-
timeout(db.
|
193
|
+
Timeout.timeout(db.timeout){
|
194
194
|
DBI.connect(db.dsn, db.user, db.passwd)
|
195
195
|
}
|
196
196
|
rescue DBI::Error
|
197
197
|
n -= 1
|
198
|
-
|
199
|
-
|
198
|
+
if n > 0
|
199
|
+
sleep db.interval
|
200
|
+
retry
|
201
|
+
end
|
200
202
|
raise
|
201
203
|
rescue TimeoutError
|
202
204
|
# handle timeout error
|
@@ -232,7 +234,7 @@ DBRC#dsn=(dsn)
|
|
232
234
|
|
233
235
|
== Adding your own configuration
|
234
236
|
If you want to add your own type of configuration file, you can still use
|
235
|
-
the dbi-dbrc
|
237
|
+
the dbi-dbrc library. All you need to do is:
|
236
238
|
|
237
239
|
* subclass DBRC
|
238
240
|
* redefine the +parse_dbrc_config_file+ method (a private method).
|
data/lib/dbi/dbrc.rb
CHANGED
@@ -6,7 +6,6 @@ if Config::CONFIG['host_os'].match('mswin')
|
|
6
6
|
end
|
7
7
|
|
8
8
|
require 'sys/admin'
|
9
|
-
include Sys
|
10
9
|
|
11
10
|
# The DBI module serves as a namespace only.
|
12
11
|
module DBI
|
@@ -18,14 +17,45 @@ module DBI
|
|
18
17
|
# the error that is raised.
|
19
18
|
class Error < StandardError; end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
attr_accessor :maximum_reconnects, :timeout, :interval, :dbrc_dir
|
20
|
+
# The version of this library
|
21
|
+
VERSION = '1.1.3'
|
24
22
|
|
25
|
-
#
|
26
|
-
|
23
|
+
# The database or host to be connected to.
|
24
|
+
attr_accessor :database
|
25
|
+
|
26
|
+
# The user name used for the database or host connection.
|
27
|
+
attr_accessor :user
|
28
|
+
|
29
|
+
# The password associated with the database or host.
|
30
|
+
attr_accessor :password
|
31
|
+
|
32
|
+
# The driver associated with the database. This is used to internally to
|
33
|
+
# construct the DSN.
|
34
|
+
attr_accessor :driver
|
35
|
+
|
36
|
+
# Data source name, e.g. "dbi:OCI8:your_database".
|
37
|
+
attr_accessor :dsn
|
38
|
+
|
39
|
+
# The maximum number of reconnects a program should make before
|
40
|
+
# giving up.
|
41
|
+
attr_accessor :maximum_reconnects
|
42
|
+
|
43
|
+
# The timeout, in seconds, for each connection attempt.
|
44
|
+
attr_accessor :timeout
|
45
|
+
|
46
|
+
# The interval, in seconds, between each connection attempt.
|
47
|
+
attr_accessor :interval
|
48
|
+
|
49
|
+
# The directory where the .dbrc file is stored.
|
50
|
+
attr_accessor :dbrc_dir
|
51
|
+
|
52
|
+
# The full path to the .dbrc file.
|
53
|
+
attr_accessor :dbrc_file
|
54
|
+
|
55
|
+
# Returns a new DBI::DBRC object. The contents of the object depend on
|
56
|
+
# the arguments passed to the constructor. If only a database name is
|
27
57
|
# passed, then the first entry found in the .dbrc file that matches that
|
28
|
-
# database is parsed.
|
58
|
+
# database is parsed. If a user name is also included, then the first
|
29
59
|
# entry that matches both the database and user name is parsed.
|
30
60
|
#
|
31
61
|
# If a directory is passed as the third argument, then DBRC will look
|
@@ -35,11 +65,28 @@ module DBI
|
|
35
65
|
# If an entry cannot be found for the database, or database plus user
|
36
66
|
# combination, then a Error is raised. If the .dbrc file cannot
|
37
67
|
# be found, or is setup improperly with regards to permissions or
|
38
|
-
# properties, a Error is raised.
|
68
|
+
# properties, a DBI::DBRC::Error is raised.
|
69
|
+
#
|
70
|
+
# See the README for the rules regarding .dbrc files and permissions.
|
71
|
+
#
|
72
|
+
# Note that this library can also be used as a general password
|
73
|
+
# storage mechanism. In that case simply treat the 'database' as the
|
74
|
+
# host name, and ignore the DBI::DBRC#dsn and DBI::DBRC#driver methods.
|
75
|
+
#
|
76
|
+
# Examples:
|
77
|
+
#
|
78
|
+
# # Find the first match for 'some_database'
|
79
|
+
# DBI::DBRC.new('some_database')
|
80
|
+
#
|
81
|
+
# # Find the first match for 'foo_user@some_database'
|
82
|
+
# DBI::DBRC.new('some_database', 'foo_user')
|
83
|
+
#
|
84
|
+
# # Find the first match for 'foo_user@some_database' under /usr/local
|
85
|
+
# DBI::DBRC.new('some_database', 'foo_usr', '/usr/local')
|
39
86
|
#
|
40
87
|
def initialize(database, user=nil, dbrc_dir=nil)
|
41
88
|
if dbrc_dir.nil?
|
42
|
-
if
|
89
|
+
if Config::CONFIG['host_os'].match('mswin')
|
43
90
|
home = ENV['USERPROFILE'] || ENV['HOME']
|
44
91
|
file = nil
|
45
92
|
|
@@ -51,12 +98,16 @@ module DBI
|
|
51
98
|
|
52
99
|
@dbrc_file = file
|
53
100
|
else
|
54
|
-
@dbrc_file = File.join(
|
101
|
+
@dbrc_file = File.join(
|
102
|
+
Sys::Admin.get_user(Process.uid).dir,
|
103
|
+
'.dbrc'
|
104
|
+
)
|
55
105
|
end
|
56
106
|
else
|
57
107
|
@dbrc_file = File.join(dbrc_dir, '.dbrc')
|
58
108
|
end
|
59
109
|
|
110
|
+
@dbrc_dir = dbrc_dir
|
60
111
|
@database = database
|
61
112
|
@user = user
|
62
113
|
encrypted = false # Win32 only
|
@@ -69,7 +120,7 @@ module DBI
|
|
69
120
|
check_file()
|
70
121
|
|
71
122
|
# If on Win32 and the file is encrypted, decrypt it.
|
72
|
-
if
|
123
|
+
if Config::CONFIG['host_os'].match("mswin") && File.encrypted?(@dbrc_file)
|
73
124
|
encrypted = true
|
74
125
|
File.decrypt(@dbrc_file)
|
75
126
|
end
|
@@ -80,7 +131,7 @@ module DBI
|
|
80
131
|
create_dsn_string()
|
81
132
|
|
82
133
|
# If on Win32 and the file was encrypted, re-encrypt it
|
83
|
-
if
|
134
|
+
if Config::CONFIG['host_os'].match("mswin") && encrypted
|
84
135
|
File.encrypt(@dbrc_file)
|
85
136
|
end
|
86
137
|
end
|
@@ -116,7 +167,7 @@ module DBI
|
|
116
167
|
|
117
168
|
# Permissions must be set to 600 or better on Unix systems.
|
118
169
|
# Must be hidden on Win32 systems.
|
119
|
-
if
|
170
|
+
if Config::CONFIG['host_os'].match("mswin")
|
120
171
|
unless File.hidden?(file)
|
121
172
|
raise Error, "The .dbrc file must be hidden"
|
122
173
|
end
|
@@ -165,14 +216,15 @@ module DBI
|
|
165
216
|
raise Error, err
|
166
217
|
end
|
167
218
|
|
168
|
-
alias_method(:db
|
169
|
-
alias_method(:db
|
170
|
-
alias_method(:passwd
|
171
|
-
alias_method(:passwd
|
172
|
-
alias_method(:max_reconn
|
173
|
-
alias_method(:max_reconn
|
174
|
-
alias_method(:time_out
|
175
|
-
alias_method(:time_out
|
219
|
+
alias_method(:db, :database)
|
220
|
+
alias_method(:db=, :database=)
|
221
|
+
alias_method(:passwd, :password)
|
222
|
+
alias_method(:passwd=, :password=)
|
223
|
+
alias_method(:max_reconn, :maximum_reconnects)
|
224
|
+
alias_method(:max_reconn=, :maximum_reconnects=)
|
225
|
+
alias_method(:time_out, :timeout)
|
226
|
+
alias_method(:time_out=, :timeout=)
|
227
|
+
alias_method(:host, :database)
|
176
228
|
end
|
177
229
|
|
178
230
|
# A subclass of DBRC designed to handle .dbrc files in XML format. The
|
data/test/tc_dbrc.rb
CHANGED
@@ -31,7 +31,7 @@ class TC_DBRC < Test::Unit::TestCase
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_version
|
34
|
-
assert_equal("1.1.
|
34
|
+
assert_equal("1.1.3", DBRC::VERSION)
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_bad_dbrc_properties
|
@@ -66,6 +66,21 @@ class TC_DBRC < Test::Unit::TestCase
|
|
66
66
|
assert_kind_of(String, @dbrc.db)
|
67
67
|
end
|
68
68
|
|
69
|
+
def test_host_alias
|
70
|
+
assert_respond_to(@dbrc, :host)
|
71
|
+
assert_equal(true, @dbrc.method(:host) == @dbrc.method(:database))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_dbrc_dir
|
75
|
+
assert_respond_to(@dbrc, :dbrc_dir)
|
76
|
+
assert_equal(@dir, @dbrc.dbrc_dir)
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_dbrc_file
|
80
|
+
assert_respond_to(@dbrc, :dbrc_file)
|
81
|
+
assert_equal('.dbrc', File.basename(@dbrc.dbrc_file))
|
82
|
+
end
|
83
|
+
|
69
84
|
def test_dsn
|
70
85
|
assert_respond_to(@dbrc, :dsn)
|
71
86
|
assert_respond_to(@dbrc, :dsn=)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbi-dbrc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
platform: x86-mswin32-60
|
6
6
|
authors:
|
7
7
|
- Daniel Berger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-07-
|
12
|
+
date: 2008-07-21 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|