From cb2fd59523b0dbeb12e9ad328b53387f1fd5273e Mon Sep 17 00:00:00 2001 From: mfo Date: Thu, 5 Dec 2024 15:57:33 +0100 Subject: [PATCH] feat(rnf): switch to new url and auth method --- app/lib/api/client.rb | 5 +++-- app/services/rnf_service.rb | 10 +++++++++- config/env.example.optional | 3 +++ config/initializers/02_urls.rb | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/lib/api/client.rb b/app/lib/api/client.rb index d7f7ea783be..a9de5f74b56 100644 --- a/app/lib/api/client.rb +++ b/app/lib/api/client.rb @@ -5,13 +5,14 @@ class API::Client TIMEOUT = 10 - def call(url:, params: nil, body: nil, json: nil, headers: nil, method: :get, authorization_token: nil, schema: nil, timeout: TIMEOUT) + def call(url:, params: nil, body: nil, json: nil, headers: nil, method: :get, authorization_token: nil, schema: nil, timeout: TIMEOUT, typhoeus_options: {}) response = case method when :get Typhoeus.get(url, headers: headers_with_authorization(headers, false, authorization_token), params:, - timeout: TIMEOUT) + timeout: TIMEOUT, + **typhoeus_options) when :post Typhoeus.post(url, headers: headers_with_authorization(headers, json, authorization_token), diff --git a/app/services/rnf_service.rb b/app/services/rnf_service.rb index b3663f75aa9..6c25f37f9d3 100644 --- a/app/services/rnf_service.rb +++ b/app/services/rnf_service.rb @@ -4,7 +4,7 @@ class RNFService include Dry::Monads[:result] def call(rnf_id:) - result = API::Client.new.(url: "#{url}/#{rnf_id}", schema:) + result = API::Client.new.(url: "#{url}/#{rnf_id}", schema:, headers:, typhoeus_options:) case result in Success(body:) Success(body) @@ -21,6 +21,14 @@ def call(rnf_id:) private + def headers + { Token: ENV['RNF_TOKEN'] } + end + + def typhoeus_options + { ssl_verifyhost: 0 } + end + def schema JSONSchemer.schema(Rails.root.join('app/schemas/rnf.json')) end diff --git a/config/env.example.optional b/config/env.example.optional index 050e5d49bec..aff510d7170 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -15,6 +15,9 @@ DS_ENV="staging" # You know, we are a french team # TEAM_ON_STRIKE='pas content.' +# RNF auth +RNF_TOKEN="" + # France Connect usage # FRANCE_CONNECT_ENABLED="disabled" # "enabled" by default # FC_PARTICULIER_ID="" diff --git a/config/initializers/02_urls.rb b/config/initializers/02_urls.rb index 8dc3211e718..89d9d7e3f39 100644 --- a/config/initializers/02_urls.rb +++ b/config/initializers/02_urls.rb @@ -9,7 +9,7 @@ API_PARTICULIER_URL = ENV.fetch("API_PARTICULIER_URL", "https://particulier.api.gouv.fr/api") API_TCHAP_URL = ENV.fetch("API_TCHAP_URL", "https://matrix.agent.tchap.gouv.fr/_matrix/identity/api/v1") API_COJO_URL = ENV.fetch("API_COJO_URL", nil) -API_RNF_URL = ENV.fetch("API_RNF_URL", "https://rnf.apps.app1.numerique-interieur.com") +API_RNF_URL = ENV.fetch("API_RNF_URL", "https://sir.ines-api-m2m.interieur.gouv.fr/rnf/v1") API_RECHERCHE_ENTREPRISE_URL = ENV.fetch("API_RECHERCHE_ENTREPRISE_URL", "https://recherche-entreprises.api.gouv.fr") HELPSCOUT_API_URL = ENV.fetch("HELPSCOUT_API_URL", "https://api.helpscout.net/v2") SENDINBLUE_API_URL = ENV.fetch("SENDINBLUE_API_URL", "https://in-automate.sendinblue.com/api/v2")