require 'legion/settings' module Legion module Transport module Settings # Legion::Settings.merge_settings('transport', default) if Legion::Settings.method_defined? :merge_settings def self.connection { read_timeout: 1, heartbeat: 1, automatically_recover: true, continuation_timeout: 4000, network_recovery_interval: 1, connection_timeout: 1, user: 'guest', password: 'guest', host: '127.0.0.1', port: '5672', vhost: '/', recovery_attempts: 0, logger_level: 'info', connected: false }.merge(grab_vault_creds) end def self.grab_vault_creds return {} unless Legion::Settings[:crypt][:vault][:connected] lease = Legion::Crypt.read('rabbitmq/creds/legion', type: nil) Legion::Logging.debug 'successfully grabbed amqp username from Vault' { user: lease[:username], password: lease[:password] } rescue StandardError {} end def self.default { type: 'rabbitmq', connected: false, logger_level: 'info', messages: { encrypt: false, ttl: nil, priority: 0 }, exchanges: { type: 'topic', arguments: {}, auto_delete: false, durable: true, internal: false }, queues: { manual_ack: true, durable: true, exclusive: false, block: false, auto_delete: false, arguments: { 'x-max-priority': 255, 'x-overflow': 'reject-publish' } }, prefetch: 2, connection: connection } end end end end begin Legion::Settings.merge_settings('transport', Legion::Transport::Settings.default) if Legion.const_defined?('Settings') rescue StandardError => e Legion::Logging.fatal(e.message) if Legion::Logging.method_defined?(:fatal) end