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 +4 -4
- data/Gemfile.lock +1 -1
- data/exe/proxy +4 -2
- data/lib/quick_and_ruby.rb +1 -0
- data/lib/quick_and_ruby/proxy/arg_parser.rb +9 -14
- data/lib/quick_and_ruby/proxy/env_parser.rb +40 -0
- data/lib/quick_and_ruby/proxy/proxy.rb +6 -6
- data/lib/quick_and_ruby/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e695692e69fbbe9d843e3b31fe830ab5db5b9310ec914a29fe1b57bebac5b49
|
4
|
+
data.tar.gz: dd2f04a4330b3e1442fcac6b6eaa3fb28511818b7e7ef0affd6d884468b24d08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d94125e0cb6710267077f820264d547da8400b8914106d39061982a2c6b81bd67f65ccbc739999e5a973db28176cc13fcc9e5bdc3a2926397d62f29fdb87226c
|
7
|
+
data.tar.gz: 765193d18ccf0db661daa0301004867144db799883e016d2e4ebcd07f6e7545fb78dc4faad5604bb968b5ce09194d46d4c3dcfe859cbc7a99c47e786df908907
|
data/Gemfile.lock
CHANGED
data/exe/proxy
CHANGED
@@ -3,5 +3,7 @@
|
|
3
3
|
|
4
4
|
require 'quick_and_ruby'
|
5
5
|
|
6
|
-
|
7
|
-
QuickAndRuby::Proxy::
|
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
|
data/lib/quick_and_ruby.rb
CHANGED
@@ -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 =
|
17
|
-
|
18
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
44
|
-
Port: options
|
43
|
+
{ BindAddress: options[:bind],
|
44
|
+
Port: options[:port] }
|
45
45
|
end
|
46
46
|
|
47
47
|
def remote_proxy_options
|
48
|
-
if options
|
48
|
+
if options[:proxy_host]
|
49
49
|
uri = OpenStruct.new(
|
50
|
-
userinfo: options
|
51
|
-
host: options
|
52
|
-
port: options
|
50
|
+
userinfo: options[:user],
|
51
|
+
host: options[:proxy_host],
|
52
|
+
port: options[:proxy_port]
|
53
53
|
)
|
54
54
|
return { ProxyURI: uri }
|
55
55
|
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.
|
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-
|
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
|