From a3121099089120c40a938e2a97f6bf3f78c50f2c Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Mon, 6 Mar 2023 16:58:37 +0100 Subject: [PATCH 1/3] add request_lang middleware --- Gemfile | 3 ++- Gemfile.lock | 37 ++++++++++++++++++++++--------------- app.rb | 6 ++++++ lib/rack/request_lang.rb | 16 ++++++++++++++++ 4 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 lib/rack/request_lang.rb diff --git a/Gemfile b/Gemfile index 5ff855ea..c80ea2e9 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem 'rake', '~> 10.0' gem 'sinatra', '~> 1.0' gem 'sinatra-advanced-routes' gem 'sinatra-contrib', '~> 1.0' +gem 'request_store' # Rack middleware gem 'ffi' @@ -47,7 +48,7 @@ gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.g gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'master' gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master' -gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'development' +gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'feature/support-multilingual-read-one-language-from-request-parameter' group :development do # bcrypt_pbkdf and ed35519 is required for capistrano deployments when using ed25519 keys; see https://github.com/miloserdow/capistrano-deploy/issues/42 diff --git a/Gemfile.lock b/Gemfile.lock index d02647ba..ba50a063 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,7 +11,7 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/goo.git - revision: cda6aff2338e2a2831e4e7bf716abdf8fa8483d2 + revision: b769c165906163e30a026dba511ae1069c4eed3d branch: development specs: goo (0.0.2) @@ -53,8 +53,8 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: f4395ea6b32df8cee25b3ccf8515c9c75d18b19a - branch: development + revision: f8c8f569cc282ec31ad181cdbe355f7899983b3f + branch: feature/support-multilingual-read-one-language-from-request-parameter specs: ontologies_linked_data (0.0.1) activesupport @@ -112,7 +112,7 @@ GEM bcrypt_pbkdf (1.1.0) bigdecimal (1.4.2) builder (3.2.4) - capistrano (3.17.1) + capistrano (3.17.2) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -125,7 +125,8 @@ GEM capistrano (~> 3.1) sshkit (~> 1.3) coderay (1.1.3) - concurrent-ruby (1.2.0) + concurrent-ruby (1.2.2) + connection_pool (2.3.0) cube-ruby (0.0.3) dante (0.2.0) date (3.3.3) @@ -160,8 +161,8 @@ GEM ffi (1.15.5) get_process_mem (0.2.7) ffi (~> 1.0) - google-apis-analytics_v3 (0.12.0) - google-apis-core (>= 0.9.1, < 2.a) + google-apis-analytics_v3 (0.13.0) + google-apis-core (>= 0.11.0, < 2.a) google-apis-core (0.11.0) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) @@ -206,7 +207,7 @@ GEM method_source (1.0.0) mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) + mime-types-data (3.2023.0218.1) mini_mime (1.1.2) minitest (4.7.5) minitest-stub_any_instance (1.0.3) @@ -228,7 +229,7 @@ GEM net-protocol net-ssh (7.0.1) netrc (0.11.0) - newrelic_rpm (8.16.0) + newrelic_rpm (9.0.0) oj (2.18.5) omni_logger (0.1.4) logger @@ -256,24 +257,29 @@ GEM rack-test (2.0.2) rack (>= 1.3) rack-timeout (0.6.3) - raindrops (0.20.0) + raindrops (0.20.1) rake (10.5.0) rdf (1.0.8) addressable (>= 2.2) redcarpet (3.6.0) - redis (4.8.1) + redis (5.0.6) + redis-client (>= 0.9.0) redis-activesupport (5.3.0) activesupport (>= 3, < 8) redis-store (>= 1.3, < 2) + redis-client (0.13.0) + connection_pool redis-rack-cache (2.2.1) rack-cache (>= 1.10, < 2) redis-store (>= 1.6, < 2) - redis-store (1.9.1) - redis (>= 4, < 5) + redis-store (1.9.2) + redis (>= 4, < 6) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) uber (< 0.2.0) + request_store (1.5.1) + rack (>= 1.4) rest-client (2.1.0) http-accept (>= 1.7.0, < 2.0) http-cookie (>= 1.0.2, < 2.0) @@ -316,12 +322,12 @@ GEM rack-test sinatra (~> 1.4.0) tilt (>= 1.3, < 3) - sshkit (1.21.3) + sshkit (1.21.4) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) systemu (2.6.5) temple (0.10.0) - tilt (2.0.11) + tilt (2.1.0) timeout (0.3.2) trailblazer-option (0.1.2) tzinfo (2.0.6) @@ -384,6 +390,7 @@ DEPENDENCIES redis redis-activesupport redis-rack-cache (~> 2.0) + request_store shotgun! simplecov simplecov-cobertura diff --git a/app.rb b/app.rb index 5360ae4b..46457c86 100644 --- a/app.rb +++ b/app.rb @@ -29,6 +29,7 @@ require_relative 'lib/rack/cube_reporter' require_relative 'lib/rack/param_translator' require_relative 'lib/rack/slice_detection' +require_relative 'lib/rack/request_lang' # Logging setup require_relative "config/logging" @@ -36,6 +37,8 @@ # Inflector setup require_relative "config/inflections" +require 'request_store' + # Protection settings set :protection, :except => :path_traversal @@ -143,6 +146,9 @@ use Rack::PostBodyToParams use Rack::ParamTranslator +use RequestStore::Middleware +use Rack::RequestLang + use LinkedData::Security::Authorization use LinkedData::Security::AccessDenied diff --git a/lib/rack/request_lang.rb b/lib/rack/request_lang.rb new file mode 100644 index 00000000..b2221041 --- /dev/null +++ b/lib/rack/request_lang.rb @@ -0,0 +1,16 @@ +module Rack + class RequestLang + + def initialize(app = nil, options = {}) + @app = app + end + + def call(env) + r = Rack::Request.new(env) + lang = r.params["lang"] || r.params["language"] + lang = lang.upcase.to_sym if lang + RequestStore.store[:requested_lang] = lang + @app.call(env) + end + end +end \ No newline at end of file From 207884bede33c54e764117843843220d26244674 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Mon, 6 Mar 2023 19:17:40 +0100 Subject: [PATCH 2/3] pin redis gem version to 4.8.1 --- Gemfile | 2 +- Gemfile.lock | 82 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 49 insertions(+), 35 deletions(-) diff --git a/Gemfile b/Gemfile index 82282bee..1737403e 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'rack-timeout' gem 'redis-rack-cache', '~> 2.0' # Data access (caching) -gem 'redis' +gem 'redis', '~> 4.8.1' gem 'redis-activesupport' # Monitoring diff --git a/Gemfile.lock b/Gemfile.lock index 27deaffe..e423a14a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/ncbo/goo.git - revision: 077c674a6e277a51dca4ca681e49e3e3a55b918a + revision: 919c20dec58375eb8a4dd1aed47864e2ad7bacfa branch: master specs: goo (0.0.2) @@ -15,7 +15,7 @@ GIT GIT remote: https://github.com/ncbo/ncbo_annotator.git - revision: 71d41e3afb35dafe29abfb6d9becaadc725bad36 + revision: 964f0680799421ab24eddc974d9f2995c6c88734 branch: master specs: ncbo_annotator (0.0.1) @@ -26,7 +26,7 @@ GIT GIT remote: https://github.com/ncbo/ncbo_cron.git - revision: a1a4babc0b5e36325b5af667a6a50b7af1f5f891 + revision: c09d76eeb131caf422c18ba49580db1b47df86dc branch: master specs: ncbo_cron (0.0.1) @@ -42,7 +42,7 @@ GIT GIT remote: https://github.com/ncbo/ncbo_ontology_recommender.git - revision: 6010ff60b99dc1282822b8a1fb59bd59f453755f + revision: d0ac992c88bd417f2f2137ba62934c3c41b6db7c branch: master specs: ncbo_ontology_recommender (0.0.1) @@ -53,7 +53,7 @@ GIT GIT remote: https://github.com/ncbo/ontologies_linked_data.git - revision: 4f9139d870c3b1771af1127afa17b679bd0f60dc + revision: 546b3a45a6f359c09f0cc95d954f03e979b4847a branch: master specs: ontologies_linked_data (0.0.1) @@ -112,7 +112,7 @@ GEM bcrypt_pbkdf (1.1.0) bigdecimal (1.4.2) builder (3.2.4) - capistrano (3.17.1) + capistrano (3.17.2) airbrussh (>= 1.0.0) i18n rake (>= 10.0.0) @@ -125,15 +125,16 @@ GEM capistrano (~> 3.1) sshkit (~> 1.3) coderay (1.1.3) - concurrent-ruby (1.1.10) + concurrent-ruby (1.2.2) cube-ruby (0.0.3) dante (0.2.0) + date (3.3.3) declarative (0.0.20) docile (1.4.0) domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) ed25519 (1.3.0) - faraday (1.10.2) + faraday (1.10.3) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) @@ -159,9 +160,9 @@ GEM ffi (1.15.5) get_process_mem (0.2.7) ffi (~> 1.0) - google-apis-analytics_v3 (0.12.0) - google-apis-core (>= 0.9.1, < 2.a) - google-apis-core (0.9.1) + google-apis-analytics_v3 (0.13.0) + google-apis-core (>= 0.11.0, < 2.a) + google-apis-core (0.11.0) addressable (~> 2.5, >= 2.5.1) googleauth (>= 0.16.2, < 2.a) httpclient (>= 2.8.1, < 3.a) @@ -186,36 +187,48 @@ GEM httpclient (2.8.3) i18n (0.9.5) concurrent-ruby (~> 1.0) - json (2.6.2) + json (2.6.3) json-schema (2.8.1) addressable (>= 2.4) - json_pure (2.6.2) - jwt (2.5.0) + json_pure (2.6.3) + jwt (2.7.0) kgio (2.11.4) - libxml-ruby (3.2.4) - logger (1.5.1) + libxml-ruby (4.0.0) + logger (1.5.3) macaddr (1.7.2) systemu (~> 2.6.5) - mail (2.7.1) + mail (2.8.1) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp memoist (0.16.2) method_source (1.0.0) mime-types (3.4.1) mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) + mime-types-data (3.2023.0218.1) mini_mime (1.1.2) minitest (4.7.5) minitest-stub_any_instance (1.0.3) mlanett-redis-lock (0.2.7) redis multi_json (1.15.0) - multipart-post (2.2.3) + multipart-post (2.3.0) net-http-persistent (2.9.4) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout net-scp (4.0.0) net-ssh (>= 2.6.5, < 8.0.0) + net-smtp (0.3.3) + net-protocol net-ssh (7.0.1) netrc (0.11.0) - newrelic_rpm (8.13.1) + newrelic_rpm (9.0.0) oj (2.18.5) omni_logger (0.1.4) logger @@ -223,10 +236,10 @@ GEM parseconfig (1.1.2) pony (1.13.1) mail (>= 2.0) - pry (0.14.1) + pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - public_suffix (5.0.0) + public_suffix (5.0.1) rack (1.6.13) rack-accept (0.4.5) rack (>= 0.4) @@ -243,20 +256,20 @@ GEM rack-test (2.0.2) rack (>= 1.3) rack-timeout (0.6.3) - raindrops (0.20.0) + raindrops (0.20.1) rake (10.5.0) rdf (1.0.8) addressable (>= 2.2) - redcarpet (3.5.1) - redis (4.8.0) + redcarpet (3.6.0) + redis (4.8.1) redis-activesupport (5.3.0) activesupport (>= 3, < 8) redis-store (>= 1.3, < 2) redis-rack-cache (2.2.1) rack-cache (>= 1.10, < 2) redis-store (>= 1.6, < 2) - redis-store (1.9.1) - redis (>= 4, < 5) + redis-store (1.9.2) + redis (>= 4, < 6) representable (3.2.0) declarative (< 0.1.0) trailblazer-option (>= 0.1.1, < 0.2.0) @@ -281,7 +294,7 @@ GEM faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) - simplecov (0.21.2) + simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) @@ -303,14 +316,15 @@ GEM rack-test sinatra (~> 1.4.0) tilt (>= 1.3, < 3) - sshkit (1.21.3) + sshkit (1.21.4) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) systemu (2.6.5) - temple (0.9.1) - tilt (2.0.11) + temple (0.10.0) + tilt (2.1.0) + timeout (0.3.2) trailblazer-option (0.1.2) - tzinfo (2.0.5) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) uber (0.1.0) unf (0.1.4) @@ -324,7 +338,7 @@ GEM unicorn (>= 4, < 7) uuid (2.3.9) macaddr (~> 1.0) - webrick (1.7.0) + webrick (1.8.1) PLATFORMS x86_64-darwin-21 @@ -367,7 +381,7 @@ DEPENDENCIES rack-timeout rake (~> 10.0) redcarpet - redis + redis (~> 4.8.1) redis-activesupport redis-rack-cache (~> 2.0) shotgun! From ae23ce082cab23158d0f038e9a7d956776d14376 Mon Sep 17 00:00:00 2001 From: Syphax Bouazzouni Date: Mon, 6 Mar 2023 19:31:15 +0100 Subject: [PATCH 3/3] update Gemfile.lock --- Gemfile | 2 +- Gemfile.lock | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index b8371e74..71cdf420 100644 --- a/Gemfile +++ b/Gemfile @@ -48,7 +48,7 @@ gem 'ncbo_annotator', git: 'https://github.com/ontoportal-lirmm/ncbo_annotator.g gem 'ncbo_cron', git: 'https://github.com/ontoportal-lirmm/ncbo_cron.git', branch: 'master' gem 'ncbo_ontology_recommender', git: 'https://github.com/ncbo/ncbo_ontology_recommender.git', branch: 'master' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'master' -gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'feature/support-multilingual-read-one-language-from-request-parameter' +gem 'ontologies_linked_data', git: 'https://github.com/ontoportal-lirmm/ontologies_linked_data.git', branch: 'development' group :development do # bcrypt_pbkdf and ed35519 is required for capistrano deployments when using ed25519 keys; see https://github.com/miloserdow/capistrano-deploy/issues/42 diff --git a/Gemfile.lock b/Gemfile.lock index 449708f4..38c87943 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -53,8 +53,8 @@ GIT GIT remote: https://github.com/ontoportal-lirmm/ontologies_linked_data.git - revision: f8c8f569cc282ec31ad181cdbe355f7899983b3f - branch: feature/support-multilingual-read-one-language-from-request-parameter + revision: 69756f8a7cff39d283065217559c68820d6d95e3 + branch: development specs: ontologies_linked_data (0.0.1) activesupport @@ -126,7 +126,6 @@ GEM sshkit (~> 1.3) coderay (1.1.3) concurrent-ruby (1.2.2) - connection_pool (2.3.0) cube-ruby (0.0.3) dante (0.2.0) date (3.3.3) @@ -262,13 +261,10 @@ GEM rdf (1.0.8) addressable (>= 2.2) redcarpet (3.6.0) - redis (5.0.6) - redis-client (>= 0.9.0) + redis (4.8.1) redis-activesupport (5.3.0) activesupport (>= 3, < 8) redis-store (>= 1.3, < 2) - redis-client (0.13.0) - connection_pool redis-rack-cache (2.2.1) rack-cache (>= 1.10, < 2) redis-store (>= 1.6, < 2)