proxy_pac_rb 0.6.8 → 0.6.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6218053a32fc112fbc21d3d13dcf321133f7330e
4
- data.tar.gz: 5d6a5658d3de402b187a42f97e6a5860f123a1c6
3
+ metadata.gz: e91fc474b42767f3467a68ee3d5c5ce8856f06f6
4
+ data.tar.gz: 77927902a99dcc26026e0381f2692815690235b6
5
5
  SHA512:
6
- metadata.gz: 41b9301f4bbc85cc42838873f2bccce8004c7d32ac8055f2264a36191e1c50c35243027d4f059634cd99480c9887f0f009a2e50718db541039fa27d4172bf8dd
7
- data.tar.gz: 0585895de55f8fd9634d204818b96fc042551cbb8d2c67c20624074e615eaf04226b3fc37955037a6d22b108c6f06d65ea319ae600a8dccc115d38e098c7dc1d
6
+ metadata.gz: 267f300d1b5aaa5abfc8c3717c359341f70904266880eed6ff84526f0909a0a70eacb706bdf2c143aa94f926ad7dc9f17cd3a7812f01a590d0f4f405c14811b6
7
+ data.tar.gz: 5067d0c9c78254aa7576f8c46e7ea953239ff91d713878de2b45c658a7757fc6bd9b0b10e3b1eb29a8856add226d67461209486c140faf91e8f1cbb4c4cf36f1
data/README.md CHANGED
@@ -52,12 +52,13 @@ After installing the `proxy_pac_rb` gem you must install a JavaScript runtime. C
52
52
  *Use*
53
53
 
54
54
  ```bash
55
- # Download pac
55
+ # Download via curl and parse pac
56
56
  curl -L -o sample.pac https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample.pac
57
-
58
- # Parse pac
59
57
  pprb find proxy -c 127.0.0.1 -t "2014-03-09 12:00:00" -p sample.pac -u https://github.com
60
58
 
59
+ # Or download via pprb directly and parse pac #2
60
+ pprb find proxy -c 127.0.0.1 -t "2014-03-09 12:00:00" -p https://github.com/fedux-org/proxy_pac_rb/raw/master/files/sample.pac -u https://github.com
61
+
61
62
  # => url: result
62
63
  # => https://github.com: DIRECT
63
64
  ```
@@ -9,6 +9,7 @@ module ProxyPacRb
9
9
  class_option :time, default: Time.now.to_s, desc: 'Time to use during lookup url', aliases: '-t'
10
10
  class_option :proxy_pac, desc: 'Proxy.pac-file', aliases: '-p', required: true
11
11
  class_option :urls, type: :array, desc: 'URLs to check against proxy pac', aliases: '-u', required: true
12
+ class_option :use_proxy, default: false, type: :boolean, desc: 'Use proxy to download proxy pac (default false)'
12
13
 
13
14
  def pre_init
14
15
  enable_debug_mode
@@ -22,6 +23,8 @@ module ProxyPacRb
22
23
  time: Time.parse(options[:time])
23
24
  )
24
25
 
26
+ remove_proxy_environment_variables unless options[:use_proxy]
27
+
25
28
  file = ProxyPacRb::Parser.new(environment: environment).parse(options[:proxy_pac])
26
29
 
27
30
  return if file.blank?
@@ -7,6 +7,18 @@ module ProxyPacRb
7
7
  def enable_debug_mode
8
8
  ProxyPacRb.enable_debug_mode if options[:debug_mode] == true
9
9
  end
10
+
11
+ # Remove proxy variables
12
+ def remove_proxy_environment_variables
13
+ %w(
14
+ http_proxy
15
+ https_proxy
16
+ HTTP_PROXY
17
+ HTTPS_PROXY
18
+ ).each do |v|
19
+ ENV.delete(v)
20
+ end
21
+ end
10
22
  end
11
23
  end
12
24
  end
@@ -84,10 +84,8 @@ module ProxyPacRb
84
84
  # Load proxy pac from url
85
85
  class ProxyPacUriLoader
86
86
  def load(proxy_pac)
87
- content = Net::HTTP.get(URI(proxy_pac.source.to_s)).chomp
88
-
89
- proxy_pac.content = content
90
- proxy_pac.type = :url
87
+ proxy_pac.content = download_proxy_pac(proxy_pac.source.to_s)
88
+ proxy_pac.type = :url
91
89
  end
92
90
 
93
91
  def suitable_for?(proxy_pac)
@@ -104,28 +102,9 @@ module ProxyPacRb
104
102
 
105
103
  private
106
104
 
107
- def with_proxy_environment_variables
108
- backup = []
109
-
110
- %w(
111
- http_proxy
112
- https_proxy
113
- HTTP_PROXY
114
- HTTPS_PROXY
115
- ).each do |v|
116
- backup << ENV.delete(v)
117
- end
118
-
119
- yield
120
- ensure
121
- %w(
122
- http_proxy
123
- https_proxy
124
- HTTP_PROXY
125
- HTTPS_PROXY
126
- ).each do |v|
127
- ENV[v] = backup.shift
128
- end
105
+ def download_proxy_pac(url)
106
+ Excon.defaults[:middlewares] << Excon::Middleware::RedirectFollower
107
+ Excon.get(url).body.chomp
129
108
  end
130
109
  end
131
110
  end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # ProxyPacRb
3
3
  module ProxyPacRb
4
- VERSION = '0.6.8'
4
+ VERSION = '0.6.9'
5
5
  end
data/lib/proxy_pac_rb.rb CHANGED
@@ -9,7 +9,7 @@ require 'uglifier'
9
9
  require 'optparse'
10
10
  require 'ostruct'
11
11
  require 'resolv'
12
- require 'net/http'
12
+ require 'excon'
13
13
  require 'time'
14
14
  require 'timeout'
15
15
  require 'pathname'
@@ -29,7 +29,6 @@ require 'proxy_pac_rb/parser'
29
29
  require 'proxy_pac_rb/javascript'
30
30
  require 'proxy_pac_rb/proxy_pac_js'
31
31
  require 'proxy_pac_rb/proxy_pac_file'
32
- require 'proxy_pac_rb/proxy_pac_template'
33
32
  require 'proxy_pac_rb/proxy_pac_compressor'
34
33
  require 'proxy_pac_rb/proxy_pac_dumper'
35
34
  require 'proxy_pac_rb/proxy_pac_loader'
data/proxy_pac_rb.gemspec CHANGED
@@ -9,9 +9,11 @@ Gem::Specification.new do |spec|
9
9
  spec.email = ['dg1@vrnetze.de']
10
10
  spec.homepage = 'https://github.com/dg-vrnetze/proxy_pac_rb'
11
11
  spec.summary = 'Compress, lint and parse proxy auto-config files from commandline, rack-compatible applications and custom ruby code.'
12
+ # rubocop:disable Metrics/LineLength
12
13
  spec.description = <<-DESC
13
14
  "proxy_pac_rb" is a gem to compress, lint and parse proxy auto-config files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. "proxy_pac_rb" uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: therubyracer or therubyrhino
14
15
  DESC
16
+ # rubocop:enable Metrics/LineLength
15
17
 
16
18
  spec.license = 'MIT'
17
19
 
@@ -23,6 +25,7 @@ DESC
23
25
  spec.add_runtime_dependency 'addressable', '~>2.3.8'
24
26
  spec.add_runtime_dependency 'activesupport', '~>4.1'
25
27
  spec.add_runtime_dependency 'uglifier', '~> 2.7.1'
28
+ spec.add_runtime_dependency 'excon', '~> 0.45.3'
26
29
 
27
30
  spec.required_ruby_version = '~> 2.0'
28
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proxy_pac_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.6.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Günnewig
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: 2.7.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: excon
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.45.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.45.3
55
69
  description: |
56
70
  "proxy_pac_rb" is a gem to compress, lint and parse proxy auto-config files. It comes with a cli program, some rack middlewares and can be used from within ruby scripts as well. "proxy_pac_rb" uses a JavaScript runtime to evaulate a proxy auto-config file the same way a browser does to determine what proxy (if any at all) should a program use to connect to a server. You must install on of the supported JavaScript runtimes: therubyracer or therubyrhino
57
71
  email:
@@ -117,7 +131,6 @@ files:
117
131
  - lib/proxy_pac_rb/proxy_pac_linter.rb
118
132
  - lib/proxy_pac_rb/proxy_pac_loader.rb
119
133
  - lib/proxy_pac_rb/proxy_pac_parser.rb
120
- - lib/proxy_pac_rb/proxy_pac_template.rb
121
134
  - lib/proxy_pac_rb/rack/proxy_pac_compressor.rb
122
135
  - lib/proxy_pac_rb/rack/proxy_pac_linter.rb
123
136
  - lib/proxy_pac_rb/rspec.rb
@@ -1,72 +0,0 @@
1
- # encoding: utf-8
2
- module ProxyPacRb
3
- # Template for proxy pac
4
- class ProxyPacTemplate
5
- private
6
-
7
- attr_reader :path, :compressed_content
8
-
9
- public
10
-
11
- attr_writer :compressed_content
12
-
13
- def initialize(path)
14
- @path = path
15
- end
16
-
17
- def write
18
- ::File.write(output_path, compressed_content)
19
- end
20
-
21
- def compress_me(compressor)
22
- compressor.compress(self)
23
- end
24
-
25
- def raw_content
26
- read_proxy_pac(input_path)
27
- end
28
-
29
- def input_path
30
- if ::File.exist?(path.gsub(/#{in_extension}*$/, '') + in_extension)
31
- return path.gsub(/#{in_extension}*$/, '') + in_extension
32
- elsif ::File.exist? path
33
- return path
34
- else
35
- fail Errno::ENOENT, "Both paths \"#{path.gsub(/#{in_extension}*$/, '') + in_extension}\" and \"#{path}\" do not exist."
36
- end
37
- end
38
-
39
- private
40
-
41
- def in_extension
42
- '.in'
43
- end
44
-
45
- def out_extension
46
- '.out'
47
- end
48
-
49
- def output_path
50
- if ::File.exist?(path.gsub(/#{in_extension}*$/, '') + in_extension)
51
- return path.gsub(/#{in_extension}*$/, '')
52
- elsif ::File.exist? path
53
- return path + out_extension
54
- else
55
- fail Errno::ENOENT, "Both paths \"#{path.gsub(/#{in_extension}*$/, '') + in_extension}\" and \"#{path}\" do not exist."
56
- end
57
- end
58
-
59
- def read_proxy_pac(path)
60
- uri = Addressable::URI.parse(path)
61
-
62
- uri.path = ::File.expand_path(uri.path) if uri.host.nil?
63
-
64
- ENV.delete 'HTTP_PROXY'
65
- ENV.delete 'HTTPS_PROXY'
66
- ENV.delete 'http_proxy'
67
- ENV.delete 'https_proxy'
68
-
69
- open(uri, proxy: false).read
70
- end
71
- end
72
- end