Class: Bowtie::Middleware::PolicyCheck
- Inherits:
-
Object
- Object
- Bowtie::Middleware::PolicyCheck
- Defined in:
- lib/bowtie/middleware/policy_check.rb
Defined Under Namespace
Modules: Loader Classes: Policy
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ PolicyCheck
constructor
A new instance of PolicyCheck.
Constructor Details
#initialize(app) ⇒ PolicyCheck
Returns a new instance of PolicyCheck.
25 26 27 28 |
# File 'lib/bowtie/middleware/policy_check.rb', line 25 def initialize(app) @app = app end |
Class Method Details
.watch! ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/bowtie/middleware/policy_check.rb', line 8 def self.watch! source = Jekyll.configuration['source'] # Initialize our policies with current source Policy.load_policies!(source) # Watch for policy file changes and reload policies on change Listen.to(source, only: /\.bowtie\.yml/){ begin Policy.load_policies!(source) rescue => e puts e.inspect puts e.backtrace.join("\n") end }.start end |
Instance Method Details
#call(env) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bowtie/middleware/policy_check.rb', line 30 def call(env) rack_request = Rack::Request.new(env) status, headers, response = @app.call(env) if Policy.permits?(rack_request) [status, headers, response] else [403, {}, ["Request not permitted by defined policies"]] end end |