Class: EY::GateKeeper::AccessControl
- Inherits:
-
Object
- Object
- EY::GateKeeper::AccessControl
- Defined in:
- lib/ey_gatekeeper/access_control_list.rb
Overview
An individual control, probably within a list. Example: AccessControl.new(‘xdna://foobars’, [‘GET’, ‘PUT’, ‘DELETE’])
Instance Attribute Summary collapse
-
#methods ⇒ Object
readonly
Returns the value of attribute methods.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#&(other_control) ⇒ Object
Intersect 2 acccess controls.
- #allow?(method) ⇒ Boolean
-
#initialize(path, *methods) ⇒ AccessControl
constructor
A new instance of AccessControl.
- #matches?(test_path_uri) ⇒ Boolean
- #parameters_satisfied?(test_path_uri) ⇒ Boolean
-
#path_without_parameters ⇒ Object
can’t use URI for these right now since it barfs on _ in the hostname portion.
- #query ⇒ Object
- #required_parameters ⇒ Object
- #suitable_for?(test_path) ⇒ Boolean
Constructor Details
#initialize(path, *methods) ⇒ AccessControl
Returns a new instance of AccessControl.
12 13 14 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 12 def initialize(path, *methods) @path, @methods = path, methods.flatten.map {|m| m.to_s.upcase } end |
Instance Attribute Details
#methods ⇒ Object (readonly)
Returns the value of attribute methods.
10 11 12 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 10 def methods @methods end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 10 def path @path end |
Instance Method Details
#&(other_control) ⇒ Object
Intersect 2 acccess controls
51 52 53 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 51 def &(other_control) AccessControl.new(path, other_control.methods & methods) end |
#allow?(method) ⇒ Boolean
16 17 18 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 16 def allow?(method) methods.include?(method.to_s.upcase) end |
#matches?(test_path_uri) ⇒ Boolean
27 28 29 30 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 27 def matches?(test_path_uri) path_without_parameters == 'xdna://' || "xdna:/#{test_path_uri.path}".match(%r{^#{path_without_parameters}(\/|$)}) end |
#parameters_satisfied?(test_path_uri) ⇒ Boolean
32 33 34 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 32 def parameters_satisfied?(test_path_uri) (required_parameters - CGI.parse(test_path_uri.query || '').keys).empty? end |
#path_without_parameters ⇒ Object
can’t use URI for these right now since it barfs on _ in the hostname portion
42 43 44 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 42 def path_without_parameters path.split('?').first end |
#query ⇒ Object
46 47 48 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 46 def query path.split('?', 2)[1] end |
#required_parameters ⇒ Object
36 37 38 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 36 def required_parameters @required_parameters ||= CGI.parse(query || '').keys end |
#suitable_for?(test_path) ⇒ Boolean
20 21 22 23 24 25 |
# File 'lib/ey_gatekeeper/access_control_list.rb', line 20 def suitable_for?(test_path) test_path = URI.escape(URI.unescape(test_path)) test_path_uri = URI.parse(test_path) matches?(test_path_uri) && parameters_satisfied?(test_path_uri) end |