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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.md} +57 -23
- data/Gemfile +3 -0
- data/{MANIFEST → MANIFEST.md} +10 -6
- data/README.md +307 -0
- data/Rakefile +6 -22
- data/certs/djberg96_pub.pem +22 -17
- data/dbi-dbrc.gemspec +17 -6
- data/examples/yml/test_yml.rb +5 -5
- data/lib/dbi-dbrc.rb +3 -0
- data/lib/dbi/dbrc.rb +78 -133
- data/lib/dbi/dbrc/json.rb +38 -0
- data/lib/dbi/dbrc/xml.rb +35 -0
- data/lib/dbi/dbrc/yaml.rb +37 -0
- data/spec/dbi_dbrc_json_spec.rb +109 -0
- data/spec/dbi_dbrc_spec.rb +247 -0
- data/spec/dbi_dbrc_xml_spec.rb +101 -0
- data/spec/dbi_dbrc_yml_spec.rb +95 -0
- data/spec/spec_helper.rb +6 -0
- metadata +85 -46
- metadata.gz.sig +0 -0
- data/README +0 -260
- data/test/test_dbi_dbrc.rb +0 -198
- data/test/test_dbi_dbrc_xml.rb +0 -159
- data/test/test_dbi_dbrc_yml.rb +0 -157
@@ -0,0 +1,101 @@
|
|
1
|
+
########################################################################
|
2
|
+
# dbi_dbrc_xml_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the XML specific version of DBI::DBRC. This test case
|
5
|
+
# should be run via the 'rake test' task.
|
6
|
+
########################################################################
|
7
|
+
require 'dbi/dbrc'
|
8
|
+
require 'rspec'
|
9
|
+
require 'pp' # Need this to avoid fakefs error
|
10
|
+
require 'fakefs/spec_helpers'
|
11
|
+
|
12
|
+
RSpec.describe DBI::DBRC::XML, :xml => true do
|
13
|
+
include FakeFS::SpecHelpers
|
14
|
+
|
15
|
+
let(:home) { File.join(Dir.pwd, 'home', 'someone') }
|
16
|
+
let(:dbrc) { File.join(home, '.dbrc') }
|
17
|
+
|
18
|
+
let(:db_foo){ 'foo' }
|
19
|
+
let(:user1) { 'user1' }
|
20
|
+
|
21
|
+
let(:xml){
|
22
|
+
%q{
|
23
|
+
<dbrc>
|
24
|
+
<database name="foo">
|
25
|
+
<user>user1</user>
|
26
|
+
<password>pwd1</password>
|
27
|
+
<driver>Oracle</driver>
|
28
|
+
<interval>60</interval>
|
29
|
+
<timeout>40</timeout>
|
30
|
+
<maximum_reconnects>3</maximum_reconnects>
|
31
|
+
</database>
|
32
|
+
<database name="foo">
|
33
|
+
<user>user2</user>
|
34
|
+
<password>pwd2</password>
|
35
|
+
<driver>OCI8</driver>
|
36
|
+
<interval>60</interval>
|
37
|
+
<timeout>60</timeout>
|
38
|
+
<maximum_reconnects>4</maximum_reconnects>
|
39
|
+
</database>
|
40
|
+
<database name="bar">
|
41
|
+
<user>user1</user>
|
42
|
+
<password>pwd3</password>
|
43
|
+
<driver>Oracle</driver>
|
44
|
+
<interval>30</interval>
|
45
|
+
<timeout>30</timeout>
|
46
|
+
<maximum_reconnects>2</maximum_reconnects>
|
47
|
+
</database>
|
48
|
+
<database name="baz">
|
49
|
+
<user>user3</user>
|
50
|
+
<password>pwd4</password>
|
51
|
+
</database>
|
52
|
+
</dbrc>
|
53
|
+
}.lstrip
|
54
|
+
}
|
55
|
+
|
56
|
+
before do
|
57
|
+
allow(Dir).to receive(:home).and_return(home)
|
58
|
+
|
59
|
+
if File::ALT_SEPARATOR
|
60
|
+
allow(FakeFS::File).to receive(:hidden?).and_return(true)
|
61
|
+
allow(FakeFS::File).to receive(:encrypted?).and_return(false)
|
62
|
+
end
|
63
|
+
|
64
|
+
FileUtils.mkdir_p(home)
|
65
|
+
File.open(dbrc, 'w'){ |fh| fh.write(xml) }
|
66
|
+
File.chmod(0600, dbrc)
|
67
|
+
|
68
|
+
# FakeFS doesn't implement this yet
|
69
|
+
allow_any_instance_of(FakeFS::File::Stat).to receive(:owned?).and_return(true)
|
70
|
+
end
|
71
|
+
|
72
|
+
context "instance methods" do
|
73
|
+
before do
|
74
|
+
@dbrc = described_class.new(db_foo, user1)
|
75
|
+
end
|
76
|
+
|
77
|
+
example "database method returns expected value" do
|
78
|
+
expect(@dbrc.database).to eq('foo')
|
79
|
+
end
|
80
|
+
|
81
|
+
example "password method returns expected value" do
|
82
|
+
expect(@dbrc.password).to eq('pwd1')
|
83
|
+
end
|
84
|
+
|
85
|
+
example "driver method returns expected value" do
|
86
|
+
expect(@dbrc.driver).to eq('Oracle')
|
87
|
+
end
|
88
|
+
|
89
|
+
example "interval method returns expected value" do
|
90
|
+
expect(@dbrc.interval).to eq(60)
|
91
|
+
end
|
92
|
+
|
93
|
+
example "timeout method returns expected value" do
|
94
|
+
expect(@dbrc.timeout).to eq(40)
|
95
|
+
end
|
96
|
+
|
97
|
+
example "maximum_reconnects method returns expected value" do
|
98
|
+
expect(@dbrc.maximum_reconnects).to eq(3)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
########################################################################
|
2
|
+
# dbi_dbrc_yml_spec.rb
|
3
|
+
#
|
4
|
+
# Test suite for the YAML specific version of DBI::DBRC. This test case
|
5
|
+
# should be run via the 'rake test' task.
|
6
|
+
########################################################################
|
7
|
+
require 'dbi/dbrc'
|
8
|
+
require 'rspec'
|
9
|
+
require 'pp' # Need this to avoid fakefs error
|
10
|
+
require 'fakefs/spec_helpers'
|
11
|
+
|
12
|
+
RSpec.describe DBI::DBRC::YML, :yml => true do
|
13
|
+
include FakeFS::SpecHelpers
|
14
|
+
|
15
|
+
let(:home) { File.join(Dir.pwd, 'home', 'someone') }
|
16
|
+
let(:dbrc) { File.join(home, '.dbrc') }
|
17
|
+
|
18
|
+
let(:db_foo){ 'foo' }
|
19
|
+
let(:user1) { 'user1' }
|
20
|
+
|
21
|
+
let(:yml){
|
22
|
+
%q{
|
23
|
+
- foo:
|
24
|
+
user: user1
|
25
|
+
password: pwd1
|
26
|
+
driver: Oracle
|
27
|
+
interval: 60
|
28
|
+
timeout: 40
|
29
|
+
maximum_reconnects: 3
|
30
|
+
- foo:
|
31
|
+
user: user2
|
32
|
+
password: pwd2
|
33
|
+
driver: OCI8
|
34
|
+
interval: 60
|
35
|
+
timeout: 60
|
36
|
+
maximum_reconnects: 4
|
37
|
+
- bar:
|
38
|
+
user: user1
|
39
|
+
password: pwd3
|
40
|
+
driver: Oracle
|
41
|
+
interval: 30
|
42
|
+
timeout: 30
|
43
|
+
maximum_reconnects: 2
|
44
|
+
- baz:
|
45
|
+
user: user3
|
46
|
+
password: pwd4
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
before do
|
51
|
+
allow(Dir).to receive(:home).and_return(home)
|
52
|
+
|
53
|
+
if File::ALT_SEPARATOR
|
54
|
+
allow(FakeFS::File).to receive(:hidden?).and_return(true)
|
55
|
+
allow(FakeFS::File).to receive(:encrypted?).and_return(false)
|
56
|
+
end
|
57
|
+
|
58
|
+
FileUtils.mkdir_p(home)
|
59
|
+
File.open(dbrc, 'w'){ |fh| fh.write(yml) }
|
60
|
+
File.chmod(0600, dbrc)
|
61
|
+
|
62
|
+
# FakeFS doesn't implement this yet
|
63
|
+
allow_any_instance_of(FakeFS::File::Stat).to receive(:owned?).and_return(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
context "instance methods" do
|
67
|
+
before do
|
68
|
+
@dbrc = described_class.new(db_foo, user1)
|
69
|
+
end
|
70
|
+
|
71
|
+
example "database method returns expected value" do
|
72
|
+
expect(@dbrc.database).to eq('foo')
|
73
|
+
end
|
74
|
+
|
75
|
+
example "password method returns expected value" do
|
76
|
+
expect(@dbrc.password).to eq('pwd1')
|
77
|
+
end
|
78
|
+
|
79
|
+
example "driver method returns expected value" do
|
80
|
+
expect(@dbrc.driver).to eq('Oracle')
|
81
|
+
end
|
82
|
+
|
83
|
+
example "interval method returns expected value" do
|
84
|
+
expect(@dbrc.interval).to eq(60)
|
85
|
+
end
|
86
|
+
|
87
|
+
example "timeout method returns expected value" do
|
88
|
+
expect(@dbrc.timeout).to eq(40)
|
89
|
+
end
|
90
|
+
|
91
|
+
example "maximum_reconnects method returns expected value" do
|
92
|
+
expect(@dbrc.maximum_reconnects).to eq(3)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,53 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbi-dbrc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.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
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
13
|
+
MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
|
14
14
|
cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
|
15
|
-
|
15
|
+
MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
|
16
16
|
ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
bTCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoCggGBALgfaroVM6CI06cxr0/h
|
18
|
+
A+j+pc8fgpRgBVmHFaFunq28GPC3IvW7Nvc3Y8SnAW7pP1EQIbhlwRIaQzJ93/yj
|
19
|
+
u95KpkP7tA9erypnV7dpzBkzNlX14ACaFD/6pHoXoe2ltBxk3CCyyzx70mTqJpph
|
20
|
+
75IB03ni9a8yqn8pmse+s83bFJOAqddSj009sGPcQO+QOWiNxqYv1n5EHcvj2ebO
|
21
|
+
6hN7YTmhx7aSia4qL/quc4DlIaGMWoAhvML7u1fmo53CYxkKskfN8MOecq2vfEmL
|
22
|
+
iLu+SsVVEAufMDDFMXMJlvDsviolUSGMSNRTujkyCcJoXKYYxZSNtIiyd9etI0X3
|
23
|
+
ctu0uhrFyrMZXCedutvXNjUolD5r9KGBFSWH1R9u2I3n3SAyFF2yzv/7idQHLJJq
|
24
|
+
74BMnx0FIq6fCpu5slAipvxZ3ZkZpEXZFr3cIBtO1gFvQWW7E/Y3ijliWJS1GQFq
|
25
|
+
058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
|
26
|
+
HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
|
27
|
+
AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
|
28
|
+
YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
|
29
|
+
/3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
|
30
|
+
h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
|
31
|
+
6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
|
32
|
+
ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
|
33
|
+
1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
|
34
|
+
DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
|
35
|
+
ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
|
36
|
+
WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
|
32
37
|
-----END CERTIFICATE-----
|
33
|
-
date:
|
38
|
+
date: 2021-06-19 00:00:00.000000000 Z
|
34
39
|
dependencies:
|
35
40
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
41
|
+
name: gpgme
|
37
42
|
requirement: !ruby/object:Gem::Requirement
|
38
43
|
requirements:
|
39
|
-
- - "
|
44
|
+
- - "~>"
|
40
45
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
46
|
+
version: '2.0'
|
42
47
|
type: :runtime
|
43
48
|
prerelease: false
|
44
49
|
version_requirements: !ruby/object:Gem::Requirement
|
45
50
|
requirements:
|
46
|
-
- - "
|
51
|
+
- - "~>"
|
47
52
|
- !ruby/object:Gem::Version
|
48
|
-
version: '0'
|
53
|
+
version: '2.0'
|
49
54
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
55
|
+
name: rake
|
51
56
|
requirement: !ruby/object:Gem::Requirement
|
52
57
|
requirements:
|
53
58
|
- - ">="
|
@@ -60,6 +65,34 @@ dependencies:
|
|
60
65
|
- - ">="
|
61
66
|
- !ruby/object:Gem::Version
|
62
67
|
version: '0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rspec
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.9'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.9'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: fakefs
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.3'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.3'
|
63
96
|
description: |2
|
64
97
|
The dbi-dbrc library provides an interface for storing database
|
65
98
|
connection information, including passwords, in a locally secure
|
@@ -72,29 +105,39 @@ description: |2
|
|
72
105
|
email: djberg96@gmail.com
|
73
106
|
executables: []
|
74
107
|
extensions: []
|
75
|
-
extra_rdoc_files:
|
76
|
-
- README
|
77
|
-
- CHANGES
|
78
|
-
- MANIFEST
|
108
|
+
extra_rdoc_files: []
|
79
109
|
files:
|
80
|
-
- CHANGES
|
81
|
-
-
|
82
|
-
-
|
110
|
+
- CHANGES.md
|
111
|
+
- Gemfile
|
112
|
+
- MANIFEST.md
|
113
|
+
- README.md
|
83
114
|
- Rakefile
|
84
115
|
- certs/djberg96_pub.pem
|
85
116
|
- dbi-dbrc.gemspec
|
86
117
|
- examples/plain/test.rb
|
87
118
|
- examples/xml/test_xml.rb
|
88
119
|
- examples/yml/test_yml.rb
|
120
|
+
- lib/dbi-dbrc.rb
|
89
121
|
- lib/dbi/dbrc.rb
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
122
|
+
- lib/dbi/dbrc/json.rb
|
123
|
+
- lib/dbi/dbrc/xml.rb
|
124
|
+
- lib/dbi/dbrc/yaml.rb
|
125
|
+
- spec/dbi_dbrc_json_spec.rb
|
126
|
+
- spec/dbi_dbrc_spec.rb
|
127
|
+
- spec/dbi_dbrc_xml_spec.rb
|
128
|
+
- spec/dbi_dbrc_yml_spec.rb
|
129
|
+
- spec/spec_helper.rb
|
93
130
|
homepage: https://github.com/djberg96/dbi-dbrc
|
94
131
|
licenses:
|
95
|
-
- Apache
|
96
|
-
metadata:
|
97
|
-
|
132
|
+
- Apache-2.0
|
133
|
+
metadata:
|
134
|
+
homepage_uri: https://github.com/djberg96/dbi-dbrc
|
135
|
+
bug_tracker_uri: https://github.com/djberg96/dbi-dbrc/issues
|
136
|
+
changelog_uri: https://github.com/djberg96/dbi-dbrc/blob/main/CHANGES.md
|
137
|
+
documentation_uri: https://github.com/djberg96/dbi-dbrc/wiki
|
138
|
+
source_code_uri: https://github.com/djberg96/dbi-dbrc
|
139
|
+
wiki_uri: https://github.com/djberg96/dbi-dbrc/wiki
|
140
|
+
post_install_message:
|
98
141
|
rdoc_options: []
|
99
142
|
require_paths:
|
100
143
|
- lib
|
@@ -109,12 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
152
|
- !ruby/object:Gem::Version
|
110
153
|
version: '0'
|
111
154
|
requirements: []
|
112
|
-
|
113
|
-
|
114
|
-
signing_key:
|
155
|
+
rubygems_version: 3.2.15
|
156
|
+
signing_key:
|
115
157
|
specification_version: 4
|
116
158
|
summary: A simple way to avoid hard-coding passwords with DBI
|
117
|
-
test_files:
|
118
|
-
- test/test_dbi_dbrc.rb
|
119
|
-
- test/test_dbi_dbrc_xml.rb
|
120
|
-
- test/test_dbi_dbrc_yml.rb
|
159
|
+
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|
data/README
DELETED
@@ -1,260 +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
|
-
* sys-admin
|
9
|
-
* win32-file-attributes (MS Windows only)
|
10
|
-
* win32-dir (MS Windows only)
|
11
|
-
* win32-process (MS Windows only)
|
12
|
-
|
13
|
-
== Installation
|
14
|
-
gem install dbi-dbrc
|
15
|
-
|
16
|
-
== Synopsis
|
17
|
-
require 'dbi/dbrc'
|
18
|
-
include DBI
|
19
|
-
|
20
|
-
dbrc = DBRC.new('mydb')
|
21
|
-
|
22
|
-
or
|
23
|
-
|
24
|
-
dbrc = DBRC.new('mydb', 'someUser')
|
25
|
-
|
26
|
-
puts dbrc.db
|
27
|
-
puts dbrc.user
|
28
|
-
puts dbrc.driver
|
29
|
-
puts dbrc.timeout
|
30
|
-
puts dbrc.max_reconn
|
31
|
-
puts dbrc.interval
|
32
|
-
puts dbrc.dsn
|
33
|
-
|
34
|
-
== Notes on the .dbrc file
|
35
|
-
This module relies on a file in your home directory called ".dbrc", and it
|
36
|
-
is meant to be analogous to the ".netrc" file used by programs such as
|
37
|
-
telnet. The .dbrc file has several conditions that must be met by the
|
38
|
-
module or it will fail:
|
39
|
-
|
40
|
-
* Permissions must be set to 600 (Unix only).
|
41
|
-
* Must be hidden (MS Windows only).
|
42
|
-
* Must be owned by the current user.
|
43
|
-
* Must have database, user and password. Other fields are optional.
|
44
|
-
* Must be in the following space-separated format (in the 'plain' version):
|
45
|
-
|
46
|
-
database user password driver timeout maximum_reconnects interval
|
47
|
-
|
48
|
-
e.g. mydb dan mypass oracle 10 2 30
|
49
|
-
|
50
|
-
You may include comments in the .dbrc file by starting the line with a
|
51
|
-
"#" symbol.
|
52
|
-
|
53
|
-
A failure in any of the rules mentioned above will result in a DBRC::Error
|
54
|
-
being raised. In addition, the file may also be encrypted on MS Windows
|
55
|
-
systems, in which case the file will automatically be (temporarily)
|
56
|
-
decrypted.
|
57
|
-
|
58
|
-
The format for XML (using the example above) is as follows:
|
59
|
-
|
60
|
-
<dbrc>
|
61
|
-
<database name="mydb">
|
62
|
-
<user>dan</user>
|
63
|
-
<password>mypass</password>
|
64
|
-
<driver>oracle</driver>
|
65
|
-
<interval>30</interval>
|
66
|
-
<timeout>10</timeout>
|
67
|
-
<maximum_reconnects>2</maximum_reconnects>
|
68
|
-
</database>
|
69
|
-
</dbrc>
|
70
|
-
|
71
|
-
The format for YAML is as follows:
|
72
|
-
|
73
|
-
- mydb:
|
74
|
-
user: dan
|
75
|
-
password: mypass
|
76
|
-
driver: oracle
|
77
|
-
interval: 30
|
78
|
-
timeout: 10
|
79
|
-
max_reconn: 2
|
80
|
-
|
81
|
-
== Constants
|
82
|
-
VERSION
|
83
|
-
The current version of this library, returned as a String.
|
84
|
-
|
85
|
-
== Class Methods
|
86
|
-
DBRC.new(db, user=nil, dir=nil)
|
87
|
-
The constructor takes one to three arguments. The first argument is the
|
88
|
-
database name. This *must* be provided. If only the database name is
|
89
|
-
passed, the module will look for the first database entry in the .dbrc
|
90
|
-
file that matches.
|
91
|
-
|
92
|
-
The second argument, a user name, is optional. If it is passed, the
|
93
|
-
module will look for the first entry in the .dbrc file where both the
|
94
|
-
database *and* user name match.
|
95
|
-
|
96
|
-
The third argument, also optional, specifies the directory where DBRC will
|
97
|
-
look for the .dbrc file. By default, it looks in the pwuid (present
|
98
|
-
working user id) home directory. The rules for a .dbrc file still apply.
|
99
|
-
|
100
|
-
MS Windows users should read the "Notes" section for how your home directory
|
101
|
-
is determined.
|
102
|
-
|
103
|
-
== Instance Methods
|
104
|
-
DBRC#database
|
105
|
-
The name of the database. Note that the same entry can appear more than
|
106
|
-
once, presumably because you have multiple user id's for the same
|
107
|
-
database.
|
108
|
-
|
109
|
-
DBRC#db
|
110
|
-
An alias for DBRC#database.
|
111
|
-
|
112
|
-
DBRC#database=(database)
|
113
|
-
Sets the database to +database+. This is generally discouraged because
|
114
|
-
it does not automatically reset the dsn.
|
115
|
-
|
116
|
-
DBRC#db=(database)
|
117
|
-
An alias for DBRC#database=.
|
118
|
-
|
119
|
-
DBRC#user
|
120
|
-
A valid user name for that database.
|
121
|
-
|
122
|
-
DBRC#user=(user)
|
123
|
-
Sets the user name to +user+.
|
124
|
-
|
125
|
-
DBRC#password
|
126
|
-
The password for that user.
|
127
|
-
|
128
|
-
DBRC#passwd
|
129
|
-
An alias for DBRC#password.
|
130
|
-
|
131
|
-
DBRC#password=(password)
|
132
|
-
Sets the password to +password+.
|
133
|
-
|
134
|
-
DBRC#passwd=(password)
|
135
|
-
An alias for DBRC#password=.
|
136
|
-
|
137
|
-
DBRC#driver
|
138
|
-
The driver type for that database (Oracle, MySql, etc).
|
139
|
-
|
140
|
-
DBRC#driver=(driver)
|
141
|
-
Sets the driver to +driver+. This use is discouraged because it does
|
142
|
-
not reset the dsn.
|
143
|
-
|
144
|
-
DBRC#timeout
|
145
|
-
The timeout period for a connection before the attempt is dropped.
|
146
|
-
|
147
|
-
DBRC#time_out
|
148
|
-
An alias for DBRC#timeout, provided purely for the sake of backwards
|
149
|
-
compatability.
|
150
|
-
|
151
|
-
DBRC#timeout=(int)
|
152
|
-
Sets the timeout value to +int+.
|
153
|
-
|
154
|
-
DBRC#maximum_reconnects
|
155
|
-
The maximum number of reconnect attempts that should be made for the the
|
156
|
-
database. Presumablly, you would use this with a "retry" within a rescue
|
157
|
-
block.
|
158
|
-
|
159
|
-
DBRC#max_reconn
|
160
|
-
An alias for DBRC#maximum_reconnects.
|
161
|
-
|
162
|
-
DBRC#maximum_reconnects=(max)
|
163
|
-
Sets the maximum number of reconnect attempts to +max+.
|
164
|
-
|
165
|
-
DBRC#max_reconn=(max)
|
166
|
-
An alias for DBRC#maximum_reconnects.
|
167
|
-
|
168
|
-
DBRC#interval
|
169
|
-
The number of seconds to wait before attempting to reconnect to the database
|
170
|
-
again should a network/database glitch occur.
|
171
|
-
|
172
|
-
DBRC#interval=(int)
|
173
|
-
Sets the interval seconds between connection attempts.
|
174
|
-
|
175
|
-
DBRC#dsn
|
176
|
-
Returns a string in "dbi:<driver>:<database>" format.
|
177
|
-
|
178
|
-
DBRC#dsn=(dsn)
|
179
|
-
Sets the dsn string to +dsn+. This method is discouraged because it does
|
180
|
-
not automatically reset the driver or database.
|
181
|
-
|
182
|
-
== Canonical Example
|
183
|
-
# This is a basic template for how I do things:
|
184
|
-
|
185
|
-
require 'dbi/dbrc'
|
186
|
-
require 'timeout'
|
187
|
-
|
188
|
-
db = DBI::DBRC.new("somedb")
|
189
|
-
n = db.max_reconn
|
190
|
-
|
191
|
-
begin
|
192
|
-
Timeout.timeout(db.timeout){
|
193
|
-
DBI.connect(db.dsn, db.user, db.passwd)
|
194
|
-
}
|
195
|
-
rescue DBI::Error
|
196
|
-
n -= 1
|
197
|
-
if n > 0
|
198
|
-
sleep db.interval
|
199
|
-
retry
|
200
|
-
end
|
201
|
-
raise
|
202
|
-
rescue TimeoutError
|
203
|
-
# handle timeout error
|
204
|
-
end
|
205
|
-
|
206
|
-
== Notes for MS Windows Users
|
207
|
-
The 'home' directory for Win32 users is determined by ENV['USERPROFILE'].
|
208
|
-
If that is not set, ENV['HOME'] is used. If that is not set, then
|
209
|
-
the directory found by the sys-admin library is used.
|
210
|
-
|
211
|
-
To make your file hidden, right click on the .dbrc file in your Explorer
|
212
|
-
window, select "Properties" and check the "Hidden" checkbox.
|
213
|
-
|
214
|
-
I was going to require that the .dbrc file be encrypted on MS Windows,
|
215
|
-
but that may require an official "certificate", assigned to you by a third
|
216
|
-
party, which is a bit much to expect. However, if the file is encrypted,
|
217
|
-
DBRC will attempt to decrypt it, parse it, and encrypt it again when done
|
218
|
-
parsing.
|
219
|
-
|
220
|
-
== Notes on running the test suite
|
221
|
-
I cannot guarantee that the .dbrc files under the +examples+
|
222
|
-
subdirectories maintain the appropriate properties. This can cause
|
223
|
-
failures for the test suite (which uses these files).
|
224
|
-
|
225
|
-
The only solution is to perform a 'chmod 600 .dbrc' (on Unix) or set
|
226
|
-
the properties to 'hidden' (on MS Windows) manually, for the file in
|
227
|
-
question.
|
228
|
-
|
229
|
-
== Summary
|
230
|
-
These "methods" don't really do anything. They're simply meant as a
|
231
|
-
convenience mechanism for you dbi connections, plus a little bit of
|
232
|
-
obfuscation (for passwords).
|
233
|
-
|
234
|
-
== Adding your own configuration
|
235
|
-
If you want to add your own type of configuration file, you can still use
|
236
|
-
the dbi-dbrc library. All you need to do is:
|
237
|
-
|
238
|
-
* subclass DBRC
|
239
|
-
* redefine the +parse_dbrc_config_file+ method (a private method).
|
240
|
-
|
241
|
-
Take a look at the XML and YML subclasses in dbrc.rb for two examples that
|
242
|
-
you can work from.
|
243
|
-
|
244
|
-
== Future Plans
|
245
|
-
Add DBI::DBRC::JSON.
|
246
|
-
|
247
|
-
== Known Bugs
|
248
|
-
I'm not positive about the dsn strings for databases other than Oracle.
|
249
|
-
If it's not correct, please let me know.
|
250
|
-
|
251
|
-
== Copyright
|
252
|
-
(C) Copyright 2002-2014, Daniel J. Berger, all rights reserved.
|
253
|
-
|
254
|
-
= Warranty
|
255
|
-
This package is provided "as is" and without any express or
|
256
|
-
implied warranties, including, without limitation, the implied
|
257
|
-
warranties of merchantability and fitness for a particular purpose
|
258
|
-
|
259
|
-
== Author
|
260
|
-
Daniel J. Berger
|