getaround_utils 0.3.5 → 0.4.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/.ruby-version +1 -1
- data/CHANGELOG.md +40 -0
- data/Gemfile.lock +151 -142
- data/README.md +115 -0
- data/getaround_utils.gemspec +4 -4
- data/lib/getaround_utils/exposed_hosts/configuration.rb +79 -0
- data/lib/getaround_utils/exposed_hosts/entry.rb +95 -0
- data/lib/getaround_utils/exposed_hosts/host_constraint.rb +46 -0
- data/lib/getaround_utils/exposed_hosts/routing_helpers.rb +43 -0
- data/lib/getaround_utils/exposed_hosts/undeclared_host.rb +16 -0
- data/lib/getaround_utils/railties/exposed_hosts.rb +21 -0
- data/lib/getaround_utils/utils/health_check_file.rb +7 -1
- data/lib/getaround_utils/version.rb +1 -1
- metadata +15 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8b29d5e002547c03e781129472956389c1c4e6e4e5e9f45249958e6ec9b1ea4
|
|
4
|
+
data.tar.gz: d1e7717af732b4f34dd4294c66ed9f9967e806cce09fc0843f56ad11e02465a4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e99e685fc042b608e4f313a0d0dd01db58bf28aa241e07ee553e20b81459b545faa63e128e71332bae3be8bc47085ab7182604bec05398c6e3b7f25409188e40
|
|
7
|
+
data.tar.gz: fecff28c580af34c49dfbe51683f21e581502e5a0fc5e6555792d6237894c57667025da6b60c456b7114ca19ec87d992b384f2f209992e43c0c72955eda548d9
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
ruby-4.0.
|
|
1
|
+
ruby-4.0.6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
+
## [0.4.0] 2026-11-23
|
|
2
|
+
|
|
3
|
+
### Breaking Changes
|
|
4
|
+
|
|
5
|
+
- Require Ruby >= 4.0
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `GetaroundUtils::Utils::HealthCheckFile#refresh`: update the file modification time, without recreating it ([#506](https://github.com/drivy/backend-configs/pull/506))
|
|
10
|
+
```ruby
|
|
11
|
+
Sidekiq.configure_server do |config|
|
|
12
|
+
config.on(:beat) { SIDEKIQ_HEALTH_FILE.refresh }
|
|
13
|
+
end
|
|
14
|
+
```
|
|
15
|
+
- `GetaroundUtils::Railties::ExposedHosts`: declares the external and internal hosts of an application and provides the `internal_routes`, `host_defaults` and `host_constraints` routing helpers ([#492](https://github.com/drivy/backend-configs/pull/492))
|
|
16
|
+
```ruby
|
|
17
|
+
# config/application.rb
|
|
18
|
+
require 'getaround_utils/railties/exposed_hosts'
|
|
19
|
+
# ...
|
|
20
|
+
config.hosts += config.exposed_hosts.hosts
|
|
21
|
+
```
|
|
22
|
+
```yaml
|
|
23
|
+
# config/exposed_hosts.yml
|
|
24
|
+
production:
|
|
25
|
+
hosts:
|
|
26
|
+
- { host: app.example.com, exposure: internal }
|
|
27
|
+
- { host: www.example.com, exposure: external }
|
|
28
|
+
```
|
|
29
|
+
```ruby
|
|
30
|
+
# config/routes.rb
|
|
31
|
+
internal_routes { get '/admin', to: 'admin#index' }
|
|
32
|
+
host_defaults(:external) { post '/webhooks/github', to: 'webhooks#github' }
|
|
33
|
+
host_constraints(:external) { get '/signup', to: 'signups#new' }
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- Update Ruby to 4.0.6
|
|
39
|
+
- Update dependencies
|
|
40
|
+
|
|
1
41
|
## [0.3.5] 2026-07-07
|
|
2
42
|
|
|
3
43
|
### Fixed
|
data/Gemfile.lock
CHANGED
|
@@ -1,103 +1,102 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
getaround_utils (0.
|
|
4
|
+
getaround_utils (0.4.0)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
8
8
|
specs:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
action_text-trix (2.1.19)
|
|
10
|
+
railties
|
|
11
|
+
actioncable (8.1.4.1)
|
|
12
|
+
actionpack (= 8.1.4.1)
|
|
13
|
+
activesupport (= 8.1.4.1)
|
|
12
14
|
nio4r (~> 2.0)
|
|
13
15
|
websocket-driver (>= 0.6.1)
|
|
14
16
|
zeitwerk (~> 2.6)
|
|
15
|
-
actionmailbox (
|
|
16
|
-
actionpack (=
|
|
17
|
-
activejob (=
|
|
18
|
-
activerecord (=
|
|
19
|
-
activestorage (=
|
|
20
|
-
activesupport (=
|
|
17
|
+
actionmailbox (8.1.4.1)
|
|
18
|
+
actionpack (= 8.1.4.1)
|
|
19
|
+
activejob (= 8.1.4.1)
|
|
20
|
+
activerecord (= 8.1.4.1)
|
|
21
|
+
activestorage (= 8.1.4.1)
|
|
22
|
+
activesupport (= 8.1.4.1)
|
|
21
23
|
mail (>= 2.8.0)
|
|
22
|
-
actionmailer (
|
|
23
|
-
actionpack (=
|
|
24
|
-
actionview (=
|
|
25
|
-
activejob (=
|
|
26
|
-
activesupport (=
|
|
24
|
+
actionmailer (8.1.4.1)
|
|
25
|
+
actionpack (= 8.1.4.1)
|
|
26
|
+
actionview (= 8.1.4.1)
|
|
27
|
+
activejob (= 8.1.4.1)
|
|
28
|
+
activesupport (= 8.1.4.1)
|
|
27
29
|
mail (>= 2.8.0)
|
|
28
30
|
rails-dom-testing (~> 2.2)
|
|
29
|
-
actionpack (
|
|
30
|
-
actionview (=
|
|
31
|
-
activesupport (=
|
|
32
|
-
cgi
|
|
31
|
+
actionpack (8.1.4.1)
|
|
32
|
+
actionview (= 8.1.4.1)
|
|
33
|
+
activesupport (= 8.1.4.1)
|
|
33
34
|
nokogiri (>= 1.8.5)
|
|
34
|
-
|
|
35
|
-
rack (>= 2.2.4, < 3.3)
|
|
35
|
+
rack (>= 2.2.4)
|
|
36
36
|
rack-session (>= 1.0.1)
|
|
37
37
|
rack-test (>= 0.6.3)
|
|
38
38
|
rails-dom-testing (~> 2.2)
|
|
39
39
|
rails-html-sanitizer (~> 1.6)
|
|
40
40
|
useragent (~> 0.16)
|
|
41
|
-
actiontext (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
actiontext (8.1.4.1)
|
|
42
|
+
action_text-trix (~> 2.1.15)
|
|
43
|
+
actionpack (= 8.1.4.1)
|
|
44
|
+
activerecord (= 8.1.4.1)
|
|
45
|
+
activestorage (= 8.1.4.1)
|
|
46
|
+
activesupport (= 8.1.4.1)
|
|
46
47
|
globalid (>= 0.6.0)
|
|
47
48
|
nokogiri (>= 1.8.5)
|
|
48
|
-
actionview (
|
|
49
|
-
activesupport (=
|
|
49
|
+
actionview (8.1.4.1)
|
|
50
|
+
activesupport (= 8.1.4.1)
|
|
50
51
|
builder (~> 3.1)
|
|
51
|
-
cgi
|
|
52
52
|
erubi (~> 1.11)
|
|
53
53
|
rails-dom-testing (~> 2.2)
|
|
54
|
-
rails-html-sanitizer (~> 1.6)
|
|
55
|
-
activejob (
|
|
56
|
-
activesupport (=
|
|
54
|
+
rails-html-sanitizer (~> 1.6, >= 1.7.2)
|
|
55
|
+
activejob (8.1.4.1)
|
|
56
|
+
activesupport (= 8.1.4.1)
|
|
57
57
|
globalid (>= 0.3.6)
|
|
58
|
-
activemodel (
|
|
59
|
-
activesupport (=
|
|
60
|
-
activerecord (
|
|
61
|
-
activemodel (=
|
|
62
|
-
activesupport (=
|
|
58
|
+
activemodel (8.1.4.1)
|
|
59
|
+
activesupport (= 8.1.4.1)
|
|
60
|
+
activerecord (8.1.4.1)
|
|
61
|
+
activemodel (= 8.1.4.1)
|
|
62
|
+
activesupport (= 8.1.4.1)
|
|
63
63
|
timeout (>= 0.4.0)
|
|
64
|
-
activestorage (
|
|
65
|
-
actionpack (=
|
|
66
|
-
activejob (=
|
|
67
|
-
activerecord (=
|
|
68
|
-
activesupport (=
|
|
64
|
+
activestorage (8.1.4.1)
|
|
65
|
+
actionpack (= 8.1.4.1)
|
|
66
|
+
activejob (= 8.1.4.1)
|
|
67
|
+
activerecord (= 8.1.4.1)
|
|
68
|
+
activesupport (= 8.1.4.1)
|
|
69
69
|
marcel (~> 1.0)
|
|
70
|
-
activesupport (
|
|
70
|
+
activesupport (8.1.4.1)
|
|
71
71
|
base64
|
|
72
|
-
benchmark (>= 0.3)
|
|
73
72
|
bigdecimal
|
|
74
73
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
75
74
|
connection_pool (>= 2.2.5)
|
|
76
75
|
drb
|
|
77
76
|
i18n (>= 1.6, < 2)
|
|
77
|
+
json
|
|
78
78
|
logger (>= 1.4.2)
|
|
79
79
|
minitest (>= 5.1)
|
|
80
80
|
securerandom (>= 0.3)
|
|
81
81
|
tzinfo (~> 2.0, >= 2.0.5)
|
|
82
|
-
|
|
82
|
+
uri (>= 0.13.1)
|
|
83
|
+
addressable (2.9.2)
|
|
83
84
|
public_suffix (>= 2.0.2, < 8.0)
|
|
84
85
|
ast (2.4.3)
|
|
85
86
|
base64 (0.3.0)
|
|
86
|
-
|
|
87
|
-
bigdecimal (4.0.1)
|
|
87
|
+
bigdecimal (4.1.3)
|
|
88
88
|
builder (3.3.0)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
connection_pool (3.0.2)
|
|
89
|
+
concurrent-ruby (1.3.8)
|
|
90
|
+
connection_pool (3.0.3)
|
|
92
91
|
crack (1.0.1)
|
|
93
92
|
bigdecimal
|
|
94
93
|
rexml
|
|
95
|
-
crass (1.0.
|
|
96
|
-
date (3.
|
|
94
|
+
crass (1.0.8)
|
|
95
|
+
date (3.6.0)
|
|
97
96
|
diff-lcs (1.6.2)
|
|
98
97
|
dotenv (3.2.0)
|
|
99
98
|
drb (2.2.3)
|
|
100
|
-
erb (6.0.
|
|
99
|
+
erb (6.0.7)
|
|
101
100
|
erubi (1.13.1)
|
|
102
101
|
getaround-rubocop (0.3.1)
|
|
103
102
|
relaxed-rubocop (~> 2.5)
|
|
@@ -105,99 +104,102 @@ GEM
|
|
|
105
104
|
rubocop-performance (~> 1.0)
|
|
106
105
|
rubocop-rails (~> 2.0)
|
|
107
106
|
rubocop-rspec (~> 3.0)
|
|
108
|
-
globalid (1.
|
|
107
|
+
globalid (1.4.0)
|
|
109
108
|
activesupport (>= 6.1)
|
|
110
|
-
hashdiff (1.2.
|
|
111
|
-
i18n (1.
|
|
109
|
+
hashdiff (1.2.2)
|
|
110
|
+
i18n (1.15.2)
|
|
112
111
|
concurrent-ruby (~> 1.0)
|
|
113
|
-
io-console (0.
|
|
114
|
-
irb (1.
|
|
112
|
+
io-console (0.9.5)
|
|
113
|
+
irb (1.19.0)
|
|
115
114
|
pp (>= 0.6.0)
|
|
115
|
+
prism (>= 1.3.0)
|
|
116
116
|
rdoc (>= 4.0.0)
|
|
117
117
|
reline (>= 0.4.2)
|
|
118
|
-
json (
|
|
119
|
-
language_server-protocol (3.17.0.
|
|
118
|
+
json (3.1.0)
|
|
119
|
+
language_server-protocol (3.17.0.6)
|
|
120
120
|
lint_roller (1.1.0)
|
|
121
121
|
logger (1.7.0)
|
|
122
|
-
lograge (0.
|
|
122
|
+
lograge (0.16.0)
|
|
123
123
|
actionpack (>= 4)
|
|
124
124
|
activesupport (>= 4)
|
|
125
|
+
logger
|
|
125
126
|
railties (>= 4)
|
|
126
127
|
request_store (~> 1.0)
|
|
127
|
-
loofah (2.
|
|
128
|
+
loofah (2.25.3)
|
|
128
129
|
crass (~> 1.0.2)
|
|
129
|
-
nokogiri (>= 1.
|
|
130
|
-
mail (2.
|
|
130
|
+
nokogiri (>= 1.19.5)
|
|
131
|
+
mail (2.9.1)
|
|
132
|
+
logger
|
|
131
133
|
mini_mime (>= 0.1.1)
|
|
132
134
|
net-imap
|
|
133
135
|
net-pop
|
|
134
136
|
net-smtp
|
|
135
|
-
marcel (1.
|
|
137
|
+
marcel (1.2.1)
|
|
136
138
|
mini_mime (1.1.5)
|
|
137
139
|
mini_portile2 (2.8.9)
|
|
138
|
-
minitest (
|
|
139
|
-
|
|
140
|
+
minitest (6.1.0)
|
|
141
|
+
drb (~> 2.0)
|
|
142
|
+
prism (>= 1.5, < 3)
|
|
143
|
+
net-imap (0.6.8)
|
|
140
144
|
date
|
|
141
145
|
net-protocol
|
|
142
146
|
net-pop (0.1.2)
|
|
143
147
|
net-protocol
|
|
144
|
-
net-protocol (0.
|
|
148
|
+
net-protocol (0.4.0)
|
|
145
149
|
timeout
|
|
146
|
-
net-smtp (0.5.
|
|
150
|
+
net-smtp (0.5.2)
|
|
147
151
|
net-protocol
|
|
148
|
-
nio4r (2.7.
|
|
149
|
-
nokogiri (1.
|
|
152
|
+
nio4r (2.7.5)
|
|
153
|
+
nokogiri (1.19.7)
|
|
150
154
|
mini_portile2 (~> 2.8.2)
|
|
151
155
|
racc (~> 1.4)
|
|
152
|
-
oj (3.
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
156
|
+
oj (3.17.8)
|
|
157
|
+
bigdecimal (>= 3.0)
|
|
158
|
+
ougai (2.1.0)
|
|
159
|
+
logger (~> 1.5)
|
|
160
|
+
oj (~> 3.17)
|
|
161
|
+
parallel (2.3.0)
|
|
162
|
+
parser (3.3.14.0)
|
|
157
163
|
ast (~> 2.4.1)
|
|
158
164
|
racc
|
|
159
|
-
pp (0.6.
|
|
165
|
+
pp (0.6.4)
|
|
160
166
|
prettyprint
|
|
161
|
-
prettyprint (0.2.
|
|
162
|
-
prism (1.
|
|
163
|
-
|
|
164
|
-
date
|
|
165
|
-
stringio
|
|
166
|
-
public_suffix (7.0.2)
|
|
167
|
+
prettyprint (0.2.1)
|
|
168
|
+
prism (2.1.0)
|
|
169
|
+
public_suffix (7.0.5)
|
|
167
170
|
racc (1.8.1)
|
|
168
|
-
rack (3.2.
|
|
169
|
-
rack-session (2.1.
|
|
171
|
+
rack (3.2.8)
|
|
172
|
+
rack-session (2.1.2)
|
|
170
173
|
base64 (>= 0.1.0)
|
|
171
174
|
rack (>= 3.0.0)
|
|
172
|
-
rack-test (2.
|
|
175
|
+
rack-test (2.3.0)
|
|
173
176
|
rack (>= 1.3)
|
|
174
|
-
rackup (2.
|
|
177
|
+
rackup (2.3.1)
|
|
175
178
|
rack (>= 3)
|
|
176
|
-
rails (
|
|
177
|
-
actioncable (=
|
|
178
|
-
actionmailbox (=
|
|
179
|
-
actionmailer (=
|
|
180
|
-
actionpack (=
|
|
181
|
-
actiontext (=
|
|
182
|
-
actionview (=
|
|
183
|
-
activejob (=
|
|
184
|
-
activemodel (=
|
|
185
|
-
activerecord (=
|
|
186
|
-
activestorage (=
|
|
187
|
-
activesupport (=
|
|
179
|
+
rails (8.1.4.1)
|
|
180
|
+
actioncable (= 8.1.4.1)
|
|
181
|
+
actionmailbox (= 8.1.4.1)
|
|
182
|
+
actionmailer (= 8.1.4.1)
|
|
183
|
+
actionpack (= 8.1.4.1)
|
|
184
|
+
actiontext (= 8.1.4.1)
|
|
185
|
+
actionview (= 8.1.4.1)
|
|
186
|
+
activejob (= 8.1.4.1)
|
|
187
|
+
activemodel (= 8.1.4.1)
|
|
188
|
+
activerecord (= 8.1.4.1)
|
|
189
|
+
activestorage (= 8.1.4.1)
|
|
190
|
+
activesupport (= 8.1.4.1)
|
|
188
191
|
bundler (>= 1.15.0)
|
|
189
|
-
railties (=
|
|
192
|
+
railties (= 8.1.4.1)
|
|
190
193
|
rails-dom-testing (2.3.0)
|
|
191
194
|
activesupport (>= 5.0.0)
|
|
192
195
|
minitest
|
|
193
196
|
nokogiri (>= 1.6)
|
|
194
|
-
rails-html-sanitizer (1.
|
|
195
|
-
loofah (~> 2.
|
|
197
|
+
rails-html-sanitizer (1.7.2)
|
|
198
|
+
loofah (~> 2.25, >= 2.25.3)
|
|
196
199
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
197
|
-
railties (
|
|
198
|
-
actionpack (=
|
|
199
|
-
activesupport (=
|
|
200
|
-
cgi
|
|
200
|
+
railties (8.1.4.1)
|
|
201
|
+
actionpack (= 8.1.4.1)
|
|
202
|
+
activesupport (= 8.1.4.1)
|
|
201
203
|
irb (~> 1.13)
|
|
202
204
|
rackup (>= 1.0.0)
|
|
203
205
|
rake (>= 12.2)
|
|
@@ -205,16 +207,21 @@ GEM
|
|
|
205
207
|
tsort (>= 0.2)
|
|
206
208
|
zeitwerk (~> 2.6)
|
|
207
209
|
rainbow (3.1.1)
|
|
208
|
-
rake (13.
|
|
209
|
-
|
|
210
|
+
rake (13.4.2)
|
|
211
|
+
rbs (4.2.0)
|
|
212
|
+
logger
|
|
213
|
+
prism (>= 1.6.0)
|
|
214
|
+
tsort
|
|
215
|
+
rdoc (8.1.0)
|
|
210
216
|
erb
|
|
211
|
-
|
|
217
|
+
prism (>= 1.6.0)
|
|
218
|
+
rbs (>= 4.0.0)
|
|
212
219
|
tsort
|
|
213
|
-
redis-client (0.
|
|
220
|
+
redis-client (0.31.0)
|
|
214
221
|
connection_pool
|
|
215
|
-
regexp_parser (2.
|
|
222
|
+
regexp_parser (2.13.4)
|
|
216
223
|
relaxed-rubocop (2.5)
|
|
217
|
-
reline (0.
|
|
224
|
+
reline (0.7.0)
|
|
218
225
|
io-console (~> 0.5)
|
|
219
226
|
request_store (1.7.0)
|
|
220
227
|
rack (>= 1.4)
|
|
@@ -223,37 +230,39 @@ GEM
|
|
|
223
230
|
rspec-core (~> 3.13.0)
|
|
224
231
|
rspec-expectations (~> 3.13.0)
|
|
225
232
|
rspec-mocks (~> 3.13.0)
|
|
226
|
-
rspec-core (3.13.
|
|
233
|
+
rspec-core (3.13.7)
|
|
227
234
|
rspec-support (~> 3.13.0)
|
|
228
|
-
rspec-expectations (3.13.
|
|
235
|
+
rspec-expectations (3.13.6)
|
|
229
236
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
230
237
|
rspec-support (~> 3.13.0)
|
|
231
|
-
rspec-mocks (3.13.
|
|
238
|
+
rspec-mocks (3.13.9)
|
|
232
239
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
233
240
|
rspec-support (~> 3.13.0)
|
|
234
|
-
rspec-rails (8.0
|
|
241
|
+
rspec-rails (8.1.0)
|
|
235
242
|
actionpack (>= 7.2)
|
|
236
243
|
activesupport (>= 7.2)
|
|
237
244
|
railties (>= 7.2)
|
|
238
|
-
rspec-core (
|
|
239
|
-
rspec-expectations (
|
|
240
|
-
rspec-mocks (
|
|
241
|
-
rspec-support (
|
|
242
|
-
rspec-support (3.13.
|
|
243
|
-
rubocop (1.
|
|
244
|
-
json (
|
|
245
|
+
rspec-core (>= 3.13.0, < 5.0.0)
|
|
246
|
+
rspec-expectations (>= 3.13.0, < 5.0.0)
|
|
247
|
+
rspec-mocks (>= 3.13.0, < 5.0.0)
|
|
248
|
+
rspec-support (>= 3.13.0, < 5.0.0)
|
|
249
|
+
rspec-support (3.13.8)
|
|
250
|
+
rubocop (1.92.3)
|
|
251
|
+
json (>= 2.3)
|
|
245
252
|
language_server-protocol (~> 3.17.0.2)
|
|
246
253
|
lint_roller (~> 1.1.0)
|
|
247
|
-
parallel (
|
|
254
|
+
parallel (>= 1.10)
|
|
248
255
|
parser (>= 3.3.0.2)
|
|
249
256
|
rainbow (>= 2.2.2, < 4.0)
|
|
250
|
-
regexp_parser (>= 2.
|
|
251
|
-
rubocop-ast (>= 1.
|
|
257
|
+
regexp_parser (>= 2.11.3, < 3.0)
|
|
258
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
252
259
|
ruby-progressbar (~> 1.7)
|
|
253
260
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
254
|
-
rubocop-ast (1.
|
|
261
|
+
rubocop-ast (1.53.0)
|
|
262
|
+
ast (~> 2.4)
|
|
255
263
|
parser (>= 3.3.7.2)
|
|
256
|
-
prism (
|
|
264
|
+
prism (>= 1.7)
|
|
265
|
+
racc
|
|
257
266
|
rubocop-performance (1.25.0)
|
|
258
267
|
lint_roller (~> 1.1)
|
|
259
268
|
rubocop (>= 1.75.0, < 2.0)
|
|
@@ -269,31 +278,31 @@ GEM
|
|
|
269
278
|
rubocop (~> 1.72, >= 1.72.1)
|
|
270
279
|
ruby-progressbar (1.13.0)
|
|
271
280
|
securerandom (0.4.1)
|
|
272
|
-
sidekiq (8.1.
|
|
281
|
+
sidekiq (8.1.7)
|
|
273
282
|
connection_pool (>= 3.0.0)
|
|
274
283
|
json (>= 2.16.0)
|
|
275
284
|
logger (>= 1.7.0)
|
|
276
285
|
rack (>= 3.2.0)
|
|
277
|
-
redis-client (>= 0.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
timeout (0.4.3)
|
|
286
|
+
redis-client (>= 0.29.0)
|
|
287
|
+
thor (1.5.0)
|
|
288
|
+
timeout (0.6.1)
|
|
281
289
|
tsort (0.2.0)
|
|
282
290
|
tzinfo (2.0.6)
|
|
283
291
|
concurrent-ruby (~> 1.0)
|
|
284
|
-
unicode-display_width (3.
|
|
285
|
-
unicode-emoji (~> 4.
|
|
286
|
-
unicode-emoji (4.
|
|
292
|
+
unicode-display_width (3.3.0)
|
|
293
|
+
unicode-emoji (~> 4.3)
|
|
294
|
+
unicode-emoji (4.3.0)
|
|
295
|
+
uri (1.1.2)
|
|
287
296
|
useragent (0.16.11)
|
|
288
|
-
webmock (3.
|
|
297
|
+
webmock (3.34.0)
|
|
289
298
|
addressable (>= 2.8.0)
|
|
290
299
|
crack (>= 0.3.2)
|
|
291
300
|
hashdiff (>= 0.4.0, < 2.0.0)
|
|
292
|
-
websocket-driver (0.8.
|
|
301
|
+
websocket-driver (0.8.2)
|
|
293
302
|
base64
|
|
294
303
|
websocket-extensions (>= 0.1.0)
|
|
295
304
|
websocket-extensions (0.1.5)
|
|
296
|
-
zeitwerk (2.
|
|
305
|
+
zeitwerk (2.8.3)
|
|
297
306
|
|
|
298
307
|
PLATFORMS
|
|
299
308
|
ruby
|
|
@@ -303,14 +312,14 @@ DEPENDENCIES
|
|
|
303
312
|
getaround-rubocop (= 0.3.1)
|
|
304
313
|
getaround_utils!
|
|
305
314
|
irb (~> 1.15)
|
|
306
|
-
lograge (~> 0.
|
|
315
|
+
lograge (~> 0.16.0)
|
|
307
316
|
ougai (~> 2.0)
|
|
308
317
|
rack (> 2.2)
|
|
309
|
-
rails (~>
|
|
318
|
+
rails (~> 8.1)
|
|
310
319
|
rake (~> 13.2)
|
|
311
320
|
rspec (~> 3.13)
|
|
312
321
|
rspec-rails (~> 8.0)
|
|
313
|
-
rubocop (~> 1.
|
|
322
|
+
rubocop (~> 1.92.2)
|
|
314
323
|
sidekiq (> 7.0)
|
|
315
324
|
webmock (~> 3.25)
|
|
316
325
|
|
data/README.md
CHANGED
|
@@ -49,6 +49,116 @@ require 'getaround_utils/railties/ougai'
|
|
|
49
49
|
|
|
50
50
|
For more details, [read the spec](spec/getaround_utils/railties/ougai_spec.rb)
|
|
51
51
|
|
|
52
|
+
### GetaroundUtils::Railties::ExposedHosts
|
|
53
|
+
|
|
54
|
+
Declares the hosts the application is exposed on, external or internal, and provides routing helpers that restrict routes to some of these hosts or generate their URLs on one of them.
|
|
55
|
+
```ruby
|
|
56
|
+
# config/application.rb
|
|
57
|
+
require 'getaround_utils/railties/exposed_hosts'
|
|
58
|
+
```
|
|
59
|
+
```yaml
|
|
60
|
+
# config/exposed_hosts.yml
|
|
61
|
+
production:
|
|
62
|
+
hosts:
|
|
63
|
+
- { host: app.example.com, exposure: internal }
|
|
64
|
+
- { host: www.example.com, exposure: external }
|
|
65
|
+
- { host: <%= ENV.fetch('LEGACY_HOST') %>, exposure: external, group: legacy }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
- Each environment lists its hosts under `hosts`. It has no other key.
|
|
69
|
+
- Each entry is validated: `host` (an exact host name, without port) and `exposure` (`external` or `internal`) are required, any other key is kept as metadata.
|
|
70
|
+
- ERB and a `shared:` section work as in any `config_for` file. `shared:` is deep merged into the environment's section, so an environment that lists its own `hosts` replaces those of `shared:` rather than adding to them.
|
|
71
|
+
- The file is loaded as soon as the application class is defined, so the class body and the environment files can already read it. An invalid file fails the boot with a `GetaroundUtils::ExposedHosts::Configuration::Error`.
|
|
72
|
+
|
|
73
|
+
```ruby
|
|
74
|
+
exposed = Rails.configuration.exposed_hosts # a GetaroundUtils::ExposedHosts::Configuration
|
|
75
|
+
exposed.hosts # every declared host, once, in the file's order
|
|
76
|
+
exposed.entries # every entry, in the file's order, with its metadata
|
|
77
|
+
exposed.entries(:internal) # the entries of an exposure, :external or :internal, in the file's order
|
|
78
|
+
exposed.entries(group: :legacy) # the entries matching the metadata, whatever their exposure
|
|
79
|
+
exposed.entry(:external) # the first entry of an exposure
|
|
80
|
+
exposed.entry(:external).host # => 'www.example.com'
|
|
81
|
+
exposed.entry(:external, group: :legacy) # the first entry of the exposure matching the metadata
|
|
82
|
+
|
|
83
|
+
entry = exposed.entries.first # a GetaroundUtils::ExposedHosts::Entry
|
|
84
|
+
entry.host # => 'app.example.com'
|
|
85
|
+
entry.exposure # => :internal
|
|
86
|
+
entry.internal? # => true
|
|
87
|
+
entry.external? # => false
|
|
88
|
+
entry.metadata # => {} — the other keys of the entry
|
|
89
|
+
entry.to_h # => { host: 'app.example.com', exposure: :internal } — with the metadata
|
|
90
|
+
entry.match?(group: :legacy) # => false — whether the metadata holds these keys and values
|
|
91
|
+
entry.match?(host: authority) # whether a Host header, e.g. 'APP.example.com:3000', designates this host
|
|
92
|
+
|
|
93
|
+
legacy = exposed.entries.last # the entry of LEGACY_HOST
|
|
94
|
+
legacy.metadata # => { group: 'legacy' }
|
|
95
|
+
legacy.match?(group: :legacy) # => true — a Symbol and a String with the same name are equal
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
`Entry#match?` takes its criteria as keywords: a `host`, an `exposure` and metadata, e.g. `match?(host: authority, exposure: :internal, group: :api)`. A criterion left out matches any entry, while a `nil` host, that of a request without a Host header, matches none. A Symbol and a String with the same name are equal, so `group: :api` matches the `group: api` of a YAML entry; other values compare strictly.
|
|
99
|
+
|
|
100
|
+
`entries` and `entry` take an exposure and other criteria as keywords: `entries(:internal, group: :api)`, `entry(:external, group: :api)`. The keywords are the criteria of `Entry#match?`: metadata, but also a `host`, e.g. `entries(host: authority)`. The exposure of `entries` is optional too: without it, it lists the entries matching the other criteria whatever their exposure, and without any criterion, every entry. `entries` also takes the exposure as a keyword, e.g. `entries(exposure: :internal)`. Either way, it is `external` or `internal`, as a Symbol or a String, and given once: anything else raises an `ArgumentError`. When no entry matches, both raise a `GetaroundUtils::ExposedHosts::UndeclaredHost` that names the exposure and the other criteria, e.g. `no internal host matching {group: :api} is declared`.
|
|
101
|
+
|
|
102
|
+
The railtie does not touch `config.hosts`: each application adds the hosts it needs, for instance all of them:
|
|
103
|
+
```ruby
|
|
104
|
+
# config/application.rb
|
|
105
|
+
config.hosts += config.exposed_hosts.hosts
|
|
106
|
+
```
|
|
107
|
+
Once `config.hosts` is filled, a health check that does not send a declared host is blocked. Exclude it where the application sets its other environment options:
|
|
108
|
+
```ruby
|
|
109
|
+
health_check = ->(request) { request.path == '/up' || request.path.start_with?('/health/') }
|
|
110
|
+
config.host_authorization = { exclude: health_check }
|
|
111
|
+
config.ssl_options = { redirect: { exclude: health_check } } # only when redirecting to HTTPS without `config.assume_ssl`
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
The routes DSL gets three optional helpers:
|
|
115
|
+
|
|
116
|
+
- `host_constraints` restricts routes to the matching hosts: they answer nowhere else.
|
|
117
|
+
- `host_defaults` generates the URLs of routes on the first matching host, without restricting where they answer.
|
|
118
|
+
- `internal_routes` does both on the internal hosts.
|
|
119
|
+
|
|
120
|
+
`host_defaults` takes the same arguments as `entry`, `host_constraints` the same as `entries`: without exposure, the routes answer on the hosts whose entry matches the other criteria, whatever their exposure, and without any criterion, on every declared host. `internal_routes` only takes the other criteria: an `exposure` among them raises an `ArgumentError`.
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
# config/routes.rb
|
|
124
|
+
Rails.application.routes.draw do
|
|
125
|
+
# Only exist on the internal hosts, and generate their URLs on the first of them, e.g. an admin
|
|
126
|
+
internal_routes do
|
|
127
|
+
get '/admin', to: 'admin#index'
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Exist on every host, and generate their URLs on the first external host,
|
|
131
|
+
# e.g. the webhooks of an application whose `default_url_options` point to its internal host
|
|
132
|
+
host_defaults(:external) do
|
|
133
|
+
post '/webhooks/github', to: 'webhooks#github'
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Only exist on the hosts whose entry has `group: api`, external or internal, and generate their URLs on the external one
|
|
137
|
+
host_constraints(group: :api) do
|
|
138
|
+
host_defaults(:external, group: :api) do
|
|
139
|
+
post '/graphql', to: 'graphql#execute'
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
```
|
|
144
|
+
- **`host_constraints` and `internal_routes` limit where a route answers, they do not authorize anyone**: the Host header is chosen by the client. Every internal route must still authenticate its callers.
|
|
145
|
+
- `host_defaults` and `internal_routes` set `params[:host]` to the host of their entry, whatever the request says. Their controllers must not use a parameter with this name.
|
|
146
|
+
- The other URL options, e.g. a protocol or a port, still come from the `default_url_options` of the routes, whose host can be a declared one: `default_url_options(host: Rails.configuration.exposed_hosts.entry(:external).host)`.
|
|
147
|
+
- `host_defaults` does not check that its host is one of those of `host_constraints`: make sure it is, as with `host_defaults(:external, group: :api)` inside `host_constraints(group: :api)` above, or the URLs point to a host where the routes do not answer. `internal_routes` always does.
|
|
148
|
+
- Inside `host_constraints` or `internal_routes`, a route that takes its own constraint object or lambda, e.g. `get '/admin', to: 'admin#index', constraints: LoggedIn.new`, drops the host constraint and answers on every host: Rails replaces the constraint of the block with that of the route. Nest it in a `constraints(LoggedIn.new) do` block instead. A hash of constraints, e.g. `constraints: { subdomain: 'www' }`, adds to the host constraint.
|
|
149
|
+
- Drawing any of them without a matching entry raises a `GetaroundUtils::ExposedHosts::UndeclaredHost`.
|
|
150
|
+
|
|
151
|
+
`host_constraints` matches the hosts of the entries in any case and with any port. An internal entry is matched against the raw Host header: it ignores `X-Forwarded-Host` and `Forwarded`, and a request without a Host header matches none. An external entry is matched against `request.host`: the forwarded host if any, else the Host header, else `SERVER_NAME`. In the router, the `ActionDispatch::Request` only reads `X-Forwarded-Host`, while a `Rack::Request` also reads `Forwarded`, before `X-Forwarded-Host`. Its `GetaroundUtils::ExposedHosts::HostConstraint` takes any Rack request, so the code that runs before the router can use it too:
|
|
152
|
+
```ruby
|
|
153
|
+
INTERNAL_API_HOSTS = GetaroundUtils::ExposedHosts::HostConstraint.new(Rails.configuration.exposed_hosts.entries(:internal, group: :api))
|
|
154
|
+
INTERNAL_API_HOSTS.matches?(request) # whether the request targets an internal host of the api group
|
|
155
|
+
```
|
|
156
|
+
It takes a list of entries, which matches no request when empty, and raises an `ArgumentError` for anything else.
|
|
157
|
+
|
|
158
|
+
The ERB of `config/exposed_hosts.yml` only sees the `.env` files loaded before the application class: load them at the top of `config/application.rb`, e.g. with `GetaroundUtils::Railties::Dotenv.load`. The `before_configuration` hook of `dotenv-rails` is not enough when this railtie is required first, as its own hook then runs first.
|
|
159
|
+
|
|
160
|
+
For more details, read the specs of [the railtie](spec/getaround_utils/railties/exposed_hosts_spec.rb), [the configuration](spec/getaround_utils/exposed_hosts/configuration_spec.rb), [the entry](spec/getaround_utils/exposed_hosts/entry_spec.rb), [the host constraint](spec/getaround_utils/exposed_hosts/host_constraint_spec.rb) and [the routing helpers](spec/getaround_utils/exposed_hosts/routing_helpers_spec.rb). [The routes of the spec dummy application](spec/getaround_utils/exposed_hosts/dummy_routes_spec.rb) show where the URLs generated with each helper point, during a request and outside one.
|
|
161
|
+
|
|
52
162
|
## Engines
|
|
53
163
|
|
|
54
164
|
### GetaroundUtils::Engine::Health
|
|
@@ -210,8 +320,13 @@ SIDEKIQ_HEALTH_FILE = GetaroundUtils::Utils::HealthCheckFile.new('sidekiq')
|
|
|
210
320
|
|
|
211
321
|
Sidekiq.configure_server do |config|
|
|
212
322
|
config.on(:startup) { SIDEKIQ_HEALTH_FILE.create }
|
|
323
|
+
config.on(:beat) { SIDEKIQ_HEALTH_FILE.refresh }
|
|
213
324
|
config.on(:shutdown) { SIDEKIQ_HEALTH_FILE.delete }
|
|
214
325
|
end
|
|
215
326
|
```
|
|
216
327
|
|
|
328
|
+
`refresh` only updates the modification time of an existing file. Sidekiq fires `:beat` every 10 seconds after a
|
|
329
|
+
successful Redis round trip, so a liveness probe can check the file age to detect a frozen process or a lost Redis
|
|
330
|
+
connection, e.g. `find tmp/sidekiq/health_check_file -mmin -1 | grep -q .`
|
|
331
|
+
|
|
217
332
|
For more details, [read the spec](spec/getaround_utils/utils/health_check_file_spec.rb)
|
data/getaround_utils.gemspec
CHANGED
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
|
11
11
|
gem.email = ['oss@drivy.com']
|
|
12
12
|
gem.homepage = 'https://github.com/drivy'
|
|
13
13
|
gem.license = 'MIT'
|
|
14
|
-
gem.required_ruby_version = '>=
|
|
14
|
+
gem.required_ruby_version = '>= 4.0'
|
|
15
15
|
|
|
16
16
|
gem.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
17
17
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
|
@@ -27,14 +27,14 @@ Gem::Specification.new do |gem|
|
|
|
27
27
|
gem.add_development_dependency 'rake', '~> 13.2'
|
|
28
28
|
gem.add_development_dependency 'rspec', '~> 3.13'
|
|
29
29
|
gem.add_development_dependency 'rspec-rails', '~> 8.0'
|
|
30
|
-
gem.add_development_dependency 'rubocop', '~> 1.
|
|
30
|
+
gem.add_development_dependency 'rubocop', '~> 1.92.2'
|
|
31
31
|
gem.add_development_dependency 'webmock', '~> 3.25'
|
|
32
32
|
|
|
33
33
|
# Functional (optional) dependencies
|
|
34
34
|
gem.add_development_dependency 'dotenv', '~> 3.2.0'
|
|
35
|
-
gem.add_development_dependency 'lograge', '~> 0.
|
|
35
|
+
gem.add_development_dependency 'lograge', '~> 0.16.0'
|
|
36
36
|
gem.add_development_dependency 'ougai', '~> 2.0'
|
|
37
37
|
gem.add_development_dependency 'rack', '> 2.2'
|
|
38
|
-
gem.add_development_dependency 'rails', '~>
|
|
38
|
+
gem.add_development_dependency 'rails', '~> 8.1'
|
|
39
39
|
gem.add_development_dependency 'sidekiq', '> 7.0'
|
|
40
40
|
end
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'getaround_utils/exposed_hosts/entry'
|
|
4
|
+
require 'getaround_utils/exposed_hosts/undeclared_host'
|
|
5
|
+
|
|
6
|
+
module GetaroundUtils; end
|
|
7
|
+
|
|
8
|
+
module GetaroundUtils::ExposedHosts; end
|
|
9
|
+
|
|
10
|
+
# The section of an environment in config/exposed_hosts.yml: its `hosts`, validated and turned into entries. It has
|
|
11
|
+
# no other key.
|
|
12
|
+
class GetaroundUtils::ExposedHosts::Configuration
|
|
13
|
+
attr_reader :hosts
|
|
14
|
+
|
|
15
|
+
class Error < StandardError; end
|
|
16
|
+
|
|
17
|
+
NO_ARG = Object.new.freeze
|
|
18
|
+
private_constant :NO_ARG
|
|
19
|
+
|
|
20
|
+
def initialize(section)
|
|
21
|
+
raise Error, "the environment section must be a hash, got #{section.inspect}" unless section.is_a?(Hash)
|
|
22
|
+
|
|
23
|
+
unknown_keys = section.keys - [:hosts]
|
|
24
|
+
raise Error, "unknown keys: #{unknown_keys.join(', ')}" if unknown_keys.any?
|
|
25
|
+
raise Error, 'missing key: hosts' unless section.key?(:hosts)
|
|
26
|
+
|
|
27
|
+
@entries = build_entries(section[:hosts]).freeze
|
|
28
|
+
@hosts = @entries.map(&:host).uniq.freeze
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# The entries that have the exposure and match the other criteria, in the file's order, e.g.
|
|
32
|
+
# `entries(:internal, group: 'api')`. Without exposure, whatever their exposure, and without any criterion, every
|
|
33
|
+
# entry. Raises an UndeclaredHost when there is none.
|
|
34
|
+
# The keywords are the criteria of `Entry#match?`: metadata, but also a `host`, e.g. `entries(host: authority)`, or
|
|
35
|
+
# the exposure, e.g. `entries(exposure: :internal)`. The exposure is external or internal, as a Symbol or a String,
|
|
36
|
+
# given as an argument or as a keyword but not both: anything else raises an ArgumentError.
|
|
37
|
+
def entries(exposure = NO_ARG, **)
|
|
38
|
+
criteria = criteria_for(exposure, **)
|
|
39
|
+
@entries.select { |entry| entry.match?(**criteria) }.freeze.tap do |entries|
|
|
40
|
+
undeclared_host!(**criteria) if entries.empty?
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# The first entry that has the exposure and matches the other criteria, e.g. `entry(:external, group: 'api')`. It
|
|
45
|
+
# takes the arguments of `entries`, and raises the same errors, but requires the exposure as an argument.
|
|
46
|
+
def entry(exposure, **)
|
|
47
|
+
criteria = criteria_for(exposure, **)
|
|
48
|
+
@entries.find { |entry| entry.match?(**criteria) } || undeclared_host!(**criteria)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
private
|
|
52
|
+
|
|
53
|
+
def build_entries(raw_entries)
|
|
54
|
+
raise Error, "hosts must be a list, got #{raw_entries.inspect}" unless raw_entries.is_a?(Array)
|
|
55
|
+
|
|
56
|
+
raw_entries.each.with_index(1).map do |raw_entry, position|
|
|
57
|
+
GetaroundUtils::ExposedHosts::Entry.build(raw_entry).freeze
|
|
58
|
+
rescue GetaroundUtils::ExposedHosts::Entry::Error => e
|
|
59
|
+
raise Error, "hosts entry ##{position}: #{e.message}"
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def criteria_for(exposure, **kwargs)
|
|
64
|
+
if exposure != NO_ARG && kwargs.key?(:exposure)
|
|
65
|
+
raise ArgumentError, "exposure must be given once, got #{exposure.inspect} and exposure: #{kwargs[:exposure].inspect}"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
criteria = exposure == NO_ARG ? kwargs : kwargs.merge(exposure:)
|
|
69
|
+
if criteria.key?(:exposure) && !GetaroundUtils::ExposedHosts::Entry.valid_exposure?(criteria[:exposure])
|
|
70
|
+
raise ArgumentError, "exposure must be external or internal, got #{criteria[:exposure].inspect}"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
criteria
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def undeclared_host!(**)
|
|
77
|
+
raise GetaroundUtils::ExposedHosts::UndeclaredHost.new(**)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GetaroundUtils; end
|
|
4
|
+
|
|
5
|
+
module GetaroundUtils::ExposedHosts; end
|
|
6
|
+
|
|
7
|
+
# A host of config/exposed_hosts.yml: its exposure, and any other key of the entry as metadata.
|
|
8
|
+
class GetaroundUtils::ExposedHosts::Entry
|
|
9
|
+
attr_reader :host, :exposure, :metadata
|
|
10
|
+
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
|
|
13
|
+
EXPOSURES = %i[external internal].freeze
|
|
14
|
+
REQUIRED_KEYS = %i[host exposure].freeze
|
|
15
|
+
NO_ARG = Object.new.freeze
|
|
16
|
+
private_constant :NO_ARG
|
|
17
|
+
|
|
18
|
+
# Builds an entry from a hash of config/exposed_hosts.yml: `host`, `exposure`, and any other key as metadata.
|
|
19
|
+
def self.build(raw_entry)
|
|
20
|
+
raise Error, "expected a hash, got #{raw_entry.inspect}" unless raw_entry.is_a?(Hash)
|
|
21
|
+
|
|
22
|
+
missing_keys = REQUIRED_KEYS - raw_entry.keys
|
|
23
|
+
raise Error, "missing required keys: #{missing_keys.join(', ')}" if missing_keys.any?
|
|
24
|
+
|
|
25
|
+
new(**raw_entry)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.valid_exposure?(exposure)
|
|
29
|
+
(exposure.is_a?(String) || exposure.is_a?(Symbol)) && EXPOSURES.include?(exposure.to_sym)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def initialize(host:, exposure:, **metadata)
|
|
33
|
+
raise Error, "exposure must be external or internal, got #{exposure.inspect}" unless self.class.valid_exposure?(exposure)
|
|
34
|
+
# The rules on the host keep `@host_pattern` identical to the pattern HostAuthorization builds for the same host.
|
|
35
|
+
# HostAuthorization only builds such a pattern for a String, and an empty host would match an empty Host header.
|
|
36
|
+
raise Error, "host must be a non-empty string, got #{host.inspect}" unless host.is_a?(String) && !host.empty?
|
|
37
|
+
# HostAuthorization reads a leading dot as a wildcard for the subdomains.
|
|
38
|
+
raise Error, "host must not start with a dot, got #{host.inspect}" if host.start_with?('.')
|
|
39
|
+
# HostAuthorization allows a host declared with a port on that port only, while an entry matches any port.
|
|
40
|
+
raise Error, "host must not include a port, got #{host.inspect}" if host.include?(':')
|
|
41
|
+
|
|
42
|
+
@host = host.freeze
|
|
43
|
+
@exposure = exposure.to_sym
|
|
44
|
+
@metadata = metadata.freeze
|
|
45
|
+
@host_pattern = /\A#{Regexp.escape(host)}(?::\d+)?\z/i
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Whether the entry has the given host, exposure and metadata, e.g. `match?(exposure: :internal, group: 'api')`.
|
|
49
|
+
# A criterion left out matches any entry, while a nil host, that of a request without a Host header, matches none,
|
|
50
|
+
# and neither does an exposure that is not external or internal.
|
|
51
|
+
def match?(host: NO_ARG, exposure: NO_ARG, **metadata)
|
|
52
|
+
return false unless exposure == NO_ARG || match_exposure?(exposure)
|
|
53
|
+
return false unless host == NO_ARG || match_host?(host)
|
|
54
|
+
|
|
55
|
+
match_metadata?(**metadata)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def external?
|
|
59
|
+
exposure == :external
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def internal?
|
|
63
|
+
exposure == :internal
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def to_h
|
|
67
|
+
{ host:, exposure:, **metadata }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private
|
|
71
|
+
|
|
72
|
+
def match_exposure?(exposure)
|
|
73
|
+
comparable(self.exposure) == comparable(exposure)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Whether a Host header designates this host, in any case and with any port, e.g. `match_host?('WWW.example.com:3000')`.
|
|
77
|
+
# It is the comparison HostAuthorization makes for a host without a leading dot nor a port, hence the rules on the
|
|
78
|
+
# host in `initialize`.
|
|
79
|
+
def match_host?(authority)
|
|
80
|
+
@host_pattern.match?(authority)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# Whether the metadata holds all the given keys with the given values, e.g. `match_metadata?(group: :api)`.
|
|
84
|
+
# A Symbol and a String with the same name are equal: YAML loads `group: api` as a String, and `group: :api`, which
|
|
85
|
+
# only the block style accepts, as a Symbol.
|
|
86
|
+
def match_metadata?(**metadata)
|
|
87
|
+
metadata.all? do |key, value|
|
|
88
|
+
self.metadata.key?(key) && comparable(self.metadata[key]) == comparable(value)
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def comparable(value)
|
|
93
|
+
value.is_a?(Symbol) ? value.name : value
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'getaround_utils/exposed_hosts/entry'
|
|
4
|
+
|
|
5
|
+
module GetaroundUtils; end
|
|
6
|
+
|
|
7
|
+
module GetaroundUtils::ExposedHosts; end
|
|
8
|
+
|
|
9
|
+
# Matches the requests whose host is the host of one of the entries, in any case and with any port,
|
|
10
|
+
# e.g. `HostConstraint.new(configuration.entries(:internal, group: 'api'))`. An internal entry is matched against the
|
|
11
|
+
# raw Host header, ignoring X-Forwarded-Host and Forwarded. An external entry is matched against `request.host`: the
|
|
12
|
+
# forwarded host if any, else the Host header, else SERVER_NAME. That of the ActionDispatch::Request the router passes
|
|
13
|
+
# only reads X-Forwarded-Host, while that of a Rack::Request also reads Forwarded, before X-Forwarded-Host. An empty
|
|
14
|
+
# list matches no request.
|
|
15
|
+
# A routing constraint, which also takes any Rack::Request.
|
|
16
|
+
class GetaroundUtils::ExposedHosts::HostConstraint
|
|
17
|
+
def initialize(entries)
|
|
18
|
+
unless entries.is_a?(Array) && entries.all?(GetaroundUtils::ExposedHosts::Entry)
|
|
19
|
+
raise ArgumentError, "expected a list of entries, got #{entries.inspect}"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
@internal_entries, @external_entries = entries.partition(&:internal?).each(&:freeze)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# A request without a Host header matches no internal entry, but still matches an external entry on its forwarded
|
|
26
|
+
# host or its SERVER_NAME.
|
|
27
|
+
def matches?(request)
|
|
28
|
+
internal_request?(request) || external_request?(request)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def internal_request?(request)
|
|
34
|
+
return false if @internal_entries.empty?
|
|
35
|
+
|
|
36
|
+
host = request.host_authority
|
|
37
|
+
@internal_entries.any? { |entry| entry.match?(host:) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def external_request?(request)
|
|
41
|
+
return false if @external_entries.empty?
|
|
42
|
+
|
|
43
|
+
host = request.host
|
|
44
|
+
@external_entries.any? { |entry| entry.match?(host:) }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'getaround_utils/exposed_hosts/host_constraint'
|
|
4
|
+
|
|
5
|
+
module GetaroundUtils; end
|
|
6
|
+
|
|
7
|
+
module GetaroundUtils::ExposedHosts; end
|
|
8
|
+
|
|
9
|
+
# Added to the routes DSL by GetaroundUtils::Railties::ExposedHosts.
|
|
10
|
+
# `internal_routes` and `host_defaults` reserve `params[:host]`, which they set to the host of their entry whatever the
|
|
11
|
+
# request says.
|
|
12
|
+
module GetaroundUtils::ExposedHosts::RoutingHelpers
|
|
13
|
+
# Routes that only exist on the hosts whose entry has the exposure and matches the other criteria, e.g.
|
|
14
|
+
# `host_constraints(:internal, group: 'api')`. It takes the arguments of `Configuration#entries`: without exposure,
|
|
15
|
+
# on every declared host whose entry matches the criteria, and without any criterion, on every declared host. Raises
|
|
16
|
+
# an ArgumentError for an exposure that `Configuration#entries` refuses, an UndeclaredHost when no entry matches.
|
|
17
|
+
# Unlike `internal_routes`, it neither sets `params[:host]` nor picks the host of their URLs. For that, wrap them in a
|
|
18
|
+
# `host_defaults` whose host is one of these hosts, or their URLs point to a host where they do not answer, e.g.
|
|
19
|
+
# `host_constraints(group: 'api') { host_defaults(:external, group: 'api') { ... } }`.
|
|
20
|
+
def host_constraints(*, **, &)
|
|
21
|
+
entries = Rails.configuration.exposed_hosts.entries(*, **)
|
|
22
|
+
constraints(GetaroundUtils::ExposedHosts::HostConstraint.new(entries), &)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Routes whose URLs are generated on the host of the first entry that has the exposure and matches the other
|
|
26
|
+
# criteria, e.g. `host_defaults(:external, group: 'api')`. Their other URL options, e.g. a protocol or a port, still
|
|
27
|
+
# come from the `default_url_options` of the routes.
|
|
28
|
+
# They answer on every host. Takes the arguments of `Configuration#entry`, and raises an ArgumentError for an
|
|
29
|
+
# exposure that it refuses, an UndeclaredHost when no entry matches.
|
|
30
|
+
def host_defaults(*, **, &)
|
|
31
|
+
entry = Rails.configuration.exposed_hosts.entry(*, **)
|
|
32
|
+
defaults(host: entry.host, &)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Routes that only exist on the internal hosts, and whose URLs are generated on the first of them.
|
|
36
|
+
# With criteria, those of `Configuration#entries` but the exposure, only the internal hosts whose entry matches them,
|
|
37
|
+
# e.g. `internal_routes(group: 'api')`. An `exposure` among them raises an ArgumentError.
|
|
38
|
+
def internal_routes(**, &)
|
|
39
|
+
host_constraints(:internal, **) do
|
|
40
|
+
host_defaults(:internal, **, &)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module GetaroundUtils; end
|
|
4
|
+
|
|
5
|
+
module GetaroundUtils::ExposedHosts; end
|
|
6
|
+
|
|
7
|
+
# Raised when no entry of config/exposed_hosts.yml matches the criteria, e.g.
|
|
8
|
+
# `UndeclaredHost.new(exposure: :internal, group: 'api')`. Its message names the exposure and the metadata.
|
|
9
|
+
class GetaroundUtils::ExposedHosts::UndeclaredHost < StandardError
|
|
10
|
+
def initialize(**criteria)
|
|
11
|
+
exposure = criteria.delete(:exposure)
|
|
12
|
+
exposed = " #{exposure}" unless exposure.nil?
|
|
13
|
+
filter = " matching #{criteria.inspect}" if criteria.any?
|
|
14
|
+
super("no#{exposed} host#{filter} is declared")
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'rails/railtie'
|
|
4
|
+
require 'getaround_utils/exposed_hosts/configuration'
|
|
5
|
+
require 'getaround_utils/exposed_hosts/routing_helpers'
|
|
6
|
+
|
|
7
|
+
module GetaroundUtils; end
|
|
8
|
+
|
|
9
|
+
module GetaroundUtils::Railties; end
|
|
10
|
+
|
|
11
|
+
class GetaroundUtils::Railties::ExposedHosts < Rails::Railtie
|
|
12
|
+
# Runs as soon as the application class is defined, so that its body and its environment files can read the hosts.
|
|
13
|
+
config.before_configuration do |app|
|
|
14
|
+
app.config.exposed_hosts = GetaroundUtils::ExposedHosts::Configuration.new(app.config_for(:exposed_hosts))
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Runs before the routes are drawn, so that they can use `internal_routes`, `host_defaults` and `host_constraints`.
|
|
18
|
+
initializer 'getaround_utils.exposed_hosts.routing_helpers' do
|
|
19
|
+
ActionDispatch::Routing::Mapper.include(GetaroundUtils::ExposedHosts::RoutingHelpers)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'fileutils'
|
|
4
|
-
require 'pathname'
|
|
5
4
|
|
|
6
5
|
module GetaroundUtils; end
|
|
7
6
|
|
|
@@ -28,6 +27,13 @@ class GetaroundUtils::Utils::HealthCheckFile
|
|
|
28
27
|
FileUtils.rm_f(@path)
|
|
29
28
|
end
|
|
30
29
|
|
|
30
|
+
def refresh
|
|
31
|
+
File.utime(nil, nil, @path)
|
|
32
|
+
true
|
|
33
|
+
rescue Errno::ENOENT
|
|
34
|
+
false
|
|
35
|
+
end
|
|
36
|
+
|
|
31
37
|
def exists?
|
|
32
38
|
File.exist?(@path)
|
|
33
39
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: getaround_utils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Drivy
|
|
@@ -86,14 +86,14 @@ dependencies:
|
|
|
86
86
|
requirements:
|
|
87
87
|
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: 1.
|
|
89
|
+
version: 1.92.2
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: 1.
|
|
96
|
+
version: 1.92.2
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
98
|
name: webmock
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -128,14 +128,14 @@ dependencies:
|
|
|
128
128
|
requirements:
|
|
129
129
|
- - "~>"
|
|
130
130
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: 0.
|
|
131
|
+
version: 0.16.0
|
|
132
132
|
type: :development
|
|
133
133
|
prerelease: false
|
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
|
135
135
|
requirements:
|
|
136
136
|
- - "~>"
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
|
-
version: 0.
|
|
138
|
+
version: 0.16.0
|
|
139
139
|
- !ruby/object:Gem::Dependency
|
|
140
140
|
name: ougai
|
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -170,14 +170,14 @@ dependencies:
|
|
|
170
170
|
requirements:
|
|
171
171
|
- - "~>"
|
|
172
172
|
- !ruby/object:Gem::Version
|
|
173
|
-
version: '
|
|
173
|
+
version: '8.1'
|
|
174
174
|
type: :development
|
|
175
175
|
prerelease: false
|
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
|
177
177
|
requirements:
|
|
178
178
|
- - "~>"
|
|
179
179
|
- !ruby/object:Gem::Version
|
|
180
|
-
version: '
|
|
180
|
+
version: '8.1'
|
|
181
181
|
- !ruby/object:Gem::Dependency
|
|
182
182
|
name: sidekiq
|
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -209,6 +209,11 @@ files:
|
|
|
209
209
|
- lib/getaround_utils.rb
|
|
210
210
|
- lib/getaround_utils/engines.rb
|
|
211
211
|
- lib/getaround_utils/engines/health.rb
|
|
212
|
+
- lib/getaround_utils/exposed_hosts/configuration.rb
|
|
213
|
+
- lib/getaround_utils/exposed_hosts/entry.rb
|
|
214
|
+
- lib/getaround_utils/exposed_hosts/host_constraint.rb
|
|
215
|
+
- lib/getaround_utils/exposed_hosts/routing_helpers.rb
|
|
216
|
+
- lib/getaround_utils/exposed_hosts/undeclared_host.rb
|
|
212
217
|
- lib/getaround_utils/i18n_backend/flat_keys.rb
|
|
213
218
|
- lib/getaround_utils/mixins.rb
|
|
214
219
|
- lib/getaround_utils/mixins/loggable.rb
|
|
@@ -216,6 +221,7 @@ files:
|
|
|
216
221
|
- lib/getaround_utils/ougai/deep_key_value_formatter.rb
|
|
217
222
|
- lib/getaround_utils/ougai/json_formatter.rb
|
|
218
223
|
- lib/getaround_utils/railties/dotenv.rb
|
|
224
|
+
- lib/getaround_utils/railties/exposed_hosts.rb
|
|
219
225
|
- lib/getaround_utils/railties/lograge.rb
|
|
220
226
|
- lib/getaround_utils/railties/ougai.rb
|
|
221
227
|
- lib/getaround_utils/utils.rb
|
|
@@ -236,14 +242,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
236
242
|
requirements:
|
|
237
243
|
- - ">="
|
|
238
244
|
- !ruby/object:Gem::Version
|
|
239
|
-
version: '
|
|
245
|
+
version: '4.0'
|
|
240
246
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
241
247
|
requirements:
|
|
242
248
|
- - ">="
|
|
243
249
|
- !ruby/object:Gem::Version
|
|
244
250
|
version: '0'
|
|
245
251
|
requirements: []
|
|
246
|
-
rubygems_version: 4.0.
|
|
252
|
+
rubygems_version: 4.0.16
|
|
247
253
|
specification_version: 4
|
|
248
254
|
summary: Backend shared utility classes
|
|
249
255
|
test_files: []
|