diff --git a/app/lib/api/client.rb b/app/lib/api/client.rb index d7f7ea783..a9de5f74b 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 b3663f75a..6c25f37f9 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 @@ class RNFService 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 050e5d49b..aff510d71 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 8dc3211e7..89d9d7e3f 100644 --- a/config/initializers/02_urls.rb +++ b/config/initializers/02_urls.rb @@ -9,7 +9,7 @@ API_GEO_URL = ENV.fetch("API_GEO_URL", "https://geo.api.gouv.fr") 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")