Module: BBK::AMQP::Spec::RabbitHelper
- Defined in:
- lib/bbk/amqp/spec/rabbit_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(_mod) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bbk/amqp/spec/rabbit_helper.rb', line 30 def self.included(_mod) cert_path, key_path, cacert_path = prepare_certs(File.join($root, 'fixtures')) self.mq_defaults = { host: ENV['MQ_HOST'] || 'mq', port: ENV['MQ_PORT'] || 5671, tls: true, tls_cert: cert_path, tls_key: key_path, tls_ca_certificates: [cacert_path], verify_peer: false, verify_ssl: false, verify: false, auth_mechanism: 'EXTERNAL', automatically_recover: false, automatic_recovery: false, recover_from_connection_close: false, continuation_timeout: 10_000, heartbeat: 10 } end |
.prepare_certs(fixtures_path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bbk/amqp/spec/rabbit_helper.rb', line 12 def self.prepare_certs(fixtures_path) FileUtils.mkdir_p File.join(fixtures_path, 'keys') cert_path = File.join(fixtures_path, 'keys', 'cert.pem') key_path = File.join(fixtures_path, 'keys', 'key.pem') cacert_path = File.join(fixtures_path, 'keys', 'cacert.pem') { 'TEST_CLIENT_CERT' => cert_path, 'TEST_CLIENT_KEY' => key_path, 'CA_CERT' => cacert_path }.each_pair do |env, file| File.write(file, ENV[env]) if ENV[env].present? end [cert_path, key_path, cacert_path] end |
Instance Method Details
#commonname ⇒ Object
52 53 54 |
# File 'lib/bbk/amqp/spec/rabbit_helper.rb', line 52 def commonname BBK::AMQP::Utils.commonname(mq_defaults[:tls_cert]) end |
#mq_connection(options = {}) ⇒ Object
56 57 58 |
# File 'lib/bbk/amqp/spec/rabbit_helper.rb', line 56 def mq_connection( = {}) Bunny.new(mq_defaults.merge()) end |