From 5e7830b888614d645646eb9bec2843fc3330989b Mon Sep 17 00:00:00 2001
From: Khemissi Amir <amir.khemissi@insat.ucar.tn>
Date: Mon, 31 Oct 2022 14:53:05 +0100
Subject: [PATCH] V2 resources migration: Removed the use of
 `Rails.configuration` in tasks. (#4048)

Co-authored-by: Ahmad Farhat <ahmad.af.farhat@gmail.com>
---
 config/application.rb                |  4 ----
 lib/tasks/migrations/migrations.rake | 14 ++++++--------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/config/application.rb b/config/application.rb
index c678a12f..d23746fd 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -51,10 +51,6 @@ module Greenlight
     # The default callback url that bn launcher will redirect to
     config.gl_callback_url = ENV["GL_CALLBACK_URL"]
 
-    # Greenlight V3 variables:
-    config.v3_endpoint = ENV["V3_ENDPOINT"]
-    config.v3_secret_key_base = ENV["V3_SECRET_KEY_BASE"]
-
     # Default credentials (test-install.blindsidenetworks.com/bigbluebutton).
     config.bigbluebutton_endpoint_default = "http://test-install.blindsidenetworks.com/bigbluebutton/api/"
     config.bigbluebutton_secret_default = "8cd8ef52e8e101574e400365b55e11a6"
diff --git a/lib/tasks/migrations/migrations.rake b/lib/tasks/migrations/migrations.rake
index d012f95c..bced060d 100644
--- a/lib/tasks/migrations/migrations.rake
+++ b/lib/tasks/migrations/migrations.rake
@@ -4,7 +4,7 @@ namespace :migrations do
   DEFAULT_ROLES_MAP = { "admin" => "Administrator", "user" => "User" }.freeze
   COMMON = {
     headers: { "Content-Type" => "application/json" },
-    batch_size: 1000,
+    batch_size: 500,
   }.freeze
 
   desc "Migrates v2 resources to v3"
@@ -116,25 +116,23 @@ namespace :migrations do
   private
 
   def encrypt_params(params)
-    unless Rails.configuration.v3_secret_key_base.present?
+    unless ENV["V3_SECRET_KEY_BASE"].present?
       raise red 'Unable to migrate: No "V3_SECRET_KEY_BASE" provided, please check your .env file.'
     end
 
-    unless Rails.configuration.v3_secret_key_base.size >= 32
+    unless ENV["V3_SECRET_KEY_BASE"].size >= 32
       raise red 'Unable to migrate: Provided "V3_SECRET_KEY_BASE" must be at least 32 charchters in length.'
     end
 
-    key = Rails.configuration.v3_secret_key_base[0..31]
+    key = ENV["V3_SECRET_KEY_BASE"][0..31]
     crypt = ActiveSupport::MessageEncryptor.new(key, cipher: 'aes-256-gcm', serializer: Marshal)
     crypt.encrypt_and_sign(params, expires_in: 10.seconds)
   end
 
   def uri(path)
-    unless Rails.configuration.v3_endpoint.present?
-      raise red 'Unable to migrate: No "V3_ENDPOINT" provided, please check your .env file.'
-    end
+    raise red 'Unable to migrate: No "V3_ENDPOINT" provided, please check your .env file.' unless ENV["V3_ENDPOINT"].present?
 
-    res = URI(Rails.configuration.v3_endpoint)
+    res = URI(ENV["V3_ENDPOINT"])
     res.path = "/api/v1/migrations/#{path}.json"
     res
   end
-- 
GitLab