Module: Rails::Auth::ConfigBuilder

Extended by:
ConfigBuilder
Included in:
ConfigBuilder
Defined in:
lib/rails/auth/config_builder.rb

Overview

Configures Rails::Auth middleware for use in a Rails application

Instance Method Summary collapse

Instance Method Details

#application(config, acl_file: Rails.root.join("config/acl.yml"), matchers: {}) ⇒ Object

Application-level configuration (i.e. config/application.rb)



10
11
12
13
14
15
16
17
# File 'lib/rails/auth/config_builder.rb', line 10

def application(config, acl_file: Rails.root.join("config/acl.yml"), matchers: {})
  config.x.rails_auth.acl = Rails::Auth::ACL.from_yaml(
    File.read(acl_file.to_s),
    matchers: matchers
  )

  config.middleware.use Rails::Auth::ACL::Middleware, acl: config.x.rails_auth.acl
end

#development(config, development_credentials: {}, error_page: :debug) ⇒ Object

Development configuration (i.e. config/environments/development.rb)



20
21
22
23
# File 'lib/rails/auth/config_builder.rb', line 20

def development(config, development_credentials: {}, error_page: :debug)
  error_page_middleware(config, error_page)
  credential_injector_middleware(config, development_credentials) unless development_credentials.empty?
end

#production(config, cert_filters: nil, error_page: Rails.root.join("public/403.html"), monitor: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rails/auth/config_builder.rb', line 31

def production(
  config,
  cert_filters: nil,
  error_page: Rails.root.join("public/403.html"),
  monitor: nil
)
  error_page_middleware(config, error_page)

  if cert_filters
    config.middleware.insert_before Rails::Auth::ACL::Middleware,
                                    Rails::Auth::X509::Middleware,
                                    cert_filters: cert_filters,
                                    logger:       Rails.logger
  end

  return unless monitor

  config.middleware.insert_before Rails::Auth::ACL::Middleware,
                                  Rails::Auth::Monitor::Middleware,
                                  monitor
end

#test(config) ⇒ Object

Test configuration (i.e. config/environments/test.rb)



26
27
28
29
# File 'lib/rails/auth/config_builder.rb', line 26

def test(config)
  # Simulated credentials to be injected with InjectorMiddleware
  credential_injector_middleware(config, config.x.rails_auth.test_credentials ||= {})
end