quick_and_ruby 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 2dacf0eef4670a10a60a03ada40d2e0e5d4e30c60b0fc23fdcd3fdbd45e38d82
4
- data.tar.gz: e503dd59874a398565fea49086327d7734bfdab6b62fca095b42b146eeff3fd5
3
+ metadata.gz: 5e695692e69fbbe9d843e3b31fe830ab5db5b9310ec914a29fe1b57bebac5b49
4
+ data.tar.gz: dd2f04a4330b3e1442fcac6b6eaa3fb28511818b7e7ef0affd6d884468b24d08
5
5
  SHA512:
6
- metadata.gz: a6bc4542f31f16d60ff9a4e8c5b777eec857b0032e8b3dd26ecee55148776bd8f7fc04dc5220fd9f856944260a2bbbeaae63b54296cf39bab43de8e909f4b23e
7
- data.tar.gz: e5606a498d3fbf8c4a09cf222ac82e3e8ed3b3501920db1f7dc48542587d2ac3ad918d6ca65b2cb10f106fca0728ae470442d190e2094b839686ca3a023cd923
6
+ metadata.gz: d94125e0cb6710267077f820264d547da8400b8914106d39061982a2c6b81bd67f65ccbc739999e5a973db28176cc13fcc9e5bdc3a2926397d62f29fdb87226c
7
+ data.tar.gz: 765193d18ccf0db661daa0301004867144db799883e016d2e4ebcd07f6e7545fb78dc4faad5604bb968b5ce09194d46d4c3dcfe859cbc7a99c47e786df908907
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quick_and_ruby (0.1.0)
4
+ quick_and_ruby (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exe/proxy CHANGED
@@ -3,5 +3,7 @@
3
3
 
4
4
  require 'quick_and_ruby'
5
5
 
6
- options = QuickAndRuby::Proxy::ArgParser.new(ARGV).parse
7
- QuickAndRuby::Proxy::Proxy.new(options).start
6
+ env_options = QuickAndRuby::Proxy::EnvParser.new.parse
7
+ arg_options = QuickAndRuby::Proxy::ArgParser.new(ARGV).parse
8
+ QuickAndRuby::Proxy::Proxy.new(env_options.merge(arg_options))
9
+ .start
@@ -1,5 +1,6 @@
1
1
  require 'quick_and_ruby/version'
2
2
  require 'quick_and_ruby/proxy/arg_parser'
3
+ require 'quick_and_ruby/proxy/env_parser'
3
4
  require 'quick_and_ruby/proxy/proxy'
4
5
 
5
6
  module QuickAndRuby
@@ -2,9 +2,6 @@ require 'optparse'
2
2
  require 'optparse/time'
3
3
  require 'ostruct'
4
4
 
5
- # Usage is
6
- # --dowstream
7
- # -v --verbose
8
5
  module QuickAndRuby
9
6
  module Proxy
10
7
  # service
@@ -13,11 +10,9 @@ module QuickAndRuby
13
10
  class ArgParser
14
11
  def initialize(argv)
15
12
  @argv = argv
16
- @options = OpenStruct.new(
17
- verbose: false,
18
- bind: '0.0.0.0',
19
- port: 8080
20
- )
13
+ @options = { verbose: false,
14
+ bind: '0.0.0.0',
15
+ port: 8080 }
21
16
  end
22
17
 
23
18
  def parse
@@ -37,32 +32,32 @@ module QuickAndRuby
37
32
  opts.separator 'Options:'
38
33
 
39
34
  opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
40
- options.verbose = v
35
+ options[:verbose] = v
41
36
  end
42
37
 
43
38
  opts.on('-u', '--user USER:PASSWORD',
44
39
  'specify USER') do |user|
45
- options.user = user
40
+ options[:user] = user
46
41
  end
47
42
 
48
43
  opts.on('-H', '--proxy-host HOST',
49
44
  'specify proxy HOST to use') do |host|
50
- options.proxy_host = host
45
+ options[:proxy_host] = host
51
46
  end
52
47
 
53
48
  opts.on('-P', '--proxy-port PORT',
54
49
  'specify proxy PORT to use') do |port|
55
- options.proxy_port = port
50
+ options[:proxy_port] = port
56
51
  end
57
52
 
58
53
  opts.on('-b', '--bind IP',
59
54
  'specify IP to bind on') do |ip|
60
- options.bind = ip
55
+ options[:bind] = ip
61
56
  end
62
57
 
63
58
  opts.on('-p', '--port PORT',
64
59
  'specify PORT to listen on') do |port|
65
- options.port = port
60
+ options[:port] = port
66
61
  end
67
62
 
68
63
  opts.on_tail('-h', '--help', 'Show this message') do
@@ -0,0 +1,40 @@
1
+ require 'uri'
2
+
3
+ module QuickAndRuby
4
+ module Proxy
5
+ # service
6
+ # parse env for proxy exe
7
+ class EnvParser
8
+ INDEX_TO_KEY = { 3 => :user,
9
+ 4 => :proxy_host,
10
+ 5 => :proxy_port }.freeze
11
+
12
+ def initialize(env = ENV)
13
+ @env = env
14
+ end
15
+
16
+ def parse
17
+ parsed = _parsed_proxy
18
+ return {} unless parsed
19
+
20
+ INDEX_TO_KEY.each_with_object({}) do |(index, key), options|
21
+ options[key] = parsed[index] if parsed[index]
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :env
28
+
29
+ def _http_proxy
30
+ env['HTTP_PROXY'] || env['http_proxy']
31
+ end
32
+
33
+ def _parsed_proxy
34
+ return unless _http_proxy
35
+
36
+ _http_proxy.match(URI::DEFAULT_PARSER.make_regexp)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -40,16 +40,16 @@ module QuickAndRuby
40
40
  end
41
41
 
42
42
  def base_proxy_options
43
- { BindAddress: options.bind,
44
- Port: options.port }
43
+ { BindAddress: options[:bind],
44
+ Port: options[:port] }
45
45
  end
46
46
 
47
47
  def remote_proxy_options
48
- if options.proxy_host
48
+ if options[:proxy_host]
49
49
  uri = OpenStruct.new(
50
- userinfo: options.user,
51
- host: options.proxy_host,
52
- port: options.proxy_port
50
+ userinfo: options[:user],
51
+ host: options[:proxy_host],
52
+ port: options[:proxy_port]
53
53
  )
54
54
  return { ProxyURI: uri }
55
55
  end
@@ -1,3 +1,3 @@
1
1
  module QuickAndRuby
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quick_and_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ttych
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-06 00:00:00.000000000 Z
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,6 +88,7 @@ files:
88
88
  - exe/proxy
89
89
  - lib/quick_and_ruby.rb
90
90
  - lib/quick_and_ruby/proxy/arg_parser.rb
91
+ - lib/quick_and_ruby/proxy/env_parser.rb
91
92
  - lib/quick_and_ruby/proxy/proxy.rb
92
93
  - lib/quick_and_ruby/version.rb
93
94
  - quick_and_ruby.gemspec