require 'soar_xt' require 'soar_flow' require 'soar_auditing_provider' require 'log4r_auditor' module SoarSc module Providers class Auditing DEFAULT_AUDITING_CONFIGURATION = { 'auditing' => { 'provider' => 'SoarAuditingProvider::AuditingProvider', 'level' => 'debug', 'install_exit_handler' => 'true', 'queue_worker' => { 'queue_size' => 1000, 'initial_back_off_in_seconds' => 1, 'back_off_multiplier' => 2, 'back_off_attempts' => 5 }, 'default_nfrs' => { 'accessibility' => 'local', 'privacy' => 'not encrypted', 'reliability' => 'instance', 'performance' => 'high' }, 'auditors' => { 'log4r' => { 'adaptor' => 'Log4rAuditor::Log4rAuditor', 'file_name' => 'soar_sc.log', 'standard_stream' => 'stdout', 'nfrs' => { 'accessibility' => 'local', 'privacy' => 'not encrypted', 'reliability' => 'instance', 'performance' => 'high' } } } } } unless defined? DEFAULT_AUDITING_CONFIGURATION; DEFAULT_AUDITING_CONFIGURATION.freeze def self.bootstrap(configuration) begin merged_configuration = self.merge_configuration_with_auditing_defaults(configuration) self.validate_auditing_provider_configuration(merged_configuration['auditing']) SoarSc::auditing = SoarSc::Providers.const_get(merged_configuration['auditing']['provider']).new(merged_configuration['auditing']) self.generate_instance_flow_id SoarSc::auditing.service_identifier = SoarSc::environment['IDENTIFIER'] merged_configuration rescue $stderr.puts 'Failure initializing auditing provider' raise end end private def self.generate_instance_flow_id SoarSc::startup_flow_id = SoarFlow::ID::generate_flow_id SoarSc::auditing.instance_flow_identifier = SoarSc::startup_flow_id end def self.merge_configuration_with_auditing_defaults(configuration) Hash.deep_merge(DEFAULT_AUDITING_CONFIGURATION,SoarSc::configuration) end def self.validate_auditing_provider_configuration(configuration) begin SoarSc::Providers.const_get(configuration['provider']) rescue $stderr.puts 'Invalid auditing provider configuration' raise end end end end end