Allow different remote translation keys per tenant

Note we don't need to update the tests; the tests themselves help us
confirm that `Rails.application.secrets` and `Tenant.current_secrets`
return the same object on single-tenant applications.
This commit is contained in:
Javi Martín
2022-09-29 22:58:10 +02:00
parent 338f4929ca
commit 18f1d5c1a3
4 changed files with 9 additions and 6 deletions

View File

@@ -26,6 +26,6 @@ module RemotelyTranslatable
end end
def api_key_has_been_set_in_secrets? def api_key_has_been_set_in_secrets?
Rails.application.secrets.microsoft_api_key.present? Tenant.current_secrets.microsoft_api_key.present?
end end
end end

View File

@@ -57,7 +57,8 @@ staging:
# my_tenant_subdomain: # my_tenant_subdomain:
# secret_key: my_secret_value # secret_key: my_secret_value
# #
# Currently you can overwrite SMTP, SMS and manager settings. # Currently you can overwrite SMTP, SMS, manager and microsoft API
# settings.
<<: *maps <<: *maps
<<: *apis <<: *apis
@@ -92,7 +93,8 @@ preproduction:
# my_tenant_subdomain: # my_tenant_subdomain:
# secret_key: my_secret_value # secret_key: my_secret_value
# #
# Currently you can overwrite SMTP, SMS and manager settings. # Currently you can overwrite SMTP, SMS, manager and microsoft API
# settings.
twitter_key: "" twitter_key: ""
twitter_secret: "" twitter_secret: ""
facebook_key: "" facebook_key: ""
@@ -132,7 +134,8 @@ production:
# my_tenant_subdomain: # my_tenant_subdomain:
# secret_key: my_secret_value # secret_key: my_secret_value
# #
# Currently you can overwrite SMTP, SMS and manager settings. # Currently you can overwrite SMTP, SMS, manager and microsoft API
# settings.
twitter_key: "" twitter_key: ""
twitter_secret: "" twitter_secret: ""
facebook_key: "" facebook_key: ""

View File

@@ -36,7 +36,7 @@ class RemoteTranslations::Microsoft::AvailableLocales
uri = URI(host + path) uri = URI(host + path)
request = Net::HTTP::Get.new(uri) request = Net::HTTP::Get.new(uri)
request["Ocp-Apim-Subscription-Key"] = Rails.application.secrets.microsoft_api_key request["Ocp-Apim-Subscription-Key"] = Tenant.current_secrets.microsoft_api_key
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http| response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http|
http.request(request) http.request(request)

View File

@@ -6,7 +6,7 @@ class RemoteTranslations::Microsoft::Client
PREVENTING_TRANSLATION_KEY = "notranslate".freeze PREVENTING_TRANSLATION_KEY = "notranslate".freeze
def initialize def initialize
api_key = Rails.application.secrets.microsoft_api_key api_key = Tenant.current_secrets.microsoft_api_key
@client = TranslatorText::Client.new(api_key) @client = TranslatorText::Client.new(api_key)
end end