netrc 0.7.5 → 0.7.6
Sign up to get free protection for your applications and to get access to all the features.
- data/data/login.netrc +3 -0
- data/data/password.netrc +3 -0
- data/lib/netrc.rb +18 -10
- data/test/test_netrc.rb +22 -0
- metadata +6 -4
data/data/login.netrc
ADDED
data/data/password.netrc
ADDED
data/lib/netrc.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rbconfig'
|
2
2
|
|
3
3
|
class Netrc
|
4
|
-
VERSION = "0.7.
|
4
|
+
VERSION = "0.7.6"
|
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/
|
@@ -26,13 +26,17 @@ class Netrc
|
|
26
26
|
# exist, returns an empty object. Decrypt paths ending in .gpg.
|
27
27
|
def self.read(path=default_path)
|
28
28
|
check_permissions(path)
|
29
|
-
if path =~ /\.gpg$/
|
29
|
+
data = if path =~ /\.gpg$/
|
30
30
|
decrypted = `gpg --batch --quiet --decrypt #{path}`
|
31
|
-
|
32
|
-
|
31
|
+
if $?.success?
|
32
|
+
decrypted
|
33
|
+
else
|
34
|
+
raise Error.new("Decrypting #{path} failed.") unless $?.success?
|
35
|
+
end
|
33
36
|
else
|
34
|
-
|
37
|
+
File.read(path)
|
35
38
|
end
|
39
|
+
new(path, parse(lex(data.lines.to_a)))
|
36
40
|
rescue Errno::ENOENT
|
37
41
|
new(path, parse(lex([])))
|
38
42
|
end
|
@@ -69,7 +73,7 @@ class Netrc
|
|
69
73
|
end
|
70
74
|
|
71
75
|
# Returns two values, a header and a list of items.
|
72
|
-
# Each item is a
|
76
|
+
# Each item is a tuple, containing some or all of:
|
73
77
|
# - machine keyword (including trailing whitespace+comments)
|
74
78
|
# - machine name
|
75
79
|
# - login keyword (including surrounding whitespace+comments)
|
@@ -101,10 +105,14 @@ class Netrc
|
|
101
105
|
while ts.length > 0
|
102
106
|
cur << ts.take + ts.readto{|t| ! skip?(t)}
|
103
107
|
cur << ts.take
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
+
if ts.include?('login')
|
109
|
+
cur << ts.readto{|t| t == "login"} + ts.take + ts.readto{|t| ! skip?(t)}
|
110
|
+
cur << ts.take
|
111
|
+
end
|
112
|
+
if ts.include?('password')
|
113
|
+
cur << ts.readto{|t| t == "password"} + ts.take + ts.readto{|t| ! skip?(t)}
|
114
|
+
cur << ts.take
|
115
|
+
end
|
108
116
|
cur << ts.readto{|t| t == "machine"}
|
109
117
|
item << cur
|
110
118
|
cur = []
|
data/test/test_netrc.rb
CHANGED
@@ -31,6 +31,28 @@ class TestNetrc < Test::Unit::TestCase
|
|
31
31
|
assert_equal(exp, items)
|
32
32
|
end
|
33
33
|
|
34
|
+
def test_login_file
|
35
|
+
pre, items = Netrc.parse(Netrc.lex(IO.readlines("data/login.netrc")))
|
36
|
+
assert_equal("# this is my login netrc\n", pre)
|
37
|
+
exp = [["machine ",
|
38
|
+
"m",
|
39
|
+
"\n login ",
|
40
|
+
"l",
|
41
|
+
" # this is my username\n"]]
|
42
|
+
assert_equal(exp, items)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_password_file
|
46
|
+
pre, items = Netrc.parse(Netrc.lex(IO.readlines("data/password.netrc")))
|
47
|
+
assert_equal("# this is my password netrc\n", pre)
|
48
|
+
exp = [["machine ",
|
49
|
+
"m",
|
50
|
+
"\n password ",
|
51
|
+
"p",
|
52
|
+
" # this is my password\n"]]
|
53
|
+
assert_equal(exp, items)
|
54
|
+
end
|
55
|
+
|
34
56
|
def test_missing_file
|
35
57
|
n = Netrc.read("data/nonexistent.netrc")
|
36
58
|
assert_equal(0, n.length)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netrc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-08-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: turn
|
17
|
-
requirement: &
|
17
|
+
requirement: &70245365255400 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70245365255400
|
26
26
|
description: This library can read and update netrc files, preserving formatting including
|
27
27
|
comments and whitespace.
|
28
28
|
email: geemus@gmail.com
|
@@ -33,6 +33,8 @@ files:
|
|
33
33
|
- LICENSE
|
34
34
|
- Readme.md
|
35
35
|
- changelog.txt
|
36
|
+
- data/login.netrc
|
37
|
+
- data/password.netrc
|
36
38
|
- data/permissive.netrc
|
37
39
|
- data/sample.netrc
|
38
40
|
- lib/netrc.rb
|