Class: Pechkin::Auth::Middleware
- Inherits:
-
Object
- Object
- Pechkin::Auth::Middleware
- Defined in:
- lib/pechkin/auth.rb
Overview
Auth middleware to check if provided auth can be found in .htpasswd file
Instance Attribute Summary collapse
-
#htpasswd ⇒ Object
readonly
Returns the value of attribute htpasswd.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, auth_file:) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, auth_file:) ⇒ Middleware
Returns a new instance of Middleware.
25 26 27 28 |
# File 'lib/pechkin/auth.rb', line 25 def initialize(app, auth_file:) @htpasswd = HTAuth::PasswdFile.open(auth_file) if File.exist?(auth_file) @app = app end |
Instance Attribute Details
#htpasswd ⇒ Object (readonly)
Returns the value of attribute htpasswd.
23 24 25 |
# File 'lib/pechkin/auth.rb', line 23 def htpasswd @htpasswd end |
Instance Method Details
#call(env) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/pechkin/auth.rb', line 30 def call(env) (env) @app.call(env) rescue AuthError => e body = { status: 'error', reason: e. }.to_json ['401', { 'Content-Type' => 'application/json' }, [body]] rescue StandardError => e body = { status: 'error', reason: e. }.to_json ['503', { 'Content-Type' => 'application/json' }, [body]] end |