Skip to content

Commit

Permalink
Sets config.eager_load to false for production envs
Browse files Browse the repository at this point in the history
  • Loading branch information
dwelch-r7 committed Mar 21, 2023
1 parent feaddc0 commit acf23e9
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 32 deletions.
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Application < Rails::Application
when "test"
config.eager_load = false
when "production"
config.eager_load = true
config.eager_load = false
end

if ActiveRecord.respond_to?(:legacy_connection_handling=)
Expand Down
50 changes: 19 additions & 31 deletions lib/msf/core/web_services/http_db_manager_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,43 +61,31 @@ def require_environment!(parsed_options)
Rails.application.require_environment!
end

# def init_servlets(http_server)
# servlet_path = File.dirname(__FILE__) + '/servlet/*'
# Dir.glob(servlet_path).collect{|file_path|
# servlet_class = File.basename(file_path, '.rb').classify
# require file_path
# servlet_class_constant = servlet_class.constantize
# http_server.mount servlet_class_constant.api_path, servlet_class_constant
# }
# end



end

def print_line(msg)
$console_printer.print_line(msg)
end

def print_line(msg)
$console_printer.print_line(msg)
end
def print_warning(msg)
$console_printer.print_warning(msg)
end

def print_warning(msg)
$console_printer.print_warning(msg)
end
def print_good(msg)
$console_printer.print_good(msg)
end

def print_good(msg)
$console_printer.print_good(msg)
end
def print_error(msg, exception = nil)
unless exception.nil?
msg += "\n Call Stack:"
exception.backtrace.each {|line|
msg += "\n"
msg += "\t #{line}"
}
end

def print_error(msg, exception = nil)
unless exception.nil?
msg += "\n Call Stack:"
exception.backtrace.each {|line|
msg += "\n"
msg += "\t #{line}"
}
$console_printer.print_error(msg)
end

$console_printer.print_error(msg)

end

$console_printer = Rex::Ui::Text::Output::Stdio.new
41 changes: 41 additions & 0 deletions lib/msfenv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,44 @@ def noop_error_formatter.message_for(_spot)
end

MsfAutoload.instance

def _warn_deprecation_message(method)
stack_size = 3
warning_message = "[DEPRECATION] The global method #{method.inspect} is deprecated, please raise a Github issue with this output. Called from: #{caller(1, stack_size).to_a}"
warn(warning_message)
# Additionally write to ~/.msf4/logs/framework.log - as this gets attached to Github issues etc
elog(warning_message)
end

# @deprecated In most scenarios you should delegate to either a framework module object, or Rex::Ui::Text::DispatcherShell etc
def print_line(msg)
_warn_deprecation_message __method__
$stdout.puts(msg)
end

# @deprecated In most scenarios you should delegate to either a framework module object, or Rex::Ui::Text::DispatcherShell etc
def print_warning(msg)
_warn_deprecation_message __method__
$stderr.puts(msg)
end

# @deprecated In most scenarios you should delegate to either a framework module object, or Rex::Ui::Text::DispatcherShell etc
def print_good(msg)
_warn_deprecation_message __method__
$stdout.puts(msg)
end

# @deprecated In most scenarios you should delegate to either a framework module object, or Rex::Ui::Text::DispatcherShell etc
def print_error(msg, exception = nil)
_warn_deprecation_message __method__

unless exception.nil?
msg += "\n Call Stack:"
exception.backtrace.each {|line|
msg += "\n"
msg += "\t #{line}"
}
end

$stderr.puts(msg)
end
14 changes: 14 additions & 0 deletions spec/zeitwerk_compliance_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require 'spec_helper'

# https://github.com/rails/rails/blob/0fec9536ca43e209064e60f48b0def6bfe539fe2/guides/source/classic_to_zeitwerk_howto.md#rspec
RSpec.describe 'ZeitwerkCompliance' do
it 'loads all files without errors' do
expect do
# Ensure we've configured zeitwerk
require 'msfenv'
Zeitwerk::Loader.eager_load_all
end.not_to raise_error
end
end

0 comments on commit acf23e9

Please sign in to comment.