netrc 0.7.7 → 0.7.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTNhNjdkNGMxODcwZjcxMzMxYTkwMzRmN2U4M2YyZGFlNGZmNDI2OQ==
5
+ data.tar.gz: !binary |-
6
+ MmQ3MTBiNjMzNjEyOWIzNmM4OTM3ZWZhOTVlMDRiMTNlOThiYmZlNA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjY4ZWNjZTQ4MWJmN2U2MTUwOThjNDAxMDNmMDJjNWJjYjM5YTAwZWMzYTZj
10
+ MGMzZmNkNWEwMTAwNGEzYTRjNzU0ZTVjMTQ4ZTJjZDJmNzY4ZWVlYWI3NDgz
11
+ YTBjMTU0MWRjNWFmZjExZTIyY2IxMDQ1YWViNWU4YzE0NzZjYTM=
12
+ data.tar.gz: !binary |-
13
+ YzQ3OWJkMzhhODUyZGQwMDA5NDgzMTQ1ODFiMTFiZmJlOTFhNTFmYWZiNmFi
14
+ MGY3MTQ0Nzg1MzM3MDhjODdmOTZiM2Q3ZjYxNWMyZTlhNjJjZTU0Y2JhMDNj
15
+ ZjJkMTM3ZjM5OTM2MzE0OWM4Mjk0MWQ3MWQ3YjQ5ZDBmMWE1NmQ=
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2011-2014 [CONTRIBUTORS.md](https://github.com/geemus/netrc/blob/master/CONTRIBUTORS.md)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Readme.md CHANGED
@@ -18,6 +18,12 @@ Read the user's default netrc file (`$HOME/.netrc` on Unix;
18
18
 
19
19
  n = Netrc.read
20
20
 
21
+ Configure netrc to allow permissive files (with permissions other than 0600):
22
+
23
+ Netrc.configure do |config|
24
+ config[:allow_permissive_netrc_file] = true
25
+ end
26
+
21
27
  Look up a username and password:
22
28
 
23
29
  user, pass = n["example.com"]
@@ -1,3 +1,15 @@
1
+ 0.7.8 10/15/14
2
+ ==============
3
+
4
+ add entry class to facilitate usage
5
+ switch gem source to rubygems.org
6
+ use guard, when available via guardfile
7
+ add default/read-only behavior
8
+ add allow_permissive_netrc_file option
9
+ fix an undefined variable path
10
+ fix Errno::EACCES error
11
+ silence const warnings in test
12
+
1
13
  0.7.7 08/15/12
2
14
  ==============
3
15
 
@@ -0,0 +1,4 @@
1
+ # this is my netrc with only a default
2
+ default
3
+ login ld # this is my default username
4
+ password pd
@@ -0,0 +1,8 @@
1
+ # this is my netrc with multiple machines
2
+ machine m
3
+ login lm # this is my m-username
4
+ password pm
5
+
6
+ machine n
7
+ login ln # this is my n-username
8
+ password pn
@@ -0,0 +1,12 @@
1
+ # this is my netrc with multiple machines and a default
2
+ machine m
3
+ login lm # this is my m-username
4
+ password pm
5
+
6
+ machine n
7
+ login ln # this is my n-username
8
+ password pn
9
+
10
+ default
11
+ login ld # this is my default username
12
+ password pd
@@ -0,0 +1,8 @@
1
+ # this is my netrc with default
2
+ machine m
3
+ login l # this is my username
4
+ password p
5
+
6
+ default
7
+ login default_login # this is my default username
8
+ password default_password
@@ -1,7 +1,7 @@
1
1
  require 'rbconfig'
2
2
 
3
3
  class Netrc
4
- VERSION = "0.7.7"
4
+ VERSION = "0.7.8"
5
5
 
6
6
  # see http://stackoverflow.com/questions/4871309/what-is-the-correct-way-to-detect-if-ruby-is-running-on-windows
7
7
  WINDOWS = RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
@@ -11,13 +11,25 @@ class Netrc
11
11
  if WINDOWS && !CYGWIN
12
12
  File.join(ENV['USERPROFILE'].gsub("\\","/"), "_netrc")
13
13
  else
14
- File.join((ENV["HOME"] || "./"), ".netrc")
14
+ # In some cases, people run master process as "root" user, and run worker processes as "www" user.
15
+ # Fix "Permission denied" error in worker processes when $HOME is "/root".
16
+ default_dir = (ENV['HOME'] && File.exists?(ENV['HOME']) && File.stat(ENV['HOME']).readable?) ? ENV['HOME'] : './'
17
+ File.join(default_dir, ".netrc")
15
18
  end
16
19
  end
17
20
 
21
+ def self.config
22
+ @config ||= {}
23
+ end
24
+
25
+ def self.configure
26
+ yield(self.config) if block_given?
27
+ self.config
28
+ end
29
+
18
30
  def self.check_permissions(path)
19
31
  perm = File.stat(path).mode & 0777
20
- if perm != 0600 && !(WINDOWS)
32
+ if perm != 0600 && !(WINDOWS) && !(Netrc.config[:allow_permissive_netrc_file])
21
33
  raise Error, "Permission bits for '#{path}' should be 0600, but are "+perm.to_s(8)
22
34
  end
23
35
  end
@@ -101,19 +113,29 @@ class Netrc
101
113
  return l.join
102
114
  end
103
115
 
104
- pre = ts.readto{|t| t == "machine"}
116
+ pre = ts.readto{|t| t == "machine" || t == "default"}
117
+
105
118
  while ts.length > 0
106
- cur << ts.take + ts.readto{|t| ! skip?(t)}
107
- cur << ts.take
119
+ if ts[0] == 'default'
120
+ cur << ts.take.to_sym
121
+ cur << ''
122
+ else
123
+ cur << ts.take + ts.readto{|t| ! skip?(t)}
124
+ cur << ts.take
125
+ end
126
+
108
127
  if ts.include?('login')
109
128
  cur << ts.readto{|t| t == "login"} + ts.take + ts.readto{|t| ! skip?(t)}
110
129
  cur << ts.take
111
130
  end
131
+
112
132
  if ts.include?('password')
113
133
  cur << ts.readto{|t| t == "password"} + ts.take + ts.readto{|t| ! skip?(t)}
114
134
  cur << ts.take
115
135
  end
116
- cur << ts.readto{|t| t == "machine"}
136
+
137
+ cur << ts.readto{|t| t == "machine" || t == "default"}
138
+
117
139
  item << cur
118
140
  cur = []
119
141
  end
@@ -125,13 +147,21 @@ class Netrc
125
147
  @new_item_prefix = ''
126
148
  @path = path
127
149
  @pre, @data = data
150
+
151
+ if @data && @data.last && :default == @data.last[0]
152
+ @default = @data.pop
153
+ else
154
+ @default = nil
155
+ end
128
156
  end
129
157
 
130
158
  attr_accessor :new_item_prefix
131
159
 
132
160
  def [](k)
133
161
  if item = @data.detect {|datum| datum[1] == k}
134
- [item[3], item[5]]
162
+ Entry.new(item[3], item[5])
163
+ elsif @default
164
+ Entry.new(@default[3], @default[5])
135
165
  end
136
166
  end
137
167
 
@@ -173,7 +203,7 @@ class Netrc
173
203
  gpg.close_write
174
204
  gpg.read
175
205
  end
176
- raise Error.new("Encrypting #{path} failed.") unless $?.success?
206
+ raise Error.new("Encrypting #{@path} failed.") unless $?.success?
177
207
  File.open(@path, 'w', 0600) {|file| file.print(e)}
178
208
  else
179
209
  File.open(@path, 'w', 0600) {|file| file.print(unparse)}
@@ -191,6 +221,10 @@ class Netrc
191
221
  end.join
192
222
  end
193
223
 
224
+ Entry = Struct.new(:login, :password) do
225
+ alias to_ary to_a
226
+ end
227
+
194
228
  end
195
229
 
196
230
  class Netrc::Error < ::StandardError
@@ -8,7 +8,7 @@ require "rbconfig"
8
8
  class TestNetrc < Test::Unit::TestCase
9
9
 
10
10
  def setup
11
- File.chmod(0600, "data/sample.netrc")
11
+ Dir.glob('data/*.netrc').each{|f| File.chmod(0600, f)}
12
12
  File.chmod(0644, "data/permissive.netrc")
13
13
  end
14
14
 
@@ -60,21 +60,45 @@ class TestNetrc < Test::Unit::TestCase
60
60
 
61
61
  def test_permission_error
62
62
  original_windows = Netrc::WINDOWS
63
+ Netrc.send(:remove_const, :WINDOWS)
63
64
  Netrc.const_set(:WINDOWS, false)
64
65
  Netrc.read("data/permissive.netrc")
66
+ assert false, "Should raise an error if permissions are wrong on a non-windows system."
65
67
  rescue Netrc::Error
66
- assert true, "Should raise an error if permissions are wrong on a non-windows system."
68
+ assert true, ""
67
69
  ensure
70
+ Netrc.send(:remove_const, :WINDOWS)
68
71
  Netrc.const_set(:WINDOWS, original_windows)
69
72
  end
70
73
 
74
+ def test_allow_permissive_netrc_file_option
75
+ Netrc.configure do |config|
76
+ config[:allow_permissive_netrc_file] = true
77
+ end
78
+ original_windows = Netrc::WINDOWS
79
+ Netrc.send(:remove_const, :WINDOWS)
80
+ Netrc.const_set(:WINDOWS, false)
81
+ Netrc.read("data/permissive.netrc")
82
+ assert true, ""
83
+ rescue Netrc::Error
84
+ assert false, "Should not raise an error if allow_permissive_netrc_file option is set to true"
85
+ ensure
86
+ Netrc.send(:remove_const, :WINDOWS)
87
+ Netrc.const_set(:WINDOWS, original_windows)
88
+ Netrc.configure do |config|
89
+ config[:allow_permissive_netrc_file] = false
90
+ end
91
+ end
92
+
71
93
  def test_permission_error_windows
72
94
  original_windows = Netrc::WINDOWS
95
+ Netrc.send(:remove_const, :WINDOWS)
73
96
  Netrc.const_set(:WINDOWS, true)
74
97
  Netrc.read("data/permissive.netrc")
75
98
  rescue Netrc::Error
76
99
  assert false, "Should not raise an error if permissions are wrong on a non-windows system."
77
100
  ensure
101
+ Netrc.send(:remove_const, :WINDOWS)
78
102
  Netrc.const_set(:WINDOWS, original_windows)
79
103
  end
80
104
 
@@ -96,7 +120,7 @@ class TestNetrc < Test::Unit::TestCase
96
120
  def test_set_get
97
121
  n = Netrc.read("data/sample.netrc")
98
122
  n["m"] = "a", "b"
99
- assert_equal(["a", "b"], n["m"])
123
+ assert_equal(["a", "b"], n["m"].to_a)
100
124
  end
101
125
 
102
126
  def test_add
@@ -133,7 +157,7 @@ class TestNetrc < Test::Unit::TestCase
133
157
  n = Netrc.read("data/sample.netrc")
134
158
  n.new_item_prefix = "# added\n"
135
159
  n["x"] = "a", "b"
136
- assert_equal(["a", "b"], n["x"])
160
+ assert_equal(["a", "b"], n["x"].to_a)
137
161
  end
138
162
 
139
163
  def test_get_missing
@@ -176,5 +200,62 @@ class TestNetrc < Test::Unit::TestCase
176
200
  ENV["HOME"], nil_home = nil_home, ENV["HOME"]
177
201
  end
178
202
 
203
+ def test_read_entry
204
+ entry = Netrc.read("data/sample.netrc")['m']
205
+ assert_equal 'l', entry.login
206
+ assert_equal 'p', entry.password
207
+
208
+ # hash-style
209
+ assert_equal 'l', entry[:login]
210
+ assert_equal 'p', entry[:password]
211
+ end
212
+
213
+ def test_write_entry
214
+ n = Netrc.read("data/sample.netrc")
215
+ entry = n['m']
216
+ entry.login = 'new_login'
217
+ entry.password = 'new_password'
218
+ n['m'] = entry
219
+ assert_equal(['new_login', 'new_password'], n['m'].to_a)
220
+ end
221
+
222
+ def test_entry_splat
223
+ e = Netrc::Entry.new("user", "pass")
224
+ user, pass = *e
225
+ assert_equal("user", user)
226
+ assert_equal("pass", pass)
227
+ end
179
228
 
229
+ def test_entry_implicit_splat
230
+ e = Netrc::Entry.new("user", "pass")
231
+ user, pass = e
232
+ assert_equal("user", user)
233
+ assert_equal("pass", pass)
234
+ end
235
+
236
+ def test_with_default
237
+ netrc = Netrc.read('data/sample_with_default.netrc')
238
+ assert_equal(['l', 'p'], netrc['m'].to_a)
239
+ assert_equal(['default_login', 'default_password'], netrc['unknown'].to_a)
240
+ end
241
+
242
+ def test_multi_without_default
243
+ netrc = Netrc.read('data/sample_multi.netrc')
244
+ assert_equal(['lm', 'pm'], netrc['m'].to_a)
245
+ assert_equal(['ln', 'pn'], netrc['n'].to_a)
246
+ assert_equal([], netrc['other'].to_a)
247
+ end
248
+
249
+ def test_multi_with_default
250
+ netrc = Netrc.read('data/sample_multi_with_default.netrc')
251
+ assert_equal(['lm', 'pm'], netrc['m'].to_a)
252
+ assert_equal(['ln', 'pn'], netrc['n'].to_a)
253
+ assert_equal(['ld', 'pd'], netrc['other'].to_a)
254
+ end
255
+
256
+ def test_default_only
257
+ netrc = Netrc.read('data/default_only.netrc')
258
+ assert_equal(['ld', 'pd'], netrc['m'].to_a)
259
+ assert_equal(['ld', 'pd'], netrc['other'].to_a)
260
+ end
180
261
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netrc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.7
5
- prerelease:
4
+ version: 0.7.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Keith Rarick
@@ -10,19 +9,22 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-08-15 00:00:00.000000000 Z
12
+ date: 2014-10-15 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: turn
17
- requirement: &70180390635460 !ruby/object:Gem::Requirement
18
- none: false
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  requirements:
20
18
  - - ! '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '0'
23
21
  type: :development
24
22
  prerelease: false
25
- version_requirements: *70180390635460
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
26
28
  description: This library can read and update netrc files, preserving formatting including
27
29
  comments and whitespace.
28
30
  email: geemus@gmail.com
@@ -30,40 +32,44 @@ executables: []
30
32
  extensions: []
31
33
  extra_rdoc_files: []
32
34
  files:
33
- - LICENSE
35
+ - LICENSE.md
34
36
  - Readme.md
35
37
  - changelog.txt
38
+ - data/default_only.netrc
36
39
  - data/login.netrc
37
40
  - data/newlineless.netrc
38
41
  - data/password.netrc
39
42
  - data/permissive.netrc
40
43
  - data/sample.netrc
44
+ - data/sample_multi.netrc
45
+ - data/sample_multi_with_default.netrc
46
+ - data/sample_with_default.netrc
41
47
  - lib/netrc.rb
42
48
  - test/test_lex.rb
43
49
  - test/test_netrc.rb
44
50
  - test/test_parse.rb
45
51
  homepage: https://github.com/geemus/netrc
46
52
  licenses: []
53
+ metadata: {}
47
54
  post_install_message:
48
55
  rdoc_options: []
49
56
  require_paths:
50
57
  - lib
51
58
  required_ruby_version: !ruby/object:Gem::Requirement
52
- none: false
53
59
  requirements:
54
60
  - - ! '>='
55
61
  - !ruby/object:Gem::Version
56
62
  version: '0'
57
63
  required_rubygems_version: !ruby/object:Gem::Requirement
58
- none: false
59
64
  requirements:
60
65
  - - ! '>='
61
66
  - !ruby/object:Gem::Version
62
67
  version: '0'
63
68
  requirements: []
64
69
  rubyforge_project:
65
- rubygems_version: 1.8.15
70
+ rubygems_version: 2.3.0
66
71
  signing_key:
67
- specification_version: 3
72
+ specification_version: 4
68
73
  summary: Library to read and write netrc files.
69
74
  test_files: []
75
+ has_rdoc:
data/LICENSE DELETED
@@ -1,7 +0,0 @@
1
- Copyright (c) 2012 Wesley Beary <geemus@gmail.com>
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.