falcon 0.42.3 → 0.44.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/bake/falcon/supervisor.rb +3 -1
- data/changes.md +22 -0
- data/lib/falcon/command/host.rb +7 -50
- data/lib/falcon/command/paths.rb +2 -19
- data/lib/falcon/command/proxy.rb +21 -33
- data/lib/falcon/command/redirect.rb +22 -33
- data/lib/falcon/command/serve.rb +44 -82
- data/lib/falcon/command/supervisor.rb +2 -19
- data/lib/falcon/command/top.rb +2 -19
- data/lib/falcon/command/virtual.rb +16 -41
- data/lib/falcon/command.rb +3 -19
- data/lib/falcon/configuration.rb +28 -142
- data/lib/falcon/endpoint.rb +2 -19
- data/lib/falcon/environment/application.rb +60 -0
- data/lib/falcon/environment/lets_encrypt_tls.rb +34 -0
- data/lib/falcon/environment/proxy.rb +109 -0
- data/lib/falcon/environment/rack.rb +20 -0
- data/lib/falcon/environment/rackup.rb +26 -0
- data/lib/falcon/environment/redirect.rb +50 -0
- data/lib/falcon/environment/self_signed_tls.rb +45 -0
- data/lib/falcon/environment/server.rb +69 -0
- data/lib/falcon/environment/supervisor.rb +40 -0
- data/lib/falcon/environment/tls.rb +97 -0
- data/lib/falcon/environment.rb +13 -0
- data/lib/falcon/middleware/proxy.rb +3 -20
- data/lib/falcon/middleware/redirect.rb +2 -19
- data/lib/falcon/middleware/verbose.rb +2 -19
- data/lib/falcon/proxy_endpoint.rb +2 -19
- data/lib/falcon/railtie.rb +10 -0
- data/lib/falcon/server.rb +2 -19
- data/lib/falcon/service/server.rb +84 -0
- data/lib/falcon/service/supervisor.rb +5 -21
- data/lib/falcon/{controller → service}/virtual.rb +72 -36
- data/lib/falcon/tls.rb +2 -19
- data/lib/falcon/version.rb +3 -20
- data/lib/falcon.rb +5 -19
- data/lib/rack/handler/falcon.rb +4 -0
- data/lib/rackup/handler/falcon.rb +83 -0
- data/license.md +41 -0
- data/readme.md +60 -0
- data.tar.gz.sig +0 -0
- metadata +37 -117
- metadata.gz.sig +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/falcon/controller/host.rb +0 -72
- data/lib/falcon/controller/proxy.rb +0 -126
- data/lib/falcon/controller/redirect.rb +0 -76
- data/lib/falcon/controller/serve.rb +0 -126
- data/lib/falcon/environments/application.rb +0 -72
- data/lib/falcon/environments/lets_encrypt_tls.rb +0 -47
- data/lib/falcon/environments/proxy.rb +0 -37
- data/lib/falcon/environments/rack.rb +0 -50
- data/lib/falcon/environments/self_signed_tls.rb +0 -55
- data/lib/falcon/environments/supervisor.rb +0 -51
- data/lib/falcon/environments/tls.rb +0 -103
- data/lib/falcon/environments.rb +0 -31
- data/lib/falcon/service/application.rb +0 -115
- data/lib/falcon/service/generic.rb +0 -78
- data/lib/falcon/service/proxy.rb +0 -66
- data/lib/falcon/services.rb +0 -99
@@ -1,115 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require_relative 'proxy'
|
24
|
-
|
25
|
-
require 'async/http/endpoint'
|
26
|
-
require 'async/io/shared_endpoint'
|
27
|
-
|
28
|
-
module Falcon
|
29
|
-
module Service
|
30
|
-
# Implements an application server using an internal clear-text proxy.
|
31
|
-
class Application < Proxy
|
32
|
-
def initialize(environment)
|
33
|
-
super
|
34
|
-
|
35
|
-
@bound_endpoint = nil
|
36
|
-
end
|
37
|
-
|
38
|
-
# The middleware that will be served by this application.
|
39
|
-
# @returns [Protocol::HTTP::Middleware]
|
40
|
-
def middleware
|
41
|
-
# In a multi-threaded container, we don't want to modify the shared evaluator's cache, so we create a new evaluator:
|
42
|
-
@environment.evaluator.middleware
|
43
|
-
end
|
44
|
-
|
45
|
-
# Number of instances to start.
|
46
|
-
# @returns [Integer | nil]
|
47
|
-
def count
|
48
|
-
@environment.evaluator.count
|
49
|
-
end
|
50
|
-
|
51
|
-
# Preload any resources specified by the environment.
|
52
|
-
def preload!
|
53
|
-
if scripts = @evaluator.preload
|
54
|
-
scripts.each do |path|
|
55
|
-
Console.logger.info(self) {"Preloading #{path}..."}
|
56
|
-
full_path = File.expand_path(path, self.root)
|
57
|
-
load(full_path)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# Prepare the bound endpoint for the application instances.
|
63
|
-
# Invoke {preload!} to load shared resources into the parent process.
|
64
|
-
def start
|
65
|
-
Console.logger.info(self) {"Binding to #{self.endpoint}..."}
|
66
|
-
|
67
|
-
@bound_endpoint = Async::Reactor.run do
|
68
|
-
Async::IO::SharedEndpoint.bound(self.endpoint)
|
69
|
-
end.wait
|
70
|
-
|
71
|
-
preload!
|
72
|
-
|
73
|
-
super
|
74
|
-
end
|
75
|
-
|
76
|
-
# Setup instances of the application into the container.
|
77
|
-
# @parameter container [Async::Container::Generic]
|
78
|
-
def setup(container)
|
79
|
-
protocol = self.protocol
|
80
|
-
scheme = self.scheme
|
81
|
-
|
82
|
-
run_options = {
|
83
|
-
name: self.name,
|
84
|
-
restart: true,
|
85
|
-
}
|
86
|
-
|
87
|
-
run_options[:count] = count unless count.nil?
|
88
|
-
|
89
|
-
container.run(**run_options) do |instance|
|
90
|
-
Async do |task|
|
91
|
-
Console.logger.info(self) {"Starting application server for #{self.root}..."}
|
92
|
-
|
93
|
-
server = Server.new(self.middleware, @bound_endpoint, protocol: protocol, scheme: scheme)
|
94
|
-
|
95
|
-
server.run
|
96
|
-
|
97
|
-
instance.ready!
|
98
|
-
|
99
|
-
task.children.each(&:wait)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
super
|
104
|
-
end
|
105
|
-
|
106
|
-
# Close the bound endpoint.
|
107
|
-
def stop
|
108
|
-
@bound_endpoint&.close
|
109
|
-
@bound_endpoint = nil
|
110
|
-
|
111
|
-
super
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
@@ -1,78 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 201, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
module Falcon
|
24
|
-
module Service
|
25
|
-
# Captures the stateful behaviour of a specific service.
|
26
|
-
# Specifies the interfaces required by derived classes.
|
27
|
-
#
|
28
|
-
# Designed to be invoked within an {Async::Controller::Container}.
|
29
|
-
class Generic
|
30
|
-
# Convert the given environment into a service if possible.
|
31
|
-
# @parameter environment [Build::Environment] The environment to use to construct the service.
|
32
|
-
def self.wrap(environment)
|
33
|
-
evaluator = environment.evaluator
|
34
|
-
service = evaluator.service || self
|
35
|
-
|
36
|
-
return service.new(environment)
|
37
|
-
end
|
38
|
-
|
39
|
-
# Initialize the service from the given environment.
|
40
|
-
# @parameter environment [Build::Environment]
|
41
|
-
def initialize(environment)
|
42
|
-
@environment = environment
|
43
|
-
@evaluator = @environment.evaluator
|
44
|
-
end
|
45
|
-
|
46
|
-
# Whether the service environment contains the specified keys.
|
47
|
-
# This is used for matching environment configuration to service behaviour.
|
48
|
-
def include?(keys)
|
49
|
-
keys.all?{|key| @environment.include?(key)}
|
50
|
-
end
|
51
|
-
|
52
|
-
# The name of the service.
|
53
|
-
# e.g. `myapp.com`.
|
54
|
-
def name
|
55
|
-
@evaluator.name
|
56
|
-
end
|
57
|
-
|
58
|
-
# The logger to use for this service.
|
59
|
-
# @returns [Console::Logger]
|
60
|
-
def logger
|
61
|
-
return Console.logger # .with(name: name)
|
62
|
-
end
|
63
|
-
|
64
|
-
# Start the service.
|
65
|
-
def start
|
66
|
-
end
|
67
|
-
|
68
|
-
# Setup the service into the specified container.
|
69
|
-
# @parameter container [Async::Container::Generic]
|
70
|
-
def setup(container)
|
71
|
-
end
|
72
|
-
|
73
|
-
# Stop the service.
|
74
|
-
def stop
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/lib/falcon/service/proxy.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require_relative 'generic'
|
24
|
-
|
25
|
-
require 'async/http/endpoint'
|
26
|
-
require 'async/io/shared_endpoint'
|
27
|
-
|
28
|
-
module Falcon
|
29
|
-
module Service
|
30
|
-
class Proxy < Generic
|
31
|
-
def name
|
32
|
-
"#{self.class} for #{self.authority}"
|
33
|
-
end
|
34
|
-
|
35
|
-
# The host that this proxy will receive connections for.
|
36
|
-
def authority
|
37
|
-
@evaluator.authority
|
38
|
-
end
|
39
|
-
|
40
|
-
# The upstream endpoint that this proxy will connect to.
|
41
|
-
def endpoint
|
42
|
-
@evaluator.endpoint
|
43
|
-
end
|
44
|
-
|
45
|
-
# The {OpenSSL::SSL::SSLContext} that will be used for incoming connections.
|
46
|
-
def ssl_context
|
47
|
-
@evaluator.ssl_context
|
48
|
-
end
|
49
|
-
|
50
|
-
# The root
|
51
|
-
def root
|
52
|
-
@evaluator.root
|
53
|
-
end
|
54
|
-
|
55
|
-
# The protocol this proxy will use to talk to the upstream host.
|
56
|
-
def protocol
|
57
|
-
endpoint.protocol
|
58
|
-
end
|
59
|
-
|
60
|
-
# The scheme this proxy will use to talk to the upstream host.
|
61
|
-
def scheme
|
62
|
-
endpoint.scheme
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/lib/falcon/services.rb
DELETED
@@ -1,99 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require_relative 'service/generic'
|
24
|
-
|
25
|
-
module Falcon
|
26
|
-
# Represents one or more services associated with a host.
|
27
|
-
#
|
28
|
-
# The services model allows falcon to manage one more more service associated with a given host. Some examples of services include:
|
29
|
-
#
|
30
|
-
# - Rack applications wrapped by {Service::Application}.
|
31
|
-
# - Host supervisor implemented in {Service::Supervisor}.
|
32
|
-
# - Proxy services wrapped by {Service::Proxy}.
|
33
|
-
#
|
34
|
-
# The list of services is typically generated from the user supplied `falcon.rb` configuration file, which is loaded into an immutable {Configuration} instance, which is mapped into a list of services.
|
35
|
-
class Services
|
36
|
-
# Initialize the services from the given configuration.
|
37
|
-
#
|
38
|
-
# @parameter configuration [Configuration]
|
39
|
-
def initialize(configuration)
|
40
|
-
@named = {}
|
41
|
-
|
42
|
-
configuration.each(:service) do |environment|
|
43
|
-
service = Service::Generic.wrap(environment)
|
44
|
-
|
45
|
-
add(service)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Enumerate all named services.
|
50
|
-
def each(&block)
|
51
|
-
@named.each_value(&block)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Add a named service.
|
55
|
-
#
|
56
|
-
# @parameter service [Service]
|
57
|
-
def add(service)
|
58
|
-
@named[service.name] = service
|
59
|
-
end
|
60
|
-
|
61
|
-
# Start all named services.
|
62
|
-
def start
|
63
|
-
@named.each do |name, service|
|
64
|
-
Console.logger.debug(self) {"Starting #{name}..."}
|
65
|
-
service.start
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Setup all named services into the given container.
|
70
|
-
#
|
71
|
-
# @parameter container [Async::Container::Generic]
|
72
|
-
def setup(container)
|
73
|
-
@named.each do |name, service|
|
74
|
-
Console.logger.debug(self) {"Setup #{name} into #{container}..."}
|
75
|
-
service.setup(container)
|
76
|
-
end
|
77
|
-
|
78
|
-
return container
|
79
|
-
end
|
80
|
-
|
81
|
-
# Stop all named services.
|
82
|
-
def stop
|
83
|
-
failed = false
|
84
|
-
|
85
|
-
@named.each do |name, service|
|
86
|
-
Console.logger.debug(self) {"Stopping #{name}..."}
|
87
|
-
|
88
|
-
begin
|
89
|
-
service.stop
|
90
|
-
rescue => error
|
91
|
-
failed = true
|
92
|
-
Console.logger.error(self, error)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
return failed
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|