roo_on_rails 2.0.0.pre.pre.2 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +457 -97
- data/.circleci/config.yml.erb +28 -9
- data/.codecov.yml +3 -0
- data/.ruby-version +1 -1
- data/Appraisals +33 -18
- data/CHANGELOG.md +29 -0
- data/README.md +5 -45
- data/appraise +2 -3
- data/gemfiles/rails_5_2.gemfile +3 -1
- data/gemfiles/{rails_5.gemfile → rails_6_0.gemfile} +5 -2
- data/gemfiles/rails_6_1.gemfile +21 -0
- data/gemfiles/rails_7_0.gemfile +20 -0
- data/lib/roo_on_rails/logger.rb +2 -15
- data/lib/roo_on_rails/rack/populate_env_from_jwt.rb +2 -1
- data/lib/roo_on_rails/railties/database.rb +29 -3
- data/lib/roo_on_rails/railties/env.rb +3 -5
- data/lib/roo_on_rails/railties/google_oauth.rb +4 -6
- data/lib/roo_on_rails/railties/http.rb +30 -32
- data/lib/roo_on_rails/railties/roo_identity.rb +12 -8
- data/lib/roo_on_rails/railties/sidekiq_integration.rb +7 -19
- data/lib/roo_on_rails/tasks/db.rake +27 -2
- data/lib/roo_on_rails/version.rb +1 -1
- data/lib/roo_on_rails.rb +0 -1
- data/roo_on_rails.gemspec +7 -5
- metadata +59 -39
- data/gemfiles/rails_4.gemfile +0 -13
- data/gemfiles/rails_5_1.gemfile +0 -13
- data/lib/roo_on_rails/railties/logging.rb +0 -25
data/.circleci/config.yml.erb
CHANGED
@@ -10,17 +10,34 @@
|
|
10
10
|
# * GEM_HOME
|
11
11
|
# * BUNDLE_PATH
|
12
12
|
# * BUNDLE_BIN
|
13
|
-
|
13
|
+
common_ruby_environment: &common_ruby_environment
|
14
|
+
environment:
|
15
|
+
RAILS_ENV: test
|
16
|
+
PGHOST: 127.0.0.1
|
17
|
+
PGUSER: postgres
|
18
|
+
POSTGRES_HOST_AUTH_METHOD: "trust"
|
19
|
+
common_pg_environment_vars: &common_pg_environment_vars
|
20
|
+
POSTGRES_USER: postgres
|
21
|
+
POSTGRES_DB: ror_testapp_test
|
22
|
+
POSTGRES_HOST_AUTH_METHOD: "trust"
|
14
23
|
<%
|
15
24
|
builds = [
|
16
|
-
['2.
|
17
|
-
['2.
|
18
|
-
['2.
|
19
|
-
|
20
|
-
['2.
|
21
|
-
['2.
|
22
|
-
['2.
|
23
|
-
|
25
|
+
['2.5.9', 'rails_5_2'],
|
26
|
+
['2.5.9', 'rails_6_0'],
|
27
|
+
['2.5.9', 'rails_6_1'],
|
28
|
+
|
29
|
+
['2.6.10', 'rails_5_2'],
|
30
|
+
['2.6.10', 'rails_6_0'],
|
31
|
+
['2.6.10', 'rails_6_1'],
|
32
|
+
|
33
|
+
['2.7.6', 'rails_6_0'],
|
34
|
+
['2.7.6', 'rails_6_1'],
|
35
|
+
|
36
|
+
['3.0.4', 'rails_6_0'],
|
37
|
+
['3.0.4', 'rails_6_1'],
|
38
|
+
|
39
|
+
['3.1.2', 'rails_6_1'],
|
40
|
+
['3.1.2', 'rails_7_0']
|
24
41
|
]
|
25
42
|
%>
|
26
43
|
version: 2
|
@@ -29,9 +46,11 @@ jobs:
|
|
29
46
|
build_<%= ruby %>_<%= variant %>:
|
30
47
|
docker:
|
31
48
|
- image: ruby:<%= ruby %>-alpine
|
49
|
+
<<: *common_ruby_environment
|
32
50
|
- image: postgres:9.6-alpine
|
33
51
|
environment:
|
34
52
|
PGDATA: /dev/shm/pgdata
|
53
|
+
<<: *common_pg_environment_vars
|
35
54
|
- image: redis:4-alpine
|
36
55
|
steps:
|
37
56
|
- checkout
|
data/.codecov.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.9
|
data/Appraisals
CHANGED
@@ -1,29 +1,44 @@
|
|
1
|
-
appraise 'rails-
|
2
|
-
gem 'rails', '~>
|
1
|
+
appraise 'rails-5-2' do
|
2
|
+
gem 'rails', '~> 5.2.0'
|
3
|
+
gem 'bootsnap', '>= 1.1.0', require: false
|
3
4
|
gem 'sqlite3', '~> 1.3.6'
|
4
|
-
gem 'pg', '~> 0.
|
5
|
-
gem 'sprockets', '~>3.0'
|
5
|
+
gem 'pg', '~> 0.18'
|
6
6
|
gem 'rake', '13.0.1'
|
7
|
+
gem 'dotenv', '~> 2.7.6'
|
7
8
|
end
|
8
9
|
|
9
|
-
appraise 'rails-
|
10
|
-
gem 'rails', '~>
|
11
|
-
gem '
|
10
|
+
appraise 'rails-6-0' do
|
11
|
+
gem 'rails', '~> 6.0.3'
|
12
|
+
gem 'bootsnap', '>= 1.1.0', require: false
|
13
|
+
gem 'sqlite3', '~> 1.4'
|
12
14
|
gem 'pg', '~> 0.18'
|
13
15
|
gem 'rake', '13.0.1'
|
16
|
+
gem 'dotenv', '~> 2.7.6'
|
14
17
|
end
|
15
18
|
|
16
|
-
appraise 'rails-
|
17
|
-
gem 'rails', '~>
|
18
|
-
gem '
|
19
|
-
gem '
|
20
|
-
gem '
|
19
|
+
appraise 'rails-6-1' do
|
20
|
+
gem 'rails', '~> 6.1.5'
|
21
|
+
gem 'bootsnap', require: false
|
22
|
+
gem 'sqlite3'
|
23
|
+
gem 'pg'
|
24
|
+
gem 'rake'
|
25
|
+
gem 'net-smtp', require: false
|
26
|
+
gem 'net-pop', require: false
|
27
|
+
gem 'net-imap', require: false
|
28
|
+
gem 'webpacker', '~>3.0'
|
29
|
+
gem 'psych', '< 4'
|
30
|
+
gem 'dotenv', '~> 2.7.6'
|
21
31
|
end
|
22
32
|
|
23
|
-
appraise 'rails-
|
24
|
-
gem 'rails', '~>
|
25
|
-
gem 'bootsnap',
|
26
|
-
gem 'sqlite3'
|
27
|
-
gem 'pg'
|
28
|
-
gem 'rake'
|
33
|
+
appraise 'rails-7-0' do
|
34
|
+
gem 'rails', '~> 7.0.3'
|
35
|
+
gem 'bootsnap', require: false
|
36
|
+
gem 'sqlite3'
|
37
|
+
gem 'pg'
|
38
|
+
gem 'rake'
|
39
|
+
gem 'net-smtp', require: false
|
40
|
+
gem 'net-pop', require: false
|
41
|
+
gem 'net-imap', require: false
|
42
|
+
gem 'webpacker', '~>3.0'
|
43
|
+
gem 'psych', '< 4'
|
29
44
|
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
# v2.2.0
|
2
|
+
|
3
|
+
Breaking changes:
|
4
|
+
|
5
|
+
- Drops Rails 4 support
|
6
|
+
- Drops Rails 5.0 support
|
7
|
+
- Drops Rails 5.1 support
|
8
|
+
- Drops Ruby 2.4 support
|
9
|
+
|
10
|
+
Features:
|
11
|
+
|
12
|
+
- Adds Rails 6.1 support
|
13
|
+
- Adds Rails 7.0 support
|
14
|
+
- Adds Ruby 2.7 support
|
15
|
+
- Adds Ruby 3.0 support
|
16
|
+
- Adds Ruby 3.1 support
|
17
|
+
|
18
|
+
# v2.1.2
|
19
|
+
|
20
|
+
Bug fix:
|
21
|
+
|
22
|
+
- fixes PopulateEnvFromJWT caching issue where a key that couldn't be fetched would be cached
|
23
|
+
|
24
|
+
# v2.1.0
|
25
|
+
|
26
|
+
Features:
|
27
|
+
|
28
|
+
- Rails 6 compatibility
|
29
|
+
|
1
30
|
# v2.0.0-pre.2
|
2
31
|
|
3
32
|
Features:
|
data/README.md
CHANGED
@@ -21,9 +21,6 @@
|
|
21
21
|
- [Disabling SSL enforcement](#disabling-ssl-enforcement)
|
22
22
|
- [Database configuration](#database-configuration)
|
23
23
|
- [Sidekiq](#sidekiq)
|
24
|
-
- [HireFire](#hirefire)
|
25
|
-
- [For Web Dynos](#for-web-dynos)
|
26
|
-
- [For Sidekiq Workers](#for-sidekiq-workers)
|
27
24
|
- [Logging](#logging)
|
28
25
|
- [Identity](#identity)
|
29
26
|
- [Google OAuth authentication](#google-oauth-authentication)
|
@@ -137,48 +134,6 @@ NB. If you are migrating to SLA-based queue names, do not set `SIDEKIQ_ENABLED`
|
|
137
134
|
to `true` before your old queues have finished processing (this will prevent
|
138
135
|
Sidekiq from seeing the old queues at all).
|
139
136
|
|
140
|
-
### HireFire
|
141
|
-
|
142
|
-
#### For Web Dynos
|
143
|
-
|
144
|
-
Web dynos can be autoscaled by HireFire _only_ if it has been configured to use the `Web.Logplex.Load` source and the Heroku runtime metrics lab feature has been enabled:
|
145
|
-
|
146
|
-
```bash
|
147
|
-
$ heroku labs:enable log-runtime-metrics -a your-service-name-here
|
148
|
-
```
|
149
|
-
|
150
|
-
You will also need a log drain for HireFire, but the RooOnRails helper below should configure this for you. You can check with
|
151
|
-
|
152
|
-
```bash
|
153
|
-
$ heroku drains | grep hirefire
|
154
|
-
https://logdrain.hirefire.io (d.00000000-0000-0000-0000-000000000000)
|
155
|
-
|
156
|
-
# No drain? Add with:
|
157
|
-
$ heroku drains:add -a your-service-name-here https://logdrain.hirefire.io
|
158
|
-
```
|
159
|
-
|
160
|
-
([HireFire docs for set up](https://help.hirefire.io/guides/logplex/load-logplex))
|
161
|
-
|
162
|
-
#### For Sidekiq Workers
|
163
|
-
|
164
|
-
When `HIREFIRE_TOKEN` is set an endpoint will be mounted at `/hirefire` that
|
165
|
-
reports the required worker count as a function of queue latency. By default we
|
166
|
-
add queue names in the style 'within1day', so if we notice an average latency in
|
167
|
-
that queue of more than an set threshold we'll request one more worker. If we
|
168
|
-
notice less than a threshold we'll request one less worker. These settings can
|
169
|
-
be customised via the following ENV variables
|
170
|
-
|
171
|
-
- `WORKER_INCREASE_THRESHOLD` (default 0.5)
|
172
|
-
- `WORKER_DECREASE_THRESHOLD` (default 0.1)
|
173
|
-
|
174
|
-
When setting the manager up in the HireFire web ui, the following settings must
|
175
|
-
be used:
|
176
|
-
|
177
|
-
- name: 'worker'
|
178
|
-
- type: 'Worker.HireFire.JobQueue'
|
179
|
-
- ratio: 1
|
180
|
-
- decrementable: 'true'
|
181
|
-
|
182
137
|
### Logging
|
183
138
|
|
184
139
|
For clearer and machine-parseable log output, the Rails logger is replaced by an
|
@@ -382,6 +337,11 @@ The command is designed to fix issues in many cases.
|
|
382
337
|
Pull requests are welcome on GitHub at
|
383
338
|
`https://github.com/deliveroo/roo_on_rails`.
|
384
339
|
|
340
|
+
## Releasing
|
341
|
+
|
342
|
+
1. Bump the version number in `lib/roo_on_rails/version.rb
|
343
|
+
1. Add an entry to the changelog
|
344
|
+
1. After merging to master release e.g. `bundle exec rake release`
|
385
345
|
|
386
346
|
## License
|
387
347
|
|
data/appraise
CHANGED
@@ -4,8 +4,7 @@
|
|
4
4
|
#
|
5
5
|
require 'yaml'
|
6
6
|
|
7
|
-
|
8
|
-
RUBIES = ['2.4.5', '2.5.5']
|
7
|
+
RUBIES = ['2.5.9', '2.6.10', '2.7.6', '3.0.4', '3.1.2'].freeze
|
9
8
|
APPRAISALS = `appraisal list`.strip.split(/\s+/)
|
10
9
|
|
11
10
|
# setup
|
@@ -14,7 +13,7 @@ RUBIES.each do |ruby|
|
|
14
13
|
system 'rbenv version'
|
15
14
|
system 'rbenv exec ruby -v'
|
16
15
|
system 'rbenv exec bundle check || rbenv exec bundle install'
|
17
|
-
system
|
16
|
+
system 'rbenv exec appraisal install'
|
18
17
|
end
|
19
18
|
|
20
19
|
# tests
|
data/gemfiles/rails_5_2.gemfile
CHANGED
@@ -7,8 +7,10 @@ gem "guard-rspec"
|
|
7
7
|
gem "appraisal"
|
8
8
|
gem "webmock"
|
9
9
|
gem "pg", "~> 0.18"
|
10
|
-
gem "sqlite3"
|
10
|
+
gem "sqlite3", "~> 1.3.6"
|
11
11
|
gem "rails", "~> 5.2.0"
|
12
12
|
gem "bootsnap", ">= 1.1.0", require: false
|
13
|
+
gem "rake", "13.0.1"
|
14
|
+
gem "dotenv", "~> 2.7.6"
|
13
15
|
|
14
16
|
gemspec path: "../"
|
@@ -7,7 +7,10 @@ gem "guard-rspec"
|
|
7
7
|
gem "appraisal"
|
8
8
|
gem "webmock"
|
9
9
|
gem "pg", "~> 0.18"
|
10
|
-
gem "sqlite3", "~> 1.
|
11
|
-
gem "rails", "~>
|
10
|
+
gem "sqlite3", "~> 1.4"
|
11
|
+
gem "rails", "~> 6.0.3"
|
12
|
+
gem "bootsnap", ">= 1.1.0", require: false
|
13
|
+
gem "rake", "13.0.1"
|
14
|
+
gem "dotenv", "~> 2.7.6"
|
12
15
|
|
13
16
|
gemspec path: "../"
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "guard"
|
6
|
+
gem "guard-rspec"
|
7
|
+
gem "appraisal"
|
8
|
+
gem "webmock"
|
9
|
+
gem "pg"
|
10
|
+
gem "sqlite3"
|
11
|
+
gem "rails", "~> 6.1.5"
|
12
|
+
gem "bootsnap", require: false
|
13
|
+
gem "rake"
|
14
|
+
gem "net-smtp", require: false
|
15
|
+
gem "net-pop", require: false
|
16
|
+
gem "net-imap", require: false
|
17
|
+
gem "webpacker", "~>3.0"
|
18
|
+
gem "psych", "< 4"
|
19
|
+
gem "dotenv", "~> 2.7.6"
|
20
|
+
|
21
|
+
gemspec path: "../"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "guard"
|
6
|
+
gem "guard-rspec"
|
7
|
+
gem "appraisal"
|
8
|
+
gem "webmock"
|
9
|
+
gem "pg"
|
10
|
+
gem "sqlite3"
|
11
|
+
gem "rails", "~> 6.1.5"
|
12
|
+
gem "bootsnap", require: false
|
13
|
+
gem "rake"
|
14
|
+
gem "net-smtp", require: false
|
15
|
+
gem "net-pop", require: false
|
16
|
+
gem "net-imap", require: false
|
17
|
+
gem "webpacker", "~>3.0"
|
18
|
+
gem "psych", "< 4"
|
19
|
+
|
20
|
+
gemspec path: "../"
|
data/lib/roo_on_rails/logger.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
require 'delegate'
|
2
2
|
require 'roo_on_rails/logfmt'
|
3
3
|
require 'rails/version'
|
4
|
-
|
5
|
-
if Rails::VERSION::MAJOR < 4
|
6
|
-
require 'logger'
|
7
|
-
else
|
8
|
-
require 'active_support/logger'
|
9
|
-
end
|
4
|
+
require 'active_support/logger'
|
10
5
|
|
11
6
|
module RooOnRails
|
12
7
|
# A compatible replacement for the standard Logger to provide context, similar
|
@@ -36,7 +31,7 @@ module RooOnRails
|
|
36
31
|
class Logger < SimpleDelegator
|
37
32
|
def initialize(io = STDOUT)
|
38
33
|
@show_timestamp = io.tty?
|
39
|
-
logger =
|
34
|
+
logger = ActiveSupport::Logger.new(io).tap do |l|
|
40
35
|
l.formatter = method(:_formatter)
|
41
36
|
end
|
42
37
|
super(logger)
|
@@ -113,13 +108,5 @@ module RooOnRails
|
|
113
108
|
thread_key = @_context_stack_key ||= "roo_on_rails:logging_context:#{object_id}".freeze
|
114
109
|
Thread.current[thread_key] ||= [{}]
|
115
110
|
end
|
116
|
-
|
117
|
-
def _default_logger_class
|
118
|
-
if Rails::VERSION::MAJOR < 4
|
119
|
-
::Logger
|
120
|
-
else
|
121
|
-
ActiveSupport::Logger
|
122
|
-
end
|
123
|
-
end
|
124
111
|
end
|
125
112
|
end
|
@@ -22,7 +22,8 @@ module RooOnRails
|
|
22
22
|
@app = app
|
23
23
|
@logger = logger
|
24
24
|
@url_mappings = url_mappings
|
25
|
-
@keys =
|
25
|
+
@keys = {}
|
26
|
+
@mapped_urls = {}
|
26
27
|
|
27
28
|
if skip_sig_verify && non_prod?
|
28
29
|
@logger.warn "JWTs signature verifification has been switched off in development."
|
@@ -3,9 +3,34 @@ module RooOnRails
|
|
3
3
|
class Database < Rails::Railtie
|
4
4
|
initializer 'roo_on_rails.database', after: 'active_record.initialize_database' do
|
5
5
|
ActiveSupport.on_load :active_record do
|
6
|
-
Rails.logger.
|
7
|
-
log.debug 'loading'
|
6
|
+
Rails.logger.debug('[roo_on_rails.database] loading')
|
8
7
|
|
8
|
+
if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
|
9
|
+
configs = ActiveRecord::Base.configurations.configurations
|
10
|
+
old_url_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'primary')
|
11
|
+
new_config_hash = old_url_config.configuration_hash.deep_dup
|
12
|
+
new_config_hash[:variables] ||= {}
|
13
|
+
statement_timeout = ENV.fetch('DATABASE_STATEMENT_TIMEOUT', 200)
|
14
|
+
# Use -1 to disable setting the statement timeout
|
15
|
+
new_config_hash[:variables][:statement_timeout] = statement_timeout unless statement_timeout == '-1'
|
16
|
+
new_config_hash[:reaping_frequency] = ENV['DATABASE_REAPING_FREQUENCY'] if ENV.key?('DATABASE_REAPING_FREQUENCY')
|
17
|
+
if old_url_config.respond_to?(:url)
|
18
|
+
new_url_config = ActiveRecord::DatabaseConfigurations::UrlConfig.new(
|
19
|
+
old_url_config.env_name,
|
20
|
+
old_url_config.name,
|
21
|
+
old_url_config.url,
|
22
|
+
new_config_hash
|
23
|
+
)
|
24
|
+
else
|
25
|
+
new_url_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(
|
26
|
+
old_url_config.env_name,
|
27
|
+
old_url_config.name,
|
28
|
+
new_config_hash
|
29
|
+
)
|
30
|
+
end
|
31
|
+
configs.delete(old_url_config)
|
32
|
+
configs << new_url_config
|
33
|
+
else
|
9
34
|
config = ActiveRecord::Base.configurations[Rails.env]
|
10
35
|
config['variables'] ||= {}
|
11
36
|
statement_timeout = ENV.fetch('DATABASE_STATEMENT_TIMEOUT', 200)
|
@@ -16,8 +41,9 @@ module RooOnRails
|
|
16
41
|
if ENV.key?('DATABASE_REAPING_FREQUENCY')
|
17
42
|
config['reaping_frequency'] = ENV['DATABASE_REAPING_FREQUENCY']
|
18
43
|
end
|
19
|
-
ActiveRecord::Base.establish_connection
|
20
44
|
end
|
45
|
+
|
46
|
+
ActiveRecord::Base.establish_connection
|
21
47
|
end
|
22
48
|
end
|
23
49
|
end
|
@@ -1,11 +1,9 @@
|
|
1
1
|
module RooOnRails
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
initializer 'roo_on_rails.default_env' do
|
4
|
-
Rails.logger.
|
5
|
-
|
6
|
-
|
7
|
-
RooOnRails::Environment.load
|
8
|
-
end
|
4
|
+
Rails.logger.debug '[roo_on_rails.default_env] loading'
|
5
|
+
require 'roo_on_rails/environment'
|
6
|
+
RooOnRails::Environment.load
|
9
7
|
end
|
10
8
|
end
|
11
9
|
end
|
@@ -4,12 +4,10 @@ module RooOnRails
|
|
4
4
|
module Railties
|
5
5
|
class GoogleOAuth < Rails::Railtie
|
6
6
|
initializer 'roo_on_rails.google_auth.middleware' do |app|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
_add_routes(app)
|
12
|
-
end
|
7
|
+
next unless Config.google_auth_enabled?
|
8
|
+
Rails.logger.debug '[roo_on_rails.google_auth] loading'
|
9
|
+
_add_middleware(app)
|
10
|
+
_add_routes(app)
|
13
11
|
end
|
14
12
|
|
15
13
|
private
|
@@ -2,45 +2,43 @@ module RooOnRails
|
|
2
2
|
module Railties
|
3
3
|
class HTTP < Rails::Railtie
|
4
4
|
initializer 'roo_on_rails.http' do |app|
|
5
|
-
Rails.logger.
|
6
|
-
log.debug 'loading'
|
5
|
+
Rails.logger.debug '[roo_on_rails.http] loading'
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
require 'rack/timeout/base'
|
8
|
+
require 'rack/ssl-enforcer'
|
9
|
+
require 'roo_on_rails/rack/safe_timeouts'
|
11
10
|
|
12
|
-
|
11
|
+
::Rack::Timeout::Logger.level = ::Logger::WARN
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
app.config.middleware.insert_before(
|
14
|
+
::Rack::Runtime,
|
15
|
+
::Rack::Timeout,
|
16
|
+
service_timeout: ENV.fetch('RACK_SERVICE_TIMEOUT', 15).to_i,
|
17
|
+
wait_timeout: ENV.fetch('RACK_WAIT_TIMEOUT', 30).to_i
|
18
|
+
)
|
20
19
|
|
21
|
-
|
20
|
+
middleware_to_insert_before = ::Rack::Head
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
# This needs to be inserted low in the stack, before Rails returns the
|
23
|
+
# thread-current connection to the pool.
|
24
|
+
if defined?(ActiveRecord)
|
25
|
+
app.config.middleware.insert_before(
|
26
|
+
middleware_to_insert_before,
|
27
|
+
RooOnRails::Rack::SafeTimeouts
|
28
|
+
)
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
if ENV.fetch('ROO_ON_RAILS_RACK_DEFLATE', 'YES').to_s =~ /\A(YES|TRUE|ON|1)\Z/i
|
32
|
+
app.config.middleware.use ::Rack::Deflater
|
33
|
+
end
|
35
34
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
end
|
35
|
+
# Don't use SslEnforcer in test environment as it breaks Capybara
|
36
|
+
unless Rails.env.test? ||
|
37
|
+
ENV.fetch('ROO_ON_RAILS_DISABLE_SSL_ENFORCEMENT', '') =~ /\A(YES|TRUE|ON|1)\Z/i
|
38
|
+
app.config.middleware.insert_before(
|
39
|
+
middleware_to_insert_before,
|
40
|
+
::Rack::SslEnforcer
|
41
|
+
)
|
44
42
|
end
|
45
43
|
end
|
46
44
|
end
|
@@ -4,13 +4,14 @@ module RooOnRails
|
|
4
4
|
module Railties
|
5
5
|
class RooIdentity < Rails::Railtie
|
6
6
|
initializer 'roo_on_rails.roo_identity.middleware' do |app|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
if RooOnRails::Rack::PopulateEnvFromJWT.configured?
|
8
|
+
Rails.logger.debug '[roo_on_rails.roo_identity.middleware] loading'
|
9
|
+
_add_middleware(app, Rails.logger)
|
10
|
+
else
|
11
|
+
Rails.logger.warn(
|
12
|
+
'[roo_on_rails.roo_identity.middleware] ' \
|
13
|
+
' not configured, roo.identity will be unavailable'
|
14
|
+
)
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
@@ -19,7 +20,10 @@ module RooOnRails
|
|
19
20
|
def _add_middleware(app, log)
|
20
21
|
app.config.middleware.use RooOnRails::Rack::PopulateEnvFromJWT, logger: log
|
21
22
|
rescue LoadError
|
22
|
-
log.error
|
23
|
+
log.error(
|
24
|
+
'[roo_on_rails.roo_identity.middleware] ' \
|
25
|
+
'the json-jwt gem is not in the bundle so Roo Identity will not be available'
|
26
|
+
)
|
23
27
|
end
|
24
28
|
end
|
25
29
|
end
|
@@ -8,27 +8,15 @@ module RooOnRails
|
|
8
8
|
module Railties
|
9
9
|
class SidekiqIntegration < Rails::Railtie
|
10
10
|
initializer 'roo_on_rails.sidekiq' do |app|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
next
|
15
|
-
end
|
16
|
-
|
17
|
-
log.debug 'loading'
|
18
|
-
require 'hirefire-resource'
|
19
|
-
|
20
|
-
config_sidekiq
|
21
|
-
config_sidekiq_metrics
|
22
|
-
config_hirefire(app)
|
11
|
+
unless RooOnRails::Config.sidekiq_enabled?
|
12
|
+
Rails.logger.debug '[roo_on_rails.sidekiq] skipping'
|
13
|
+
next
|
23
14
|
end
|
24
|
-
end
|
25
15
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
31
|
-
add_middleware(app)
|
16
|
+
Rails.logger.debug '[roo_on_rails.sidekiq] loading'
|
17
|
+
|
18
|
+
config_sidekiq
|
19
|
+
config_sidekiq_metrics
|
32
20
|
end
|
33
21
|
|
34
22
|
def config_sidekiq
|
@@ -8,12 +8,37 @@ if defined?(ActiveRecord)
|
|
8
8
|
|
9
9
|
namespace :migrate do
|
10
10
|
task extend_statement_timeout: :environment do
|
11
|
-
|
11
|
+
rails_version = Gem::Version.new(Rails.version)
|
12
|
+
|
13
|
+
if rails_version < Gem::Version.new('6.1')
|
12
14
|
config = ActiveRecord::Base.configurations[Rails.env]
|
13
15
|
config['variables'] ||= {}
|
14
16
|
config['variables']['statement_timeout'] = ENV.fetch('MIGRATION_STATEMENT_TIMEOUT', 10_000)
|
15
|
-
|
17
|
+
else
|
18
|
+
configs = ActiveRecord::Base.configurations.configurations
|
19
|
+
old_url_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'primary')
|
20
|
+
new_config_hash = old_url_config.configuration_hash.deep_dup
|
21
|
+
new_config_hash[:variables] ||= {}
|
22
|
+
new_config_hash[:variables][:statement_timeout] = ENV.fetch('MIGRATION_STATEMENT_TIMEOUT', 10_000)
|
23
|
+
if old_url_config.respond_to?(:url)
|
24
|
+
new_url_config = ActiveRecord::DatabaseConfigurations::UrlConfig.new(
|
25
|
+
old_url_config.env_name,
|
26
|
+
old_url_config.name,
|
27
|
+
old_url_config.url,
|
28
|
+
new_config_hash
|
29
|
+
)
|
30
|
+
else
|
31
|
+
new_url_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(
|
32
|
+
old_url_config.env_name,
|
33
|
+
old_url_config.name,
|
34
|
+
new_config_hash
|
35
|
+
)
|
36
|
+
end
|
37
|
+
configs.delete(old_url_config)
|
38
|
+
configs << new_url_config
|
16
39
|
end
|
40
|
+
|
41
|
+
ActiveRecord::Base.establish_connection
|
17
42
|
end
|
18
43
|
end
|
19
44
|
end
|
data/lib/roo_on_rails/version.rb
CHANGED