From a0df24b631889c483131c8bc1d9c199209da0e8a Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 2 May 2022 17:30:37 +0200 Subject: [PATCH] clean(SMTP.balancing): remove some env vars --- .../manager/application/_navigation.html.erb | 2 +- config/env.example | 9 +-------- config/env.example.optional | 9 +++++++++ config/environments/production.rb | 20 ++----------------- config/initializers/sendinblue.rb | 2 +- config/secrets.yml | 2 +- 6 files changed, 15 insertions(+), 29 deletions(-) diff --git a/app/views/manager/application/_navigation.html.erb b/app/views/manager/application/_navigation.html.erb index b7879e718..a82853123 100644 --- a/app/views/manager/application/_navigation.html.erb +++ b/app/views/manager/application/_navigation.html.erb @@ -25,7 +25,7 @@ as defined by the routes in the `admin/` namespace <%= link_to "Delayed Jobs", manager_delayed_job_path, class: "navigation__link" %> <%= link_to "Features", manager_flipper_path, class: "navigation__link" %> - <% if ENV["SENDINBLUE_ENABLED"] == "enabled" && ENV["SAML_IDP_ENABLED"] == "enabled" %> + <% if Rails.application.secrets.sendinblue[:enabled] && ENV["SAML_IDP_ENABLED"] == "enabled" %> <%= link_to "Sendinblue", ENV.fetch("SENDINBLUE_LOGIN_URL"), class: "navigation__link", target: '_blank' %> <% end %> diff --git a/config/env.example b/config/env.example index 56276ac9a..b3090af82 100644 --- a/config/env.example +++ b/config/env.example @@ -84,19 +84,12 @@ MATOMO_HOST="matomo.example.org" MAILJET_API_KEY="" MAILJET_SECRET_KEY="" -# Alternate SMTP Provider: SendInBlue -SENDINBLUE_ENABLED="disabled" +# Alternate SMTP Provider: SendInBlue/DoList SENDINBLUE_CLIENT_KEY="" SENDINBLUE_SMTP_KEY="" SENDINBLUE_USER_NAME="" # SENDINBLUE_LOGIN_URL="https://app.sendinblue.com/account/saml/login/truc" -# Ratio of emails sent using SendInBlue -# When enabled, N % of emails will be sent using SendInBlue -# (and the others using the default SMTP provider) -SENDINBLUE_BALANCING="disabled" -SENDINBLUE_BALANCING_VALUE="50" - # Alternate SMTP Provider: Mailtrap (mail catcher for staging environments) # When enabled, all emails will be sent using this provider MAILTRAP_ENABLED="disabled" diff --git a/config/env.example.optional b/config/env.example.optional index 08e47f706..e19e0d6b5 100644 --- a/config/env.example.optional +++ b/config/env.example.optional @@ -119,3 +119,12 @@ MATOMO_IFRAME_URL="https://matomo.example.org/index.php?module=CoreAdminHome&act # DOLIST_ACCOUNT_ID="" # DOLIST_NO_REPLY_EMAIL="" # DOLIST_API_KEY="" + +# Ratio of emails sent using SendInBlue +# When present, N % of emails will be sent using SendInBlue +# (and the others using the default SMTP provider) +SENDINBLUE_BALANCING_VALUE="50" +# Ratio of emails sent using DoList +# When present, N % of emails will be sent using DoList +# (and the others using the default SMTP provider) +DOLIST_BALANCING_VALUE="50" diff --git a/config/environments/production.rb b/config/environments/production.rb index 91b050442..bf8f75a4d 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -81,24 +81,8 @@ Rails.application.configure do elsif ENV['MAILCATCHER_ENABLED'] == 'enabled' config.action_mailer.delivery_method = :mailcatcher else - - sendinblue_weigth = case [ENV['SENDINBLUE_ENABLED'] == 'enabled', ENV['SENDINBLUE_BALANCING'] == 'enabled'] - in [false, _] - 0 - in [true, false] - 100 - else - ENV.fetch('SENDINBLUE_BALANCING_VALUE').to_i - end - - dolist_weigth = case [ENV['DOLIST_ENABLED'] == 'enabled', ENV['DOLIST_BALANCING'] == 'enabled'] - in [false, _] - 0 - in [true, false] - 100 - else - ENV.fetch('DOLIST_BALANCING_VALUE').to_i - end + sendinblue_weigth = ENV.fetch('SENDINBLUE_BALANCING_VALUE') { 0 }.to_i + dolist_weigth = ENV.fetch('DOLIST_BALANCING_VALUE') { 0 }.to_i ActionMailer::Base.add_delivery_method :balancer, BalancerDeliveryMethod config.action_mailer.balancer_settings = { diff --git a/config/initializers/sendinblue.rb b/config/initializers/sendinblue.rb index 206b3905d..379f0b203 100644 --- a/config/initializers/sendinblue.rb +++ b/config/initializers/sendinblue.rb @@ -1,4 +1,4 @@ -if ENV.fetch('SENDINBLUE_ENABLED') == 'enabled' +if ENV.key?('SENDINBLUE_BALANCING_VALUE') require 'sib-api-v3-sdk' ActiveSupport.on_load(:action_mailer) do diff --git a/config/secrets.yml b/config/secrets.yml index 213c41d98..35a8a5c42 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -53,7 +53,7 @@ defaults: &defaults client_secret: <%= ENV['HELPSCOUT_CLIENT_SECRET'] %> webhook_secret: <%= ENV['HELPSCOUT_WEBHOOK_SECRET'] %> sendinblue: - enabled: <%= ENV['SENDINBLUE_ENABLED'] == 'enabled' %> + enabled: <%= ENV.key?('SENDINBLUE_BALANCING_VALUE') %> username: <%= ENV['SENDINBLUE_USER_NAME'] %> client_key: <%= ENV['SENDINBLUE_CLIENT_KEY'] %> smtp_key: <%= ENV['SENDINBLUE_SMTP_KEY'] %>