envoy-proxy 0.1.5 → 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/lib/envoy/client/command.rb +4 -4
- data/lib/envoy/client/option_parser.rb +18 -16
- data/lib/envoy/server/trunk.rb +7 -6
- data/lib/envoy/server/web.rb +14 -7
- data/lib/envoy/version.rb +1 -1
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ed79185e2aad87adb4349b67cc291736ba715e0
|
4
|
+
data.tar.gz: b4c8f976611a606f40cc4cad0b4242f0e1f8b3ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0041100f109dbee5cfd0d33a5eb8bffd88acda65fa810bba1c8f3ac1c184d5bcbbae50bc6bf9f535bd9ac9485a4a1a9f28b3e0a886f5b2dced6944aef5bb622
|
7
|
+
data.tar.gz: d9a0a9017b0dc3457385c9717db2ff3acf72c549cfc76a23eb43b7e8caeca06af98b8ac67ea94b07c139b47ef3379e7e5d48e832c2b27fd8e19348c5e1ab7394
|
data/lib/envoy/client/command.rb
CHANGED
@@ -33,7 +33,7 @@ def load_config
|
|
33
33
|
conf["dir"] = File.expand_path(conf["dir"], path + "/..") if conf["dir"]
|
34
34
|
end
|
35
35
|
else
|
36
|
-
[{
|
36
|
+
[{}]
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -42,8 +42,8 @@ options = parse_options
|
|
42
42
|
unless EM.reactor_running?
|
43
43
|
EM.run do
|
44
44
|
load_config.each do |config|
|
45
|
-
config =
|
46
|
-
config["local_port"] ||= rand(16383) + 49152
|
45
|
+
config = config.merge(options)
|
46
|
+
config["local_port"] ||= config["command"] ? rand(16383) + 49152 : 80
|
47
47
|
config["hosts"] ||= [config.delete("host")] if config["host"]
|
48
48
|
config = config.each_with_object({}) do |(k, v), h|
|
49
49
|
h[k.to_sym] = v
|
@@ -51,4 +51,4 @@ unless EM.reactor_running?
|
|
51
51
|
Envoy::Client::Trunk.start config
|
52
52
|
end
|
53
53
|
end
|
54
|
-
end
|
54
|
+
end
|
@@ -16,41 +16,39 @@ end
|
|
16
16
|
def parse_options
|
17
17
|
options = default_options
|
18
18
|
OptionParser.new do |op|
|
19
|
-
op.banner = "Usage: #{$0} [options] [[HOST:]PORT]"
|
20
|
-
op.on "--
|
19
|
+
op.banner = "Usage: #{$0} [options] [[HOST:]PORT] [LABEL]"
|
20
|
+
op.on "-l LABEL", "--label", "--host", "Allocate this domain label on the proxy" do |v|
|
21
21
|
options["hosts"] ||= []
|
22
22
|
options["hosts"] << v
|
23
23
|
end
|
24
|
-
op.on "-k", "--key
|
24
|
+
op.on "-k KEY", "--key", "Secure access to the label with this key" do |v|
|
25
25
|
options["key"] = v
|
26
26
|
end
|
27
|
-
op.on "-
|
28
|
-
options["tls"] = v
|
29
|
-
end
|
30
|
-
op.on "-s", "--server SERVER", "Specify envoy/proxylocal server" do |v|
|
27
|
+
op.on "-s SERVER", "--server", "Specify envoy server" do |v|
|
31
28
|
host, port = v.split(":")
|
32
29
|
options["server_host"] = host
|
33
30
|
options["server_port"] ||= port
|
34
31
|
end
|
35
|
-
op.on "-
|
36
|
-
options["
|
37
|
-
end
|
38
|
-
op.on "--no-log", "Don't show HTTP log" do |v|
|
39
|
-
options["log"] = false
|
40
|
-
end
|
41
|
-
op.on "l", "--log FILE", "Write HTTP log to this file" do |v|
|
42
|
-
options["log"] = v
|
32
|
+
op.on "-c COMMAND", "Run this command" do |v|
|
33
|
+
options["command"] = v
|
43
34
|
end
|
44
35
|
op.on "-h", "--help", "Show this message" do
|
45
36
|
puts op
|
46
37
|
exit
|
47
38
|
end
|
48
|
-
op.on "--version" do
|
39
|
+
op.on "-V", "--version", "Show version number" do
|
49
40
|
puts Envoy::VERSION
|
50
41
|
exit
|
51
42
|
end
|
52
43
|
op.parse!
|
53
44
|
case ARGV[0]
|
45
|
+
when "rails"
|
46
|
+
options["pidfile"] = "tmp/pids/server.pid"
|
47
|
+
options["command"] = "rails s -p %{local_port}"
|
48
|
+
options["delay"] = 10
|
49
|
+
when "rackup"
|
50
|
+
options["command"] = "rackup -p %{local_port}"
|
51
|
+
options["delay"] = 10
|
54
52
|
when /^(\d+)$/
|
55
53
|
options["local_port"] = $1
|
56
54
|
when /^(\[[^\]+]\]|[^:]+):(\d+)$/x
|
@@ -59,6 +57,10 @@ def parse_options
|
|
59
57
|
when /^(.*)$/
|
60
58
|
options["local_host"] = $1
|
61
59
|
end
|
60
|
+
if ARGV[1]
|
61
|
+
options["hosts"] ||= []
|
62
|
+
options["hosts"] << ARGV[1]
|
63
|
+
end
|
62
64
|
end
|
63
65
|
options
|
64
66
|
end
|
data/lib/envoy/server/trunk.rb
CHANGED
@@ -77,6 +77,8 @@ module Envoy
|
|
77
77
|
end
|
78
78
|
if version? "< #{Envoy::VERSION}"
|
79
79
|
send_object :message, "Your client is out of date. Please upgrade to #{Envoy::VERSION}."
|
80
|
+
elsif version? "> #{Envoy::VERSION}"
|
81
|
+
send_object :message, "Your client is from the future. The server is expecting #{Envoy::VERSION}."
|
80
82
|
end
|
81
83
|
if @key and @key != @options[:key]
|
82
84
|
halt "Key is invalid"
|
@@ -85,14 +87,14 @@ module Envoy
|
|
85
87
|
hosts = @options[:hosts] || []
|
86
88
|
hosts.any? do |label|
|
87
89
|
if label == "s"
|
88
|
-
send_object :message, "
|
90
|
+
send_object :message, "label is reserved: `#{label}'"
|
89
91
|
true
|
90
92
|
elsif label =~ /\./
|
91
|
-
send_object :message, "
|
93
|
+
send_object :message, "label is invalid: `#{label}'"
|
92
94
|
true
|
93
95
|
elsif other_trunk = Trunk.trunks[label][0]
|
94
96
|
unless other_trunk.key == key
|
95
|
-
send_object :message, "
|
97
|
+
send_object :message, "label is protected with a key: `#{label}'"
|
96
98
|
true
|
97
99
|
end
|
98
100
|
end
|
@@ -101,12 +103,11 @@ module Envoy
|
|
101
103
|
m = ["#{options[:local_host]}:#{options[:local_port]} now available at:"]
|
102
104
|
@hosts = hosts.each do |host|
|
103
105
|
Trunk.trunks[host] << self
|
104
|
-
|
106
|
+
send_object :message, "host: #{host}.#{$zone}"
|
105
107
|
end
|
106
|
-
send_object :message, m.join(" ")
|
107
108
|
unless @options[:key]
|
108
109
|
@options[:key] ||= SecureRandom.hex(8)
|
109
|
-
send_object :message, "
|
110
|
+
send_object :message, "key: #{@options[:key]}"
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
data/lib/envoy/server/web.rb
CHANGED
@@ -11,17 +11,24 @@ module Envoy
|
|
11
11
|
@connection = "close"
|
12
12
|
end
|
13
13
|
|
14
|
-
def send_page status, message
|
14
|
+
def send_page status, title, message
|
15
15
|
send_data "HTTP/1.0 #{status} Message\r\n"
|
16
|
-
send_data "Content-Type: text/
|
16
|
+
send_data "Content-Type: text/html\r\n"
|
17
17
|
send_data "\r\n"
|
18
|
-
send_data "
|
18
|
+
send_data "<title>#{title}</title>\r\n"
|
19
|
+
send_data "<h1>#{title}</h1>\r\n"
|
20
|
+
send_data "<p>#{message}\r\n"
|
21
|
+
end
|
22
|
+
|
23
|
+
def fail (status, title, message)
|
24
|
+
send_page(500, title, message)
|
25
|
+
close_connection true
|
19
26
|
end
|
20
27
|
|
21
28
|
def close code
|
22
29
|
case code
|
23
30
|
when 502
|
24
|
-
send_page
|
31
|
+
send_page 502, "Bad Gateway", "The service isn't running, and couldn't be started."
|
25
32
|
end
|
26
33
|
close_connection(true)
|
27
34
|
end
|
@@ -33,7 +40,7 @@ module Envoy
|
|
33
40
|
def receive_line line
|
34
41
|
@first_line ||= line
|
35
42
|
if line == ""
|
36
|
-
trunk = Trunk.trunks[@host].sample ||
|
43
|
+
trunk = Trunk.trunks[@host].sample || (return fail(404, "Not Found", "No trunk for #{@host}.#{$zone}"))
|
37
44
|
@header << "Connection: #{@connection}\r\n\r\n"
|
38
45
|
@channel = Channel.new(trunk, self, @header)
|
39
46
|
@channel.message "%s %s" % [Socket.unpack_sockaddr_in(get_peername)[1], @first_line]
|
@@ -48,12 +55,12 @@ module Envoy
|
|
48
55
|
@host = @host.split(".").last
|
49
56
|
@header << line + "\r\n"
|
50
57
|
elsif @header.size > 4096
|
51
|
-
|
58
|
+
return fail(400, "Bad Request", "Header's too long for my liking")
|
52
59
|
else
|
53
60
|
@header << line + "\r\n"
|
54
61
|
end
|
55
62
|
rescue RuntimeError => e
|
56
|
-
send_page 500, e.inspect
|
63
|
+
send_page 500, "Internal Server Error", e.inspect
|
57
64
|
close_connection true
|
58
65
|
end
|
59
66
|
|
data/lib/envoy/version.rb
CHANGED
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envoy-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Baum
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bert
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.1'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.3'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description:
|
@@ -75,7 +75,7 @@ executables:
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
- .gitignore
|
78
|
+
- ".gitignore"
|
79
79
|
- Gemfile
|
80
80
|
- LICENSE.txt
|
81
81
|
- README.md
|
@@ -103,17 +103,17 @@ require_paths:
|
|
103
103
|
- lib
|
104
104
|
required_ruby_version: !ruby/object:Gem::Requirement
|
105
105
|
requirements:
|
106
|
-
- -
|
106
|
+
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
|
-
- -
|
111
|
+
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.
|
116
|
+
rubygems_version: 2.2.2
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: Proxy your local web-server and make it publicly available over the internet
|