netrcx 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 99e57ba09db815ea970ee451d06751e9498dd273d387c970cf4627d439644640
4
+ data.tar.gz: 0d052ccaf348c4e8b6a113c3f449531cf196993f04fa07cc0e5bcfd9a9d7fa15
5
+ SHA512:
6
+ metadata.gz: 1144c4b76d527780dd45a5ce539ec6111f4acf0936c77c42be6c13fb27bb3b2e6161c717fa83de33ae529092890f980bf0de5b93b7e25dea15fb396906dca0c2
7
+ data.tar.gz: 1cb87d34137ff0f131ba9aaac1f8f95e6819d8e343ec3d6a261a009e306282a35e6ecfc23a754781d4f6cf253a24b9732b322ec9b51aad029f2b3abe27b2861c
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .rubocop-*
2
+ pkg/
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ inherit_from:
2
+ - https://gitlab.com/bsm/misc/raw/master/rubocop/default.yml
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 2.4
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.6
5
+ - 2.5
6
+ - 2.4
7
+ before_install:
8
+ - gem install bundler
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ netrcx (0.2.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.2)
12
+ parallel (1.17.0)
13
+ parser (2.6.2.0)
14
+ ast (~> 2.4.0)
15
+ psych (3.1.0)
16
+ rainbow (3.0.0)
17
+ rake (12.3.2)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.2)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+ rubocop (0.66.0)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.5, != 2.5.1.1)
35
+ psych (>= 3.1.0)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 1.6)
39
+ ruby-progressbar (1.10.0)
40
+ unicode-display_width (1.5.0)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler
47
+ netrcx!
48
+ rake
49
+ rspec
50
+ rubocop
51
+
52
+ BUNDLED WITH
53
+ 2.0.1
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # netrcx
2
+
3
+ [![Build Status](https://travis-ci.org/bsm/netrcx.png?branch=master)](https://travis-ci.org/bsm/netrcx)
4
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
5
+
6
+ A working netrc reader and parser for Ruby.
7
+
8
+ ## Usage (Ruby)
9
+
10
+ ```ruby
11
+ require 'netrcx'
12
+
13
+ # Read from default location
14
+ netrc = Netrcx.read
15
+
16
+ # Read the default entry (if set)
17
+ netrc.default # => #<Netrcx::Entry default=true, login="me">
18
+
19
+ # Find a specific entry
20
+ netrc['github.com'] # => #<Netrcx::Entry default=false, host=github.com, login="s3cret/t0ken">
21
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ RuboCop::RakeTask.new(:rubocop)
8
+
9
+ task default: %i[spec rubocop]
data/lib/netrcx.rb ADDED
@@ -0,0 +1,82 @@
1
+ require 'shellwords'
2
+ require 'ostruct'
3
+
4
+ class Netrcx
5
+ class Entry < OpenStruct
6
+ def default?
7
+ default == true
8
+ end
9
+ end
10
+
11
+ def self.default_path
12
+ home = ENV['NETRC']
13
+ home ||= Dir.home if Dir.respond_to?(:home)
14
+ home ||= ENV['HOME']
15
+
16
+ if /mswin|mingw/.match?(RbConfig::CONFIG['host_os'])
17
+ home ||= File.join(ENV['HOMEDRIVE'], ENV['HOMEPATH']) if ENV['HOMEDRIVE'] && ENV['HOMEPATH']
18
+ home ||= ENV['USERPROFILE']
19
+ File.join home, '_netrc'
20
+ else
21
+ File.join home, '.netrc'
22
+ end
23
+ end
24
+
25
+ # Read from a file path.
26
+ def self.read(path=default_path)
27
+ File.open(path) {|io| new(io) }
28
+ end
29
+
30
+ attr_reader :entries
31
+
32
+ def initialize(raw)
33
+ @entries = []
34
+ current = nil
35
+ lastword = nil
36
+
37
+ raw.each_line do |line|
38
+ Shellwords.split(line).each do |word|
39
+ break if word.start_with?('#')
40
+
41
+ if word == 'default'
42
+ @entries.push(current) if current
43
+ current = Entry.new(default: true)
44
+ elsif word == 'machine'
45
+ @entries.push(current) if current
46
+ current = Entry.new(default: false)
47
+ elsif !current.nil?
48
+ set_value(current, lastword, word)
49
+ end
50
+
51
+ lastword = word
52
+ end
53
+ end
54
+ @entries.push(current) if current
55
+ end
56
+
57
+ # @return [Netrcx::Entry] default entry
58
+ def default
59
+ entries.detect(&:default)
60
+ end
61
+
62
+ # @return [Netrcx::Entry] entry for the host
63
+ def [](host)
64
+ host = host.strip
65
+ entries.detect {|m| m.host == host }
66
+ end
67
+
68
+ private
69
+
70
+ def set_value(current, lastword, word)
71
+ case lastword
72
+ when 'machine'
73
+ current.host = word
74
+ when 'login'
75
+ current.login = word
76
+ when 'password'
77
+ current.password = word
78
+ when 'account'
79
+ current.account = word
80
+ end
81
+ end
82
+ end
data/netrcx.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'netrcx'
3
+ s.version = '0.2.1'
4
+ s.authors = ['Black Square Media Ltd']
5
+ s.email = ['info@blacksquaremedia.com']
6
+ s.summary = %(Simple .netrc parser)
7
+ s.description = %()
8
+ s.homepage = 'https://github.com/bsm/netrcx'
9
+ s.license = 'Apache-2.0'
10
+
11
+ s.files = `git ls-files -z`.split("\x0").reject {|f| f.match(%r{^spec/}) }
12
+ s.test_files = `git ls-files -z -- spec/*`.split("\x0")
13
+ s.require_paths = ['lib']
14
+ s.required_ruby_version = '>= 2.4'
15
+
16
+ s.add_development_dependency 'bundler'
17
+ s.add_development_dependency 'rake'
18
+ s.add_development_dependency 'rspec'
19
+ s.add_development_dependency 'rubocop'
20
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Netrcx do
4
+ let :fixture do
5
+ <<~TEXT
6
+ machine a.com
7
+ login s3cret
8
+ machine b.com
9
+ login userb
10
+ password passb
11
+ machine c.com
12
+ login 'domain\\user'
13
+ password passc
14
+ account workgroup
15
+ default
16
+ login me
17
+ TEXT
18
+ end
19
+
20
+ it 'should parse' do
21
+ netrc = Netrcx.new(fixture)
22
+ expect(netrc.default).to eq(Netrcx::Entry.new(default: true, login: 'me'))
23
+ expect(netrc.entries).to eq [
24
+ Netrcx::Entry.new(default: false, host: 'a.com', login: 's3cret'),
25
+ Netrcx::Entry.new(default: false, host: 'b.com', login: 'userb', password: 'passb'),
26
+ Netrcx::Entry.new(default: false, host: 'c.com', login: 'domain\\user', password: 'passc', account: 'workgroup'),
27
+ Netrcx::Entry.new(default: true, login: 'me'),
28
+ ]
29
+ end
30
+
31
+ it 'should read from file' do
32
+ temp = Tempfile.new
33
+ temp.write fixture
34
+ temp.close
35
+
36
+ netrc = Netrcx.read(temp.path)
37
+ expect(netrc.entries.size).to eq(4)
38
+ end
39
+
40
+ it 'should skip comments' do
41
+ data = <<~TEXT
42
+ machine a.com login x
43
+ # machine b.com login y
44
+ machine c.com
45
+ # login old
46
+ login z #password follows
47
+ password # next line
48
+ s3cret
49
+ TEXT
50
+
51
+ netrc = Netrcx.new(data)
52
+ expect(netrc.default).to be_nil
53
+ expect(netrc.entries).to eq [
54
+ Netrcx::Entry.new(default: false, host: 'a.com', login: 'x'),
55
+ Netrcx::Entry.new(default: false, host: 'c.com', login: 'z', password: 's3cret'),
56
+ ]
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ require 'netrcx'
2
+ require 'rspec'
3
+ require 'tempfile'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: netrcx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Black Square Media Ltd
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: ''
70
+ email:
71
+ - info@blacksquaremedia.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rubocop.yml"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - lib/netrcx.rb
84
+ - netrcx.gemspec
85
+ - spec/netrcx_spec.rb
86
+ - spec/spec_helper.rb
87
+ homepage: https://github.com/bsm/netrcx
88
+ licenses:
89
+ - Apache-2.0
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '2.4'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.0.3
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Simple .netrc parser
110
+ test_files:
111
+ - spec/netrcx_spec.rb
112
+ - spec/spec_helper.rb