Skip to content
Snippets Groups Projects
Unverified Commit d8cc171c authored by Ahmad Farhat's avatar Ahmad Farhat Committed by GitHub
Browse files

Added configuration:check rake task that checks a configuration (#4785)

* Added configuration:check rake task that checks a configuration

* CR
parent ac2655c3
Branches
No related tags found
No related merge requests found
......@@ -48,9 +48,9 @@ Rails.application.configure do
user_name: ENV.fetch('SMTP_USERNAME', nil),
password: ENV.fetch('SMTP_PASSWORD', nil),
authentication: ENV.fetch('SMTP_AUTH', nil),
enable_starttls_auto: ENV.fetch('SMTP_STARTTLS_AUTO', true),
enable_starttls: ENV.fetch('SMTP_STARTTLS', false),
tls: ENV.fetch('SMTP_TLS', 'false') != 'false',
enable_starttls_auto: ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_STARTTLS_AUTO', 'true')),
enable_starttls: ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_STARTTLS', 'false')),
tls: ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_TLS', 'false')),
openssl_verify_mode: ENV.fetch('SMTP_SSL_VERIFY', 'true') == 'false' ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
}
config.action_mailer.default_options = {
......
......@@ -58,9 +58,9 @@ Rails.application.configure do
user_name: ENV.fetch('SMTP_USERNAME'),
password: ENV.fetch('SMTP_PASSWORD'),
authentication: ENV.fetch('SMTP_AUTH'),
enable_starttls_auto: ENV.fetch('SMTP_STARTTLS_AUTO', true),
enable_starttls: ENV.fetch('SMTP_STARTTLS', false),
tls: ENV.fetch('SMTP_TLS', 'false') != 'false',
enable_starttls_auto: ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_STARTTLS_AUTO', 'true')),
enable_starttls: ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_STARTTLS', 'false')),
tls: ActiveModel::Type::Boolean.new.cast(ENV.fetch('SMTP_TLS', 'false')),
openssl_verify_mode: ENV.fetch('SMTP_SSL_VERIFY', 'true') == 'false' ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
}
config.action_mailer.default_options = {
......@@ -70,7 +70,7 @@ Rails.application.configure do
config.action_mailer.perform_deliveries = false
end
config.action_mailer.raise_delivery_errors = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_caching = false
config.action_mailer.deliver_later_queue_name = 'mailing'
......
# frozen_string_literal: true
require_relative 'task_helpers'
namespace :configuration do
desc 'Checks that the application was configured correctly'
task check: :environment do
required_env_vars = %w[SECRET_KEY_BASE BIGBLUEBUTTON_ENDPOINT BIGBLUEBUTTON_SECRET DATABASE_URL REDIS_URL].freeze
# Initial check that variables are set
info 'Checking required environment variables:'
required_env_vars.each do |var|
failed("#{var} not set correctly") if ENV[var].blank?
end
passed
info 'Checking connection to Postgres Database:'
begin
ActiveRecord::Base.establish_connection # Establishes connection
ActiveRecord::Base.connection # Calls connection object
failed('Unable to connect to Database') unless ActiveRecord::Base.connected?
rescue StandardError => e
failed("Unable to connect to Database - #{e}")
end
passed
info 'Checking connection to Redis Cache:'
begin
Redis.new.ping
rescue StandardError => e
failed("Unable to connect to Redis - #{e}")
end
passed
info 'Checking connection to BigBlueButton:'
test_request(Rails.configuration.bigbluebutton_endpoint)
checksum = Digest::SHA1.hexdigest("getMeetings#{Rails.configuration.bigbluebutton_secret}")
test_request("#{Rails.configuration.bigbluebutton_endpoint}getMeetings?checksum=#{checksum}")
passed
if ENV['SMTP_SERVER'].present?
info 'Checking connection to SMTP Server'
begin
UserMailer.with(to: ENV.fetch('SMTP_SENDER_EMAIL', nil), subject: ENV.fetch('SMTP_SENDER_EMAIL', nil)).test_email.deliver_now
rescue StandardError => e
failed("Unable to connect to SMTP Server - #{e}")
end
passed
end
exit 0
end
end
# Takes the full URL including the protocol
def test_request(url)
uri = URI(url)
res = Net::HTTP.get(uri)
doc = Nokogiri::XML(res)
failed("Could not get a valid response from BigBlueButton server - #{res}") if doc.css('returncode').text != 'SUCCESS'
rescue StandardError => e
failed("Error connecting to BigBlueButton server - #{e}")
end
def passed
success 'Passed'
end
def failed(msg)
err "Failed - #{msg}"
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment