Sha256: 0a342eea1735767a8828b8ea456087960b9a6e13b8e24c1c3a04738e92385aed

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'elastic-apm'

module ForemanSupervisoryAuthority
  class Engine < ::Rails::Engine
    engine_name 'foreman_supervisory_authority'

    config.autoload_paths += Dir["#{config.root}/app/controllers/concerns"]

    initializer 'foreman_supervisory_authority.register_plugin', before: :finisher_hook do
      Foreman::Plugin.register :foreman_supervisory_authority do
        requires_foreman '>= 3.10'
      end
    end

    config.elastic_apm.disable_instrumentations = %w[json]

    # map user context methods to what we use in Foreman
    config.elastic_apm.current_user_email_method = :mail
    config.elastic_apm.current_user_username_method = :login

    config.elastic_apm.merge!(SETTINGS[:foreman_supervisory_authority]) if SETTINGS[:foreman_supervisory_authority]

    # Include concerns in this config.to_prepare block
    config.to_prepare do
      ::ApplicationController.include ForemanSupervisoryAuthority::SetElasticApmContext
      ::Api::BaseController.include ForemanSupervisoryAuthority::SetElasticApmContext
      ::Api::GraphqlController.include ForemanSupervisoryAuthority::SetElasticApmContext
    rescue StandardError => e
      Rails.logger.warn "ForemanSupervisoryAuthority: skipping engine hook (#{e})"
    end
  end

  def self.with_settings?
    Setting.table_exists?
  rescue StandardError
    false
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_supervisory_authority-0.2.0 lib/foreman_supervisory_authority/engine.rb