lib/mkit.rb in mkit-0.5.0 vs lib/mkit.rb in mkit-0.6.0

- old
+ new

@@ -27,10 +27,11 @@ require 'mkit/sagas/saga_manager' require 'mkit/docker_listener' require 'mkit/app/helpers/haproxy' require 'active_record/tasks/database_tasks' require 'mkit/utils' +require 'mkit/ssl/easy_ssl' MKItLogger = Console.logger module MKIt class Error < StandardError; end @@ -38,19 +39,28 @@ System = Dry::Container.new def self.configure(options:) @root = MKIt::Utils.root + @options = options MKItLogger.debug! # # config dir @config_dir = if ENV['RACK_ENV'] != 'development' - options[:config_dir].nil? ? '/etc/mkit' : options[:config_dir] + @options[:config_dir].nil? ? '/etc/mkit' : @options[:config_dir] else - options[:config_dir].nil? ? "#{@root}/config" : options[:config_dir] + @options[:config_dir].nil? ? "#{@root}/config" : @options[:config_dir] end MKIt::Utils.set_config_dir(@config_dir) + # defaults + @bind = options[:bind] ||= 'localhost' + @port = options[:port] ||= 4567 + @ssl = options[:ssl].nil? ? true : options[:ssl] && true + @verify_peer = options[:verify_peer].nil? ? false : options[:verify_peer] && true + @cert_chain_file = options[:cert_chain_file] ||= "#{@config_dir}/#{MKIt::Utils::MKIT_CRT}" + @private_key_file = options[:private_key_file] ||= "#{@config_dir}/#{MKIt::Utils::MKIT_KEY}" + # create dirs if ENV['RACK_ENV'] != 'development' || !options[:config_dir].nil? check_config_files = false unless File.exist?(@config_dir) FileUtils.mkdir_p(@config_dir) @@ -63,13 +73,15 @@ if check_config_files MKItLogger.info "Configuration files copied to #{@config_dir}. Please check it and restart." exit end end - # + # load configuration MKIt::Initializers.load_my_configuration + # cert + MKIt::EasySSL.create_self_certificate(@config_dir) # # run config based tasks FileUtils.mkdir_p(MKIt::Config.mkit.haproxy.config_dir) # ...haproxy defaults file unless File.exist?("#{MKIt::Config.mkit.haproxy.config_dir}/0000_defaults.cfg") @@ -88,9 +100,23 @@ DatabaseTasks.database_configuration = MKIt::Utils.load_db_config DatabaseTasks.env = MKIt::Config.mkit.database.env DatabaseTasks.migrations_paths = ["#{@root}/db/migrate"] DatabaseTasks.db_dir = 'db' DatabaseTasks.root = @root + end + + def self.options(server) + if @ssl + ssl_options = { + private_key_file: @private_key_file, + cert_chain_file: @cert_chain_file, + verify_peer: @verify_peer + } + server.ssl = true + server.ssl_options = ssl_options + end + server.backend.port = @port + server.backend.host = @bind end def self.establish_db_connection ActiveRecord::Base.establish_connection(DatabaseTasks.database_configuration[DatabaseTasks.env]) ActiveRecord::Base.connection.migration_context.migrations_paths.clear