envoy-proxy 0.2.3 → 1.0.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/bin/envoy +2 -0
- data/lib/envoy/client/channel.rb +4 -30
- data/lib/envoy/client/command.rb +15 -54
- data/lib/envoy/client/config.rb +94 -0
- data/lib/envoy/client/config/builder.rb +51 -0
- data/lib/envoy/client/trunk.rb +39 -44
- data/lib/envoy/protocol.rb +0 -13
- data/lib/envoy/server/command.rb +1 -0
- data/lib/envoy/server/trunk.rb +41 -36
- data/lib/envoy/utils.rb +40 -0
- data/lib/envoy/version.rb +1 -1
- metadata +5 -3
- data/lib/envoy/client/option_parser.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79aa6508c84fc016f6cd86578c4fc3c2e4c56bb7
|
4
|
+
data.tar.gz: 0756f96ffcc9738416d2f72478dd081938e7c881
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3669908f7d9b5cdde77f905b419213190164082d8750223b06b12574d91b86e7306beefa9c9ea69ca08c3498751da947eaabec8e05d572c41bb4065cfcda092c
|
7
|
+
data.tar.gz: 06434fb4ffbf9ebcf082d4118b1fd2323be2437284f13f4b06a6791f36e9dcdd6f9b835fd6ade6c20ab4de335268b9fff82fe5e14dcbd70f4fbb2cee1ab0428a
|
data/bin/envoy
CHANGED
@@ -3,9 +3,11 @@
|
|
3
3
|
|
4
4
|
begin
|
5
5
|
require 'envoy/client/command'
|
6
|
+
Envoy::Client::Command.new.run(ARGV)
|
6
7
|
rescue LoadError
|
7
8
|
path = File.expand_path '../../lib', __FILE__
|
8
9
|
$:.unshift path if File.directory?(path)
|
9
10
|
require 'envoy/client/command'
|
11
|
+
Envoy::Client::Command.new.run(ARGV)
|
10
12
|
end
|
11
13
|
|
data/lib/envoy/client/channel.rb
CHANGED
@@ -38,39 +38,13 @@ module Envoy
|
|
38
38
|
|
39
39
|
def unbind e
|
40
40
|
if e == Errno::ECONNREFUSED
|
41
|
-
@client.log
|
42
|
-
|
43
|
-
if Time.now > @tried_starting + @client.options[:delay]
|
44
|
-
@client.log ERROR, "Service isn't running, but starting it didn't really work out."
|
45
|
-
@client.send_object :close, @id, 502
|
46
|
-
@tried_starting = false
|
47
|
-
else
|
48
|
-
EM.add_timer 0.1 do
|
49
|
-
reconnect
|
50
|
-
end
|
51
|
-
end
|
52
|
-
elsif cmd = @client.options[:command]
|
53
|
-
cmd = cmd % @client.options
|
54
|
-
@client.log INFO, "Service doesn't seem to be running. Trying to start it now..."
|
55
|
-
@tried_starting = Time.now
|
56
|
-
p @client.options[:dir]
|
57
|
-
Dir.chdir File.expand_path(@client.options[:dir]) do
|
58
|
-
fork do
|
59
|
-
ENV.delete("GEM_HOME")
|
60
|
-
ENV.delete("GEM_PATH")
|
61
|
-
ENV.delete("BUNDLE_BIN_PATH")
|
62
|
-
ENV.delete("BUNDLE_GEMFILE")
|
63
|
-
system cmd
|
64
|
-
end
|
65
|
-
end
|
66
|
-
EM.add_timer 0.1 do
|
67
|
-
reconnect
|
68
|
-
end
|
69
|
-
end
|
41
|
+
@client.log ERROR, "couldn't connect to upstream service for stream #{@id}"
|
42
|
+
@client.send_object :close, @id
|
70
43
|
elsif e
|
71
44
|
@client.log ERROR, e.inspect
|
45
|
+
@client.send_object :close, @id
|
72
46
|
else
|
73
|
-
@client.log
|
47
|
+
@client.log DEBUG, "upstream service closed stream #{@id}"
|
74
48
|
@client.send_object :close, @id
|
75
49
|
end
|
76
50
|
end
|
data/lib/envoy/client/command.rb
CHANGED
@@ -1,62 +1,23 @@
|
|
1
1
|
require 'envoy/client/trunk'
|
2
|
-
require 'envoy/client/
|
2
|
+
require 'envoy/client/config'
|
3
3
|
require 'envoy/version'
|
4
|
-
require 'yaml'
|
5
4
|
|
6
|
-
|
7
|
-
dirs = Dir.pwd.split("/")
|
8
|
-
r = dirs.reduce([]) do |m, x|
|
9
|
-
[[*m[0], x], *m]
|
10
|
-
end.map do |p|
|
11
|
-
p.join("/") + "/.envoy"
|
12
|
-
end.each do |p|
|
13
|
-
return p if File.exist?(p)
|
14
|
-
end
|
15
|
-
false
|
16
|
-
end
|
17
|
-
|
18
|
-
def load_config
|
19
|
-
if path = find_config
|
20
|
-
conf = YAML.load(File.read(path))
|
21
|
-
Array(conf).each do |conf|
|
22
|
-
if conf["rails"]
|
23
|
-
conf["dir"] = conf["rails"]
|
24
|
-
conf["pidfile"] = "tmp/pids/server.pid"
|
25
|
-
conf["command"] = "rails s -p %{local_port}"
|
26
|
-
conf["delay"] = 10
|
27
|
-
elsif conf["rackup"]
|
28
|
-
conf["dir"] = conf["rackup"]
|
29
|
-
conf["command"] = "rackup -p %{local_port}"
|
30
|
-
conf["delay"] = 10
|
31
|
-
end
|
32
|
-
conf["host"] ||= conf["dir"].split("/")[-1] if conf["dir"]
|
33
|
-
conf["dir"] = File.expand_path(conf["dir"], path + "/..") if conf["dir"]
|
34
|
-
end
|
35
|
-
else
|
36
|
-
[{}]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
options = parse_options
|
5
|
+
class Envoy::Client::Command
|
41
6
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
$exiting = true
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
config
|
54
|
-
config["local_port"] ||= config["command"] ? rand(16383) + 49152 : 80
|
55
|
-
config["hosts"] ||= [config.delete("host")] if config["host"]
|
56
|
-
config = config.each_with_object({}) do |(k, v), h|
|
57
|
-
h[k.to_sym] = v
|
58
|
-
end
|
7
|
+
def run (args)
|
8
|
+
EM.run do
|
9
|
+
Envoy.verbosity = Envoy::INFO
|
10
|
+
stopper = proc { $exiting = true; EventMachine.stop }
|
11
|
+
Signal.trap("INT", stopper)
|
12
|
+
Signal.trap("TERM", stopper)
|
13
|
+
Envoy.log(Envoy::DEBUG, "envoy #{Envoy::VERSION} starting up")
|
14
|
+
config = Envoy::Client::Config.new
|
15
|
+
config.parse_options
|
16
|
+
config.parse_envoyfile
|
17
|
+
config.infer_sane_defaults
|
18
|
+
config.start_service
|
59
19
|
Envoy::Client::Trunk.start config
|
60
20
|
end
|
61
21
|
end
|
22
|
+
|
62
23
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'envoy/client/config/builder'
|
2
|
+
require 'envoy/utils'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
class Envoy::Client::Config
|
6
|
+
|
7
|
+
attr_accessor :server
|
8
|
+
attr_accessor :key
|
9
|
+
attr_accessor :label
|
10
|
+
attr_accessor :command
|
11
|
+
attr_accessor :export
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@server = ["p45.eu", 8282]
|
15
|
+
@key = ENV["ENVOY_KEY"] || SecureRandom.base64(8)
|
16
|
+
end
|
17
|
+
|
18
|
+
def options
|
19
|
+
{
|
20
|
+
hosts: [label].compact,
|
21
|
+
key: key,
|
22
|
+
verbosity: true,
|
23
|
+
version: Envoy::VERSION
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def start_service
|
28
|
+
return unless command
|
29
|
+
Envoy.log Envoy::INFO, "Starting service..."
|
30
|
+
fork do
|
31
|
+
ENV.delete("GEM_HOME")
|
32
|
+
ENV.delete("GEM_PATH")
|
33
|
+
ENV.delete("BUNDLE_BIN_PATH")
|
34
|
+
ENV.delete("BUNDLE_GEMFILE")
|
35
|
+
system(command)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def infer_sane_defaults
|
40
|
+
self.export = [:tcp, "127.0.0.1", 80] unless export
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_envoyfile
|
44
|
+
if path = Envoy.find_file("Envoyfile")
|
45
|
+
Builder.new(self).run(path)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_options
|
50
|
+
OptionParser.new do |op|
|
51
|
+
op.banner = "Usage: #{$0} [options]"
|
52
|
+
op.on "-l LABEL", "Use this domain label" do |lab|
|
53
|
+
@label = lab
|
54
|
+
end
|
55
|
+
op.on "-d DIRECTORY", "Change to this directory before starting envoy" do |dir|
|
56
|
+
Dir.chdir(dir)
|
57
|
+
end
|
58
|
+
op.on "-k KEY", "Secure access to the label with this key" do |v|
|
59
|
+
@key = v
|
60
|
+
end
|
61
|
+
op.on "-s SERVER", "Specify envoy server" do |v|
|
62
|
+
host, port = v.split(":")
|
63
|
+
@server = [host, port || @server[1]]
|
64
|
+
end
|
65
|
+
op.on "-v", "Show messages. Repeat to show more." do
|
66
|
+
Envoy.verbosity += 1
|
67
|
+
end
|
68
|
+
op.on "-q", "Hide messages. Repeat to hide more." do
|
69
|
+
Envoy.verbosity -= 1
|
70
|
+
end
|
71
|
+
op.on "-h", "Show this message" do
|
72
|
+
puts op
|
73
|
+
exit
|
74
|
+
end
|
75
|
+
op.on "-V", "Show version number" do
|
76
|
+
puts Envoy::VERSION
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
op.parse!
|
80
|
+
case ARGV[0]
|
81
|
+
when nil
|
82
|
+
when /\//
|
83
|
+
@export = [:unix, ARGV[0]]
|
84
|
+
when /^([^:]+):(\d+)$/
|
85
|
+
@export = [:tcp, $1 || "127.0.0.1", $2]
|
86
|
+
when /^(\d+)$/
|
87
|
+
@export = [:tcp, "127.0.0.1", $1]
|
88
|
+
else
|
89
|
+
@export = [:tcp, ARGV[0], 80]
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Envoy::Client::Config; end
|
2
|
+
|
3
|
+
class Envoy::Client::Config::Builder
|
4
|
+
|
5
|
+
def initialize (config)
|
6
|
+
@config = config
|
7
|
+
end
|
8
|
+
|
9
|
+
def run (path)
|
10
|
+
instance_eval(File.read(path), path)
|
11
|
+
end
|
12
|
+
|
13
|
+
def set (name, value)
|
14
|
+
@config.__send__("#{name}=", value)
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch (name, &block)
|
18
|
+
if r = @config.__send__(name)
|
19
|
+
r
|
20
|
+
elsif block
|
21
|
+
set(name, block.())
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def export (type, *args)
|
26
|
+
case type
|
27
|
+
when :tcp
|
28
|
+
args = args[0].split(":") if args[0] and !args[1]
|
29
|
+
args[0] ||= "127.0.0.1"
|
30
|
+
args[1] ||= rand(16383) + 49152
|
31
|
+
args = [:tcp, *args]
|
32
|
+
when :unix
|
33
|
+
args[0] ||= ".envoy.sock"
|
34
|
+
args = [:unix, *args]
|
35
|
+
end
|
36
|
+
set :export, args
|
37
|
+
end
|
38
|
+
|
39
|
+
def localsock ()
|
40
|
+
export(:unix)[1]
|
41
|
+
end
|
42
|
+
|
43
|
+
def localhost
|
44
|
+
export(:tcp)[1]
|
45
|
+
end
|
46
|
+
|
47
|
+
def localport ()
|
48
|
+
export(:tcp)[2]
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/envoy/client/trunk.rb
CHANGED
@@ -8,19 +8,17 @@ module Envoy
|
|
8
8
|
module Trunk
|
9
9
|
include Protocol
|
10
10
|
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :config
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
State = Struct.new(:connected, :reconnects)
|
14
|
+
|
15
|
+
def self.start (config, state = State.new(false, 0))
|
16
|
+
EM.connect(*config.server, Envoy::Client::Trunk, config, state)
|
15
17
|
end
|
16
18
|
|
17
|
-
def initialize
|
18
|
-
@
|
19
|
-
@
|
20
|
-
if @options.has_key?(:log)
|
21
|
-
@log = @options[:log] && File.open(@options[:log], "a")
|
22
|
-
end
|
23
|
-
log DEBUG, "envoy #{Envoy::VERSION} starting up"
|
19
|
+
def initialize (config, state)
|
20
|
+
@config = config
|
21
|
+
@state = state
|
24
22
|
end
|
25
23
|
|
26
24
|
def channels
|
@@ -33,46 +31,43 @@ module Envoy
|
|
33
31
|
end
|
34
32
|
|
35
33
|
def receive_close id
|
34
|
+
return unless channels[id]
|
36
35
|
log TRACE, "closed stream #{id}"
|
37
36
|
channels[id].close_connection true
|
38
37
|
channels.delete(id)
|
39
38
|
end
|
40
39
|
|
41
40
|
def receive_stream id, data
|
41
|
+
return unless channels[id]
|
42
42
|
log TRACE, "#{data.length} bytes of data received on stream #{id}"
|
43
43
|
channels[id].send_data data
|
44
44
|
end
|
45
45
|
|
46
46
|
def receive_connection id
|
47
47
|
log TRACE, "New connection request with id `#{id}'"
|
48
|
-
channels[id] =
|
49
|
-
|
48
|
+
channels[id] = case @config.export[0]
|
49
|
+
when :tcp
|
50
|
+
EM.connect(*@config.export[1, 2], Channel, id, self)
|
51
|
+
when :unix
|
52
|
+
EM.connect_unix_domain(*@config.export[1], Channel, id, self)
|
53
|
+
else
|
54
|
+
raise @config.export[0].inspect
|
55
|
+
end
|
56
|
+
rescue
|
57
|
+
send_object :close, id
|
50
58
|
end
|
51
59
|
|
52
60
|
def receive_keepalive
|
53
61
|
end
|
54
62
|
|
55
|
-
def log (level, text, io = @log)
|
56
|
-
return unless io
|
57
|
-
return unless level <= verbosity
|
58
|
-
message = [
|
59
|
-
@options[:timestamps] ? Time.now.strftime("%F %T") : nil,
|
60
|
-
@options[:show_log_level] ? "#{VERBOSITIES[level][0]}:" : nil,
|
61
|
-
text
|
62
|
-
].compact.join(" ")
|
63
|
-
if @options[:color_log_level]
|
64
|
-
#FATAL ERROR WARN\ INFO\ DEBUG TRACE
|
65
|
-
message = message.colorize(%i"red red yellow green default light_black"[level])
|
66
|
-
end
|
67
|
-
io.puts message
|
68
|
-
io.flush
|
69
|
-
end
|
70
|
-
|
71
63
|
def receive_message text, level = INFO
|
72
64
|
log level, text
|
73
65
|
end
|
74
66
|
|
75
67
|
def receive_ping
|
68
|
+
unless @state.connected
|
69
|
+
ssl_handshake_completed
|
70
|
+
end
|
76
71
|
log TRACE, "Server pinged. Ponging back."
|
77
72
|
send_object :pong
|
78
73
|
end
|
@@ -86,39 +81,39 @@ module Envoy
|
|
86
81
|
log DEBUG, "Server confirmed our request. Proxy set up."
|
87
82
|
end
|
88
83
|
|
84
|
+
def log (*args)
|
85
|
+
Envoy.log(*args)
|
86
|
+
end
|
87
|
+
|
89
88
|
def unbind
|
90
89
|
if @halting
|
91
90
|
log DEBUG, "Shutting down because server told us to."
|
92
91
|
elsif $exiting
|
93
92
|
log DEBUG, "Shutting down because the local system told us to."
|
94
|
-
elsif
|
95
|
-
log WARN, "Lost connection. Retrying..." if
|
93
|
+
elsif @state.connected
|
94
|
+
log WARN, "Lost connection. Retrying..." if @state.reconnects == 0
|
96
95
|
EM.add_timer 0.5 do
|
97
|
-
@
|
98
|
-
Trunk.start @
|
96
|
+
@state.reconnects += 1
|
97
|
+
Trunk.start(@config, @state)
|
99
98
|
end
|
100
99
|
else
|
101
|
-
|
102
|
-
log FATAL, "Connection lost. Not point reconnecting because the host is randomly generated."
|
103
|
-
else
|
104
|
-
log FATAL, "Couldn't connect. Abandoning ship."
|
105
|
-
end
|
100
|
+
log FATAL, "Couldn't connect. Abandoning ship."
|
106
101
|
EventMachine.stop_event_loop
|
107
102
|
end
|
108
103
|
end
|
109
104
|
|
110
105
|
def ssl_handshake_completed
|
111
106
|
log DEBUG, "Channel is secure, sending options"
|
112
|
-
|
113
|
-
options
|
114
|
-
|
115
|
-
log DEBUG, "Exporting #{@options[:local_host]}:#{@options[:local_port]}"
|
107
|
+
@state.connected = true
|
108
|
+
send_object :options, @config.options
|
109
|
+
log DEBUG, "Exporting #{@config.export.join(":")}"
|
116
110
|
end
|
117
111
|
|
118
112
|
def post_init
|
119
|
-
self.comm_inactivity_timeout =
|
120
|
-
log
|
121
|
-
send_object :start_tls
|
113
|
+
self.comm_inactivity_timeout = 60
|
114
|
+
log TRACE, "Requesting TLS negotiation."
|
115
|
+
#send_object :start_tls
|
116
|
+
send_object :pong
|
122
117
|
end
|
123
118
|
|
124
119
|
end
|
data/lib/envoy/protocol.rb
CHANGED
@@ -1,24 +1,11 @@
|
|
1
1
|
require 'eventmachine'
|
2
2
|
require 'bert'
|
3
3
|
|
4
|
-
TRACE = 5
|
5
|
-
DEBUG = 4
|
6
|
-
INFO = 3
|
7
|
-
WARN = 2
|
8
|
-
ERROR = 1
|
9
|
-
FATAL = 0
|
10
|
-
|
11
4
|
module Envoy
|
12
5
|
|
13
6
|
module Protocol
|
14
7
|
include EM::P::ObjectProtocol
|
15
8
|
|
16
|
-
VERBOSITIES = %w"FATAL ERROR WARN\ INFO\ DEBUG TRACE"
|
17
|
-
|
18
|
-
def verbosity
|
19
|
-
@verbosity ||= [FATAL, [TRACE, @options[:verbosity] || 3].min].max
|
20
|
-
end
|
21
|
-
|
22
9
|
module Serializer
|
23
10
|
def self.dump(object)
|
24
11
|
BERT.encode(object)
|
data/lib/envoy/server/command.rb
CHANGED
data/lib/envoy/server/trunk.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'envoy/protocol'
|
2
|
+
require 'envoy/utils'
|
2
3
|
|
3
4
|
module Envoy
|
4
5
|
module Server
|
@@ -26,37 +27,12 @@ module Envoy
|
|
26
27
|
@channels ||= {}
|
27
28
|
end
|
28
29
|
|
29
|
-
def receive_pong
|
30
|
-
EM.add_timer 30 do
|
31
|
-
send_object :ping
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def receive_close id, code = nil
|
36
|
-
if chan = channels[id]
|
37
|
-
chan.web.close(code)
|
38
|
-
channels.delete id
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def receive_start_tls
|
43
|
-
send_object :start_tls
|
44
|
-
start_tls
|
45
|
-
end
|
46
|
-
|
47
|
-
def receive_stream id, data
|
48
|
-
c = channels[id]
|
49
|
-
w = c && c.web
|
50
|
-
w && w.send_data(data)
|
51
|
-
end
|
52
|
-
|
53
30
|
def key
|
54
31
|
@options[:key]
|
55
32
|
end
|
56
33
|
|
57
|
-
def log
|
58
|
-
|
59
|
-
STDERR.puts t + " " + message.split("\n").join("\n#{t.gsub(/./, ' ')} ")
|
34
|
+
def log (*args)
|
35
|
+
Envoy.log(*args)
|
60
36
|
end
|
61
37
|
|
62
38
|
def message (level, message)
|
@@ -68,7 +44,7 @@ module Envoy
|
|
68
44
|
end
|
69
45
|
|
70
46
|
def halt message = nil
|
71
|
-
message FATAL, message if message
|
47
|
+
message Envoy::FATAL, message if message
|
72
48
|
send_object :halt
|
73
49
|
close_connection(true)
|
74
50
|
end
|
@@ -77,13 +53,42 @@ module Envoy
|
|
77
53
|
Gem::Requirement.new(*requirement) =~ Gem::Version.new(@options[:version])
|
78
54
|
end
|
79
55
|
|
56
|
+
def receive_pong
|
57
|
+
unless @pinged
|
58
|
+
send_object :ping
|
59
|
+
@pinged = true
|
60
|
+
else
|
61
|
+
EM.add_timer 30 do
|
62
|
+
send_object :ping
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def receive_close id, code = nil
|
68
|
+
if chan = channels[id]
|
69
|
+
chan.web.close(code)
|
70
|
+
channels.delete id
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def receive_start_tls
|
75
|
+
send_object :start_tls
|
76
|
+
start_tls
|
77
|
+
end
|
78
|
+
|
79
|
+
def receive_stream id, data
|
80
|
+
c = channels[id]
|
81
|
+
w = c && c.web
|
82
|
+
w && w.send_data(data)
|
83
|
+
end
|
84
|
+
|
80
85
|
def receive_options options
|
81
86
|
@options = options
|
82
87
|
receive_pong if version? "> 0.1"
|
83
88
|
if version? "< #{Envoy::VERSION}"
|
84
|
-
message WARN, "Your client is out of date. Please upgrade to #{Envoy::VERSION}."
|
89
|
+
message Envoy::WARN, "Your client is out of date. Please upgrade to #{Envoy::VERSION}."
|
85
90
|
elsif version? "> #{Envoy::VERSION}"
|
86
|
-
message WARN, "Your client is from the future. The server is expecting #{Envoy::VERSION}."
|
91
|
+
message Envoy::WARN, "Your client is from the future. The server is expecting #{Envoy::VERSION}."
|
87
92
|
end
|
88
93
|
if @key and @key != @options[:key]
|
89
94
|
halt "Key is invalid"
|
@@ -92,30 +97,30 @@ module Envoy
|
|
92
97
|
hosts = @options[:hosts] || []
|
93
98
|
hosts.any? do |label|
|
94
99
|
if label == "s"
|
95
|
-
message FATAL, "label is reserved: `#{label}'"
|
100
|
+
message Envoy::FATAL, "label is reserved: `#{label}'"
|
96
101
|
true
|
97
102
|
elsif label =~ /\./
|
98
|
-
message FATAL, "label is invalid: `#{label}'"
|
103
|
+
message Envoy::FATAL, "label is invalid: `#{label}'"
|
99
104
|
true
|
100
105
|
elsif other_trunk = Trunk.trunks[label][0]
|
101
106
|
unless other_trunk.key == key
|
102
|
-
message FATAL, "label is protected with a key: `#{label}'"
|
107
|
+
message Envoy::FATAL, "label is protected with a key: `#{label}'"
|
103
108
|
true
|
104
109
|
end
|
105
110
|
end
|
106
111
|
end && halt
|
107
112
|
if hosts.empty?
|
108
113
|
hosts = [SecureRandom.random_number(36 ** 4).to_s(36)]
|
109
|
-
message INFO, "Service accessible at http://#{hosts[0]}.#{$zone}/"
|
114
|
+
message Envoy::INFO, "Service accessible at http://#{hosts[0]}.#{$zone}/"
|
110
115
|
else
|
111
116
|
@hosts = hosts.each do |host|
|
112
117
|
Trunk.trunks[host] << self
|
113
|
-
message INFO, "Service accessible at http://#{host}.#{$zone}/"
|
118
|
+
message Envoy::INFO, "Service accessible at http://#{host}.#{$zone}/"
|
114
119
|
end
|
115
120
|
end
|
116
121
|
unless @options[:key]
|
117
122
|
@options[:key] = SecureRandom.hex(8)
|
118
|
-
message INFO, "Service access key is `#{@options[:key]}'"
|
123
|
+
message Envoy::INFO, "Service access key is `#{@options[:key]}'"
|
119
124
|
end
|
120
125
|
send_object :confirm, @options if version? ">= 0.2.2"
|
121
126
|
end
|
data/lib/envoy/utils.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Envoy
|
2
|
+
|
3
|
+
TRACE = 5
|
4
|
+
DEBUG = 4
|
5
|
+
INFO = 3
|
6
|
+
WARN = 2
|
7
|
+
ERROR = 1
|
8
|
+
FATAL = 0
|
9
|
+
|
10
|
+
VERBOSITIES = "FEWIDT"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :verbosity
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.log (level, text, io = STDERR)
|
17
|
+
return unless io
|
18
|
+
return unless level <= verbosity
|
19
|
+
message = [
|
20
|
+
Time.now.strftime("%F %T"),
|
21
|
+
VERBOSITIES[level][0],
|
22
|
+
text
|
23
|
+
].compact.join(" ")
|
24
|
+
io.puts message
|
25
|
+
io.flush
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.find_file (name)
|
29
|
+
dirs = Dir.pwd.split("/")
|
30
|
+
r = dirs.reduce([]) do |m, x|
|
31
|
+
[[*m[0], x], *m]
|
32
|
+
end.map do |p|
|
33
|
+
p.join("/") + "/#{name}"
|
34
|
+
end.each do |p|
|
35
|
+
return p if File.exist?(p)
|
36
|
+
end
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/envoy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envoy-proxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.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: 2014-07-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -99,13 +99,15 @@ files:
|
|
99
99
|
- envoy-proxy.gemspec
|
100
100
|
- lib/envoy/client/channel.rb
|
101
101
|
- lib/envoy/client/command.rb
|
102
|
-
- lib/envoy/client/
|
102
|
+
- lib/envoy/client/config.rb
|
103
|
+
- lib/envoy/client/config/builder.rb
|
103
104
|
- lib/envoy/client/trunk.rb
|
104
105
|
- lib/envoy/protocol.rb
|
105
106
|
- lib/envoy/server/channel.rb
|
106
107
|
- lib/envoy/server/command.rb
|
107
108
|
- lib/envoy/server/trunk.rb
|
108
109
|
- lib/envoy/server/web.rb
|
110
|
+
- lib/envoy/utils.rb
|
109
111
|
- lib/envoy/version.rb
|
110
112
|
homepage: ''
|
111
113
|
licenses:
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
|
3
|
-
def default_options
|
4
|
-
{
|
5
|
-
"server_host" => 'p45.eu',
|
6
|
-
"server_port" => "8282",
|
7
|
-
"local_host" => '127.0.0.1',
|
8
|
-
"tls" => false,
|
9
|
-
"verbosity" => 3,
|
10
|
-
"version" => Envoy::VERSION,
|
11
|
-
"delay" => 1,
|
12
|
-
"dir" => ".",
|
13
|
-
"timestamps" => false,
|
14
|
-
"show_log_level" => true,
|
15
|
-
"color_log_level" => true,
|
16
|
-
}
|
17
|
-
end
|
18
|
-
|
19
|
-
def parse_options
|
20
|
-
options = default_options
|
21
|
-
OptionParser.new do |op|
|
22
|
-
op.banner = "Usage: #{$0} [options] [[HOST:]PORT] [LABEL]"
|
23
|
-
op.on "-l LABEL", "--label", "--host", "Allocate this domain label on the proxy" do |v|
|
24
|
-
options["hosts"] ||= []
|
25
|
-
options["hosts"] << v
|
26
|
-
end
|
27
|
-
op.on "-k KEY", "--key", "Secure access to the label with this key" do |v|
|
28
|
-
options["key"] = v
|
29
|
-
end
|
30
|
-
op.on "-s SERVER", "--server", "Specify envoy server" do |v|
|
31
|
-
host, port = v.split(":")
|
32
|
-
options["server_host"] = host
|
33
|
-
options["server_port"] ||= port
|
34
|
-
end
|
35
|
-
op.on "-c COMMAND", "Run this command" do |v|
|
36
|
-
options["command"] = v
|
37
|
-
end
|
38
|
-
op.on "-v", "--verbose", "Show messages. Repeat to show more." do
|
39
|
-
options["verbosity"] += 1
|
40
|
-
end
|
41
|
-
op.on "-q", "--quiet", "Hide messages. Repeat to hide more." do
|
42
|
-
options["verbosity"] -= 1
|
43
|
-
end
|
44
|
-
op.on "-h", "--help", "Show this message" do
|
45
|
-
puts op
|
46
|
-
exit
|
47
|
-
end
|
48
|
-
op.on "-V", "--version", "Show version number" do
|
49
|
-
puts Envoy::VERSION
|
50
|
-
exit
|
51
|
-
end
|
52
|
-
op.parse!
|
53
|
-
case ARGV[0]
|
54
|
-
when "rails"
|
55
|
-
options["pidfile"] = "tmp/pids/server.pid"
|
56
|
-
options["command"] = "rails s -p %{local_port}"
|
57
|
-
options["delay"] = 10
|
58
|
-
when "rackup"
|
59
|
-
options["command"] = "rackup -p %{local_port}"
|
60
|
-
options["delay"] = 10
|
61
|
-
when /^(\d+)$/
|
62
|
-
options["local_port"] = $1
|
63
|
-
when /^(\[[^\]+]\]|[^:]+):(\d+)$/x
|
64
|
-
options["local_host"] = $1
|
65
|
-
options["local_port"] = $2
|
66
|
-
when /^(.*)$/
|
67
|
-
options["local_host"] = $1
|
68
|
-
end
|
69
|
-
if ARGV[1]
|
70
|
-
options["hosts"] ||= []
|
71
|
-
options["hosts"] << ARGV[1]
|
72
|
-
end
|
73
|
-
end
|
74
|
-
options
|
75
|
-
end
|
76
|
-
|