rack-traffic-signal 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +5 -0
- data/lib/rack/traffic_signal.rb +12 -0
- data/lib/rack/traffic_signal/config.rb +5 -9
- data/lib/rack/traffic_signal/middleware.rb +2 -2
- data/lib/rack/traffic_signal/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59e7a61c57604b1e7f3cc8503e35b062b1a49825
|
4
|
+
data.tar.gz: 0af4ffecc85271154d8f80e6fbc110d175e8651a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cccc66a6eb11d834c5c3c9f8109229fee675a65cbb7401f49cb4397bbde328afc537dbad3d5be9ded47206fba764d006eed0470a09b0bd8d3aa2dbf4d3f6cf69
|
7
|
+
data.tar.gz: ee9820ebbe3137827f3fdd12e9e4b6747ab5c4093c30e5dbadd7945e401268185f6ea8ee244b8a62d1a2dd8c66e70ae7ff87714cc9a2f8ef782e1c34b0aa5acd
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -57,6 +57,11 @@ Rack::TrafficSignal.setup do |config|
|
|
57
57
|
# Only add path to this option, mantenance mode is not skipped.
|
58
58
|
config.skip_paths = [/^\/users\/12345/]
|
59
59
|
|
60
|
+
# This config is used to skip_path? method.
|
61
|
+
# Only add path to this option, mantenance mode is not skipped.
|
62
|
+
# If request header has `X-RACK-TRAFFIC-SIGNAL-SECRET=<secret word>`, Rack::TrafficSignal.has_secret returns true.
|
63
|
+
config.secret_word = 'secret'
|
64
|
+
|
60
65
|
# Default setting
|
61
66
|
config.default_status = 503
|
62
67
|
config.default_content_type = 'application/json'
|
data/lib/rack/traffic_signal.rb
CHANGED
@@ -14,6 +14,14 @@ module Rack
|
|
14
14
|
@config ||= Config.new
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.skip?(env)
|
18
|
+
config.skip_proc.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.skip_with_warning?(env)
|
22
|
+
config.skip_with_warning_proc.call(env)
|
23
|
+
end
|
24
|
+
|
17
25
|
def self.internal_access?(env)
|
18
26
|
remote_ip = IPAddress(request_from(env))
|
19
27
|
config.internal_ips
|
@@ -21,6 +29,10 @@ module Rack
|
|
21
29
|
.any? { |internal_ip| internal_ip.include?(remote_ip) if remote_ip.class == internal_ip.class }
|
22
30
|
end
|
23
31
|
|
32
|
+
def self.has_secret_word?(env)
|
33
|
+
env.fetch('HTTP_X_RACK_TRAFFIC_SIGNAL_SECRET', nil) == config.secret_word
|
34
|
+
end
|
35
|
+
|
24
36
|
def self.skip_path?(env)
|
25
37
|
path = env['PATH_INFO']
|
26
38
|
path = path.chop if path[-1] == '/'
|
@@ -9,7 +9,10 @@ module Rack
|
|
9
9
|
:skip_paths,
|
10
10
|
:default_status,
|
11
11
|
:default_content_type,
|
12
|
-
:default_body
|
12
|
+
:default_body,
|
13
|
+
:secret_word,
|
14
|
+
:skip_proc,
|
15
|
+
:skip_with_warning_proc
|
13
16
|
|
14
17
|
def initialize
|
15
18
|
@internal_ips = []
|
@@ -17,6 +20,7 @@ module Rack
|
|
17
20
|
@default_status = 503
|
18
21
|
@default_content_type = 'application/json'
|
19
22
|
@default_body = ''
|
23
|
+
@secret_word = ''
|
20
24
|
@skip_paths = [/^\/assets/]
|
21
25
|
@maintenance_status_proc = ->{ [] }
|
22
26
|
@skip_proc = ->(env){ false }
|
@@ -45,18 +49,10 @@ module Rack
|
|
45
49
|
@skip_proc = block
|
46
50
|
end
|
47
51
|
|
48
|
-
def skip?(env)
|
49
|
-
@skip_proc.call(env)
|
50
|
-
end
|
51
|
-
|
52
52
|
def skip_with_warning_by(&block)
|
53
53
|
@skip_with_warning_proc = block
|
54
54
|
end
|
55
55
|
|
56
|
-
def skip_with_warning?(env)
|
57
|
-
@skip_with_warning_proc.call(env)
|
58
|
-
end
|
59
|
-
|
60
56
|
private
|
61
57
|
def valid_maintenance_group?(mg)
|
62
58
|
return false unless mg.is_a? Hash
|
@@ -8,7 +8,7 @@ module Rack
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def call(env)
|
11
|
-
return @app.call(env) if
|
11
|
+
return @app.call(env) if Rack::TrafficSignal.skip?(env)
|
12
12
|
method = env['REQUEST_METHOD'].downcase.to_sym
|
13
13
|
path = env['PATH_INFO']
|
14
14
|
path = path.chop if path != '/' && path[-1] == '/'
|
@@ -16,7 +16,7 @@ module Rack
|
|
16
16
|
applied_config = maintenance_application(method, path)
|
17
17
|
|
18
18
|
if applied_config
|
19
|
-
if
|
19
|
+
if Rack::TrafficSignal.skip_with_warning?(env)
|
20
20
|
@app.call(env).tap do |status, headers, body|
|
21
21
|
headers['X-RACK-TRAFFIC-SIGNAL-MAINTENENCE'] = '1'
|
22
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-traffic-signal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- keigo yamamoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ipaddress
|
@@ -141,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
143
|
rubyforge_project:
|
144
|
-
rubygems_version: 2.
|
144
|
+
rubygems_version: 2.6.12
|
145
145
|
signing_key:
|
146
146
|
specification_version: 4
|
147
147
|
summary: Traffic signal of rack application
|