dbi-dbrc 1.1.3-x86-mswin32-60 → 1.1.6-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,21 @@
1
+ == 1.1.6 - 10-Sep-2009
2
+ * Fixed validation for dbrc_dir argument.
3
+ * Added a test for bogus dbrc_dir arguments.
4
+
5
+ == 1.1.5 - 3-Sep-2009
6
+ * License changed to Artistic 2.0.
7
+ * Some gemspec updates, including the license and description.
8
+ * Renamed the test files. The ts_all.rb file was removed.
9
+ * Added win32-process as a dependency on MS Windows.
10
+ * Added test-unit as a development dependency. Some tests were refactored
11
+ to use features from test-unit 2.x.
12
+ * Added the 'test_xml' and 'test_yml' rake tasks.
13
+ * Refactored the main test task.
14
+ * Added explicit copyright and warranty to the README file.
15
+
16
+ == 1.1.4 - 10-Nov-2008
17
+ * Added a custom inspect method which filters the password.
18
+
1
19
  == 1.1.3 - 21-Jul-2008
2
20
  * More RUBY_PLATFORM changes that I missed in the last release.
3
21
  * Added inline RDOC for the accessors and updated the documentation
data/MANIFEST CHANGED
@@ -10,7 +10,6 @@
10
10
  * examples/xml_examples/test_xml.rb
11
11
  * examples/yml_examples/.dbrc
12
12
  * examples/yml_examples/test_yml.rb
13
- * test/ts_all.rb
14
- * test/tc_dbrc.rb
15
- * test/tc_dbrc_xml.rb
16
- * test/tc_dbrc_yml.rb
13
+ * test/test_dbi_dbrc.rb
14
+ * test/test_dbi_dbrc_xml.rb
15
+ * test/test_dbi_dbrc_yml.rb
data/README CHANGED
@@ -242,11 +242,20 @@ DBRC#dsn=(dsn)
242
242
  Take a look at the XML and YML subclasses in dbrc.rb for two examples that
243
243
  you can work from.
244
244
 
245
+ == Future Plans
246
+ Add DBI::DBRC::JSON.
247
+
245
248
  == Known Bugs
246
249
  I'm not positive about the dsn strings for databases other than Oracle.
247
250
  If it's not correct, please let me know.
248
251
 
252
+ == Copyright
253
+ (C) Copyright 2002-2009, Daniel J. Berger, all rights reserved.
254
+
255
+ = Warranty
256
+ This package is provided "as is" and without any express or
257
+ implied warranties, including, without limitation, the implied
258
+ warranties of merchantability and fitness for a particular purpose
259
+
249
260
  == Author
250
261
  Daniel J. Berger
251
- djberg96 at nospam at gmail dot com
252
- imperator on IRC (irc.freenode.net)
data/Rakefile ADDED
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ desc "Install the dbi-dbrc package (non-gem)"
5
+ task :install do
6
+ dest = File.join(Config::CONFIG['sitelibdir'], 'dbi')
7
+ Dir.mkdir(dest) unless File.exists? dest
8
+ cp 'lib/dbi/dbrc.rb', dest, :verbose => true
9
+ end
10
+
11
+ desc "Install the dbi-dbrc package as a gem"
12
+ task :install_gem do
13
+ ruby 'dbi-dbrc.gemspec'
14
+ file = Dir["*.gem"].first
15
+ sh "gem install #{file}"
16
+ end
17
+
18
+ Rake::TestTask.new do |t|
19
+ t.warning = true
20
+ t.verbose = true
21
+ end
22
+
23
+ Rake::TestTask.new(:test_xml) do |t|
24
+ t.warning = true
25
+ t.verbose = true
26
+ t.test_files = FileList['test/test_dbi_dbrc_xml.rb']
27
+ end
28
+
29
+ Rake::TestTask.new(:test_yml) do |t|
30
+ t.warning = true
31
+ t.verbose = true
32
+ t.test_files = FileList['test/test_dbi_dbrc_yml.rb']
33
+ end
data/dbi-dbrc.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ require 'rubygems'
2
+
3
+ spec = Gem::Specification.new do |s|
4
+ s.name = 'dbi-dbrc'
5
+ s.version = '1.1.6'
6
+ s.author = 'Daniel Berger'
7
+ s.email = 'djberg96@gmail.com'
8
+ s.license = 'Artistic 2.0'
9
+ s.summary = 'A simple way to avoid hard-coding passwords with DBI'
10
+ s.homepage = 'http://www.rubyforge.org/projects/shards'
11
+ s.platform = Gem::Platform::RUBY
12
+ s.files = Dir['**/*'].reject{ |f| f.include?('CVS') }
13
+ s.test_files = Dir['test/test*.rb']
14
+ s.has_rdoc = true
15
+
16
+ s.extra_rdoc_files = ['README', 'CHANGES', 'MANIFEST']
17
+ s.rubyforge_project = 'shards'
18
+
19
+ s.add_dependency('sys-admin', '>= 1.5.2')
20
+ s.add_development_dependency('test-unit')
21
+
22
+ if Config::CONFIG['host_os'] =~ /mswin|win32|dos/i
23
+ s.add_dependency('win32-file', '>= 0.4.2')
24
+ s.add_dependency('win32-dir', '>= 0.3.0')
25
+ s.add_dependency('win32-process', '>= 0.6.1')
26
+ s.platform = Gem::Platform::CURRENT
27
+ end
28
+
29
+ s.description = <<-EOF
30
+ The dbi-dbrc library provides an interface for storing database
31
+ connection information, including passwords, in a locally secure
32
+ file only accessible by you, or root. This allows you to avoid
33
+ hard coding login and password information in your programs
34
+ that require such information.
35
+
36
+ This library can also be used to store login and password information
37
+ for logins on remote hosts, not just databases.
38
+ EOF
39
+ end
40
+
41
+ Gem::Builder.new(spec).build
data/lib/dbi/dbrc.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'rbconfig'
2
2
 
3
- if Config::CONFIG['host_os'].match('mswin')
3
+ if Config::CONFIG['host_os'] =~ /mswin|win32|dos/i
4
4
  require 'win32/file'
5
5
  require 'win32/dir'
6
+ require 'win32/process'
6
7
  end
7
8
 
8
9
  require 'sys/admin'
@@ -14,11 +15,12 @@ module DBI
14
15
  class DBRC
15
16
 
16
17
  # This error is raised if anything fails trying to read the config file.
17
- # the error that is raised.
18
18
  class Error < StandardError; end
19
19
 
20
- # The version of this library
21
- VERSION = '1.1.3'
20
+ # The version of the dbi-dbrc library
21
+ VERSION = '1.1.6'
22
+
23
+ @@windows = Config::CONFIG['host_os'] =~ /mswin|win32|dos/i
22
24
 
23
25
  # The database or host to be connected to.
24
26
  attr_accessor :database
@@ -86,24 +88,26 @@ module DBI
86
88
  #
87
89
  def initialize(database, user=nil, dbrc_dir=nil)
88
90
  if dbrc_dir.nil?
89
- if Config::CONFIG['host_os'].match('mswin')
90
- home = ENV['USERPROFILE'] || ENV['HOME']
91
- file = nil
92
-
93
- if home
94
- file = File.join(home, '.dbrc')
91
+ uid = Process.uid
92
+ home = ENV['HOME'] || ENV['USERPROFILE']
93
+
94
+ if home.nil?
95
+ if @@windows
96
+ home ||= Sys::Admin.get_user(uid, :localaccount => true).dir
95
97
  else
96
- file = File.join(File.basename(Dir::APPDATA), '.dbrc')
98
+ home ||= Sys::Admin.get_user(uid).dir
97
99
  end
98
-
99
- @dbrc_file = file
100
+ end
101
+
102
+ # Default to the app data directory on Windows if no home dir found
103
+ if @@windows && home.nil?
104
+ @dbrc_file = File.join(File.basename(Dir::APPDATA), '.dbrc')
100
105
  else
101
- @dbrc_file = File.join(
102
- Sys::Admin.get_user(Process.uid).dir,
103
- '.dbrc'
104
- )
106
+ uid = Process.uid
107
+ @dbrc_file = File.join(Sys::Admin.get_user(uid).dir, '.dbrc')
105
108
  end
106
109
  else
110
+ raise Error, 'bad directory' unless File.directory?(dbrc_dir)
107
111
  @dbrc_file = File.join(dbrc_dir, '.dbrc')
108
112
  end
109
113
 
@@ -120,7 +124,7 @@ module DBI
120
124
  check_file()
121
125
 
122
126
  # If on Win32 and the file is encrypted, decrypt it.
123
- if Config::CONFIG['host_os'].match("mswin") && File.encrypted?(@dbrc_file)
127
+ if @@windows && File.encrypted?(@dbrc_file)
124
128
  encrypted = true
125
129
  File.decrypt(@dbrc_file)
126
130
  end
@@ -131,11 +135,26 @@ module DBI
131
135
  create_dsn_string()
132
136
 
133
137
  # If on Win32 and the file was encrypted, re-encrypt it
134
- if Config::CONFIG['host_os'].match("mswin") && encrypted
138
+ if @@windows && encrypted
135
139
  File.encrypt(@dbrc_file)
136
140
  end
137
141
  end
138
142
 
143
+ # Inspection of the DBI::DBRC object. This is identical to the standard
144
+ # Ruby Object#inspect, except that the password field is filtered.
145
+ #
146
+ def inspect
147
+ str = instance_variables.map{ |iv|
148
+ if iv == '@password'
149
+ "#{iv}=[FILTERED]"
150
+ else
151
+ "#{iv}=#{instance_variable_get(iv).inspect}"
152
+ end
153
+ }.join(', ')
154
+
155
+ "#<#{self.class}:0x#{(self.object_id*2).to_s(16)} " << str << ">"
156
+ end
157
+
139
158
  private
140
159
 
141
160
  # Ensure that the user/password has been set
@@ -167,7 +186,7 @@ module DBI
167
186
 
168
187
  # Permissions must be set to 600 or better on Unix systems.
169
188
  # Must be hidden on Win32 systems.
170
- if Config::CONFIG['host_os'].match("mswin")
189
+ if @@windows
171
190
  unless File.hidden?(file)
172
191
  raise Error, "The .dbrc file must be hidden"
173
192
  end
@@ -1,27 +1,32 @@
1
1
  #########################################################################
2
- # tc_dbrc.rb
2
+ # test_dbi_dbrc.rb
3
3
  #
4
4
  # Test suite for the base class of DBI::DBRC. This test case should be
5
5
  # run via the 'rake test' task.
6
6
  #########################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
7
10
  require 'dbi/dbrc'
8
11
  require 'test/unit'
9
12
  include DBI
10
13
 
11
- class TC_DBRC < Test::Unit::TestCase
12
- def setup
13
- Dir.chdir('test') if File.basename(Dir.pwd) != 'test'
14
+ class TC_DBI_DBRC < Test::Unit::TestCase
15
+ def self.startup
16
+ @@windows = File::ALT_SEPARATOR
17
+ end
14
18
 
15
- @dir = "../examples/plain"
19
+ def setup
20
+ @dir = File.join(Dir.pwd, 'examples/plain')
16
21
  @file = File.join(@dir, '.dbrc')
17
- @db1 = "foo"
18
- @db2 = "bar"
19
- @user1 = "user1"
20
- @user2 = "user2"
21
- @db_bad = "blah" # Doesn't exist
22
- @user_bad = "user8" # Doesn't exist
22
+ @db1 = 'foo'
23
+ @db2 = 'bar'
24
+ @user1 = 'user1'
25
+ @user2 = 'user2'
26
+ @db_bad = 'blah' # Doesn't exist
27
+ @user_bad = 'user8' # Doesn't exist
23
28
 
24
- if File::ALT_SEPARATOR
29
+ if @@windows && File.respond_to?(:set_attr)
25
30
  File.set_attr(@file, File::HIDDEN)
26
31
  else
27
32
  File.chmod(0600, @file)
@@ -31,11 +36,11 @@ class TC_DBRC < Test::Unit::TestCase
31
36
  end
32
37
 
33
38
  def test_version
34
- assert_equal("1.1.3", DBRC::VERSION)
39
+ assert_equal('1.1.6', DBRC::VERSION)
35
40
  end
36
41
 
37
42
  def test_bad_dbrc_properties
38
- if File::ALT_SEPARATOR
43
+ if @@windows
39
44
  File.unset_attr(@file, File::HIDDEN)
40
45
  assert_raises(DBRC::Error){ DBRC.new(@db1, @user1, @dir) }
41
46
  else
@@ -51,11 +56,15 @@ class TC_DBRC < Test::Unit::TestCase
51
56
  end
52
57
 
53
58
  def test_bad_database
54
- assert_raises(DBRC::Error){ DBRC.new(@db_bad, nil, @dir) }
59
+ assert_raise(DBRC::Error){ DBRC.new(@db_bad, nil, @dir) }
55
60
  end
56
61
 
57
62
  def test_bad_user
58
- assert_raises(DBRC::Error){ DBRC.new(@db1, @user_bad, @dir) }
63
+ assert_raise(DBRC::Error){ DBRC.new(@db1, @user_bad, @dir) }
64
+ end
65
+
66
+ def test_bad_dir
67
+ assert_raise(DBI::DBRC::Error){ DBI::DBRC.new(@db1, @user1, '/bogusXX') }
59
68
  end
60
69
 
61
70
  def test_database
@@ -184,10 +193,9 @@ class TC_DBRC < Test::Unit::TestCase
184
193
  @db_bad = nil
185
194
  @user_bad = nil
186
195
  @dbrc = nil
187
- if File::ALT_SEPARATOR
188
- File.set_attr(@file, File::HIDDEN)
189
- else
190
- File.chmod(0600, @file)
191
- end
196
+ end
197
+
198
+ def self.shutdown
199
+ @@windows = nil
192
200
  end
193
201
  end
@@ -1,20 +1,22 @@
1
1
  ########################################################################
2
- # tc_dbrc_xml.rb
2
+ # test_dbi_dbrc_xml.rb
3
3
  #
4
4
  # Test suite for the XML specific version of DBI::DBRC. This test case
5
5
  # should be run via the 'rake test' task.
6
6
  ########################################################################
7
- require "dbi/dbrc"
8
- require "test/unit"
9
- require "rexml/document"
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'dbi/dbrc'
11
+ require 'test/unit'
12
+ require 'rexml/document'
10
13
  include REXML
11
14
  include DBI
12
15
 
13
- class TC_DBRC_XML < Test::Unit::TestCase
16
+ class TC_DBI_DBRC_XML < Test::Unit::TestCase
14
17
  def setup
15
- Dir.chdir('test') if File.basename(Dir.pwd) != 'test'
16
- @dir = "../examples/xml"
17
- @file = File.join(@dir, ".dbrc")
18
+ @dir = File.join(Dir.pwd, 'examples/xml')
19
+ @file = File.join(@dir, '.dbrc')
18
20
  @db1 = "foo"
19
21
  @db2 = "bar"
20
22
  @user1 = "user1"
@@ -22,7 +24,7 @@ class TC_DBRC_XML < Test::Unit::TestCase
22
24
  @db_bad = "blah" # Doesn't exist
23
25
  @user_bad = "user8" # Doesn't exist
24
26
 
25
- if File::ALT_SEPARATOR
27
+ if File::ALT_SEPARATOR && File.respond_to?(:set_attr)
26
28
  File.set_attr(@file, File::HIDDEN)
27
29
  else
28
30
  File.chmod(0600, @file)
@@ -1,18 +1,19 @@
1
1
  #########################################################################
2
- # tc_dbrc_yml.rb
2
+ # test_dbi_dbrc_yml.rb
3
3
  #
4
4
  # Test suite for the YAML specific version of DBI::DBRC. You should run
5
5
  # this test case via the 'rake test' task.
6
6
  #########################################################################
7
- require "dbi/dbrc"
8
- require "test/unit"
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
10
+ require 'dbi/dbrc'
11
+ require 'test/unit'
9
12
  include DBI
10
13
 
11
- class TC_DBRC_YML < Test::Unit::TestCase
14
+ class TC_DBI_DBRC_YML < Test::Unit::TestCase
12
15
  def setup
13
- Dir.chdir('test') if File.basename(Dir.pwd) != 'test'
14
-
15
- @dir = "../examples/yml"
16
+ @dir = File.join(Dir.pwd, 'examples/yml')
16
17
  @file = File.join(@dir, '.dbrc')
17
18
  @db1 = "foo"
18
19
  @db2 = "bar"
@@ -21,7 +22,7 @@ class TC_DBRC_YML < Test::Unit::TestCase
21
22
  @db_bad = "blah" # Doesn't exist
22
23
  @user_bad = "user8" # Doesn't exist
23
24
 
24
- if File::ALT_SEPARATOR
25
+ if File::ALT_SEPARATOR && File.respond_to?(:set_attr)
25
26
  File.set_attr(@file, File::HIDDEN)
26
27
  else
27
28
  File.chmod(0600, @file)
@@ -155,11 +156,5 @@ class TC_DBRC_YML < Test::Unit::TestCase
155
156
  @db_bad = nil
156
157
  @user_bad = nil
157
158
  @dbrc = nil
158
-
159
- if File::ALT_SEPARATOR
160
- File.set_attr(@file, File::HIDDEN)
161
- else
162
- File.chmod(0600, @file)
163
- end
164
159
  end
165
160
  end
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.3
4
+ version: 1.1.6
5
5
  platform: x86-mswin32-60
6
6
  authors:
7
7
  - Daniel Berger
@@ -9,13 +9,23 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-21 00:00:00 -06:00
12
+ date: 2009-09-10 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sys-admin
17
17
  type: :runtime
18
18
  version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.5.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: test-unit
27
+ type: :development
28
+ version_requirement:
19
29
  version_requirements: !ruby/object:Gem::Requirement
20
30
  requirements:
21
31
  - - ">="
@@ -42,7 +52,17 @@ dependencies:
42
52
  - !ruby/object:Gem::Version
43
53
  version: 0.3.0
44
54
  version:
45
- description: A simple way to avoid hard-coding passwords with DBI
55
+ - !ruby/object:Gem::Dependency
56
+ name: win32-process
57
+ type: :runtime
58
+ version_requirement:
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: 0.6.1
64
+ version:
65
+ description: " The dbi-dbrc library provides an interface for storing database\n connection information, including passwords, in a locally secure\n file only accessible by you, or root. This allows you to avoid\n hard coding login and password information in your programs\n that require such information.\n\n This library can also be used to store login and password information\n for logins on remote hosts, not just databases.\n"
46
66
  email: djberg96@gmail.com
47
67
  executables: []
48
68
 
@@ -53,23 +73,22 @@ extra_rdoc_files:
53
73
  - CHANGES
54
74
  - MANIFEST
55
75
  files:
56
- - examples/plain
76
+ - CHANGES
77
+ - dbi-dbrc.gemspec
57
78
  - examples/plain/test.rb
58
- - examples/xml
59
79
  - examples/xml/test_xml.rb
60
- - examples/yml
61
80
  - examples/yml/test_yml.rb
62
- - lib/dbi
63
81
  - lib/dbi/dbrc.rb
64
- - test/tc_dbrc.rb
65
- - test/tc_dbrc_xml.rb
66
- - test/tc_dbrc_yml.rb
67
- - test/ts_all.rb
68
- - README
69
- - CHANGES
70
82
  - MANIFEST
83
+ - Rakefile
84
+ - README
85
+ - test/test_dbi_dbrc.rb
86
+ - test/test_dbi_dbrc_xml.rb
87
+ - test/test_dbi_dbrc_yml.rb
71
88
  has_rdoc: true
72
89
  homepage: http://www.rubyforge.org/projects/shards
90
+ licenses:
91
+ - Artistic 2.0
73
92
  post_install_message:
74
93
  rdoc_options: []
75
94
 
@@ -90,9 +109,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
109
  requirements: []
91
110
 
92
111
  rubyforge_project: shards
93
- rubygems_version: 1.2.0
112
+ rubygems_version: 1.3.5
94
113
  signing_key:
95
- specification_version: 2
114
+ specification_version: 3
96
115
  summary: A simple way to avoid hard-coding passwords with DBI
97
116
  test_files:
98
- - test/ts_all.rb
117
+ - test/test_dbi_dbrc.rb
118
+ - test/test_dbi_dbrc_xml.rb
119
+ - test/test_dbi_dbrc_yml.rb
data/test/ts_all.rb DELETED
@@ -1,6 +0,0 @@
1
- $LOAD_PATH.unshift(Dir.pwd)
2
- $LOAD_PATH.unshift(Dir.pwd + "/test")
3
-
4
- require "tc_dbrc"
5
- require "tc_dbrc_yml"
6
- require "tc_dbrc_xml"