Skip to content
Snippets Groups Projects
Unverified Commit 0630101c authored by Khemissi Amir's avatar Khemissi Amir Committed by GitHub
Browse files

Resources migration: Added `migrations:roles` task. (#4001)

parent 3622a25e
No related branches found
No related tags found
No related merge requests found
......@@ -51,6 +51,10 @@ 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"
......
# frozen_string_literal: true
namespace :migrations do
COMMON = {
headers: { "Content-Type" => "application/json" }
}.freeze
desc "Migrates v2 resources to v3"
task :roles, [] => :environment do |_task, _args|
has_encountred_issue = 0
Role.select(:id, :name).where.not(name: Role::RESERVED_ROLE_NAMES).each do |r|
params = { role: { name: r.name } }
response = Net::HTTP.post(uri('roles'), payload(params), COMMON[:headers])
case response
when Net::HTTPCreated
puts green "Succesfully migrated Role:"
puts cyan " Name: #{r.name}"
else
puts red "Unable to migrate Role:"
puts red " Name: #{r.name}"
has_encountred_issue = 1 # At least one of the migrations failed.
end
end
puts
puts green "Roles migration complete."
puts yellow "In case of an error please retry the process to resolve." unless has_encountred_issue.zero?
exit has_encountred_issue
end
private
def encrypt_params(params)
unless Rails.configuration.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
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]
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
res = URI(Rails.configuration.v3_endpoint)
res.path = "/api/v1/migrations/#{path}.json"
res
end
def payload(params)
encrypted_params = { "encrypted_params" => encrypt_params(params) }
res = { "v2" => encrypted_params }
res.to_json
end
end
......@@ -16,6 +16,13 @@ SECRET_KEY_BASE=
BIGBLUEBUTTON_ENDPOINT=
BIGBLUEBUTTON_SECRET=
# The endpoint and "SECRET_KEY_BASE" for your Greenlight v3 instance.
# Set these if you are trying to migrate your resources to v3.
# Example:
#V3_ENDPOINT=https://v3.greenlight.test/
#V3_SECRET_KEY_BASE=
V3_ENDPOINT=
V3_SECRET_KEY_BASE=
# The hostname that the application is accessible from.
#
# Used to protect against various HTTP header attacks
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment