Class: Contrast::Agent::Patching::Policy::PolicyNode Abstract
- Includes:
- Components::Scope::InstanceMethods
- Defined in:
- lib/contrast/agent/patching/policy/policy_node.rb
Overview
This class functions to translate our policy.json into an actionable Ruby object, allowing for dynamic patching over hardcoded patching.
Direct Known Subclasses
Assess::Policy::PolicyNode, Deadzone::Policy::DeadzoneNode, TriggerNode
Constant Summary collapse
- JSON_METHOD_VISIBILITY =
'method_visibility'
- JSON_PROPERTIES =
'properties'
- JSON_METHOD_NAME =
'method_name'
- JSON_METHOD_SCOPE =
'scope'
- JSON_CLASS_NAME =
The keys used to read from policy.json to create the individual policy nodes. These are common across node types
'class_name'
- JSON_INSTANCE_METHOD =
'instance_method'
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Name of the class in which the method is being invoked.
-
#instance_method ⇒ Object
Check for instance method.
-
#method_name ⇒ Object
The symbol representation of the invoked method.
-
#method_scope ⇒ Object
readonly
Scope of the method parsed from our JSON policy.
-
#method_visibility ⇒ Object
Visibility of the invoked method [Private, Public, Protected].
-
#properties ⇒ Object
readonly
Properties parsed from our JSON policy.
Instance Method Summary collapse
- #feature ⇒ Object
- #id ⇒ Object
-
#initialize(policy_hash = {}) ⇒ PolicyNode
constructor
A new instance of PolicyNode.
-
#instance_method? ⇒ Boolean
just turns this into a ruby-ism.
- #node_class ⇒ Object
-
#validate ⇒ Object
Don’t let nodes be created that will be missing things we need later on.
Methods included from Components::Scope::InstanceMethods
#contrast_enter_method_scopes!, #contrast_exit_method_scopes!, #with_app_scope, #with_contrast_scope, #with_deserialization_scope, #with_split_scope
Constructor Details
#initialize(policy_hash = {}) ⇒ PolicyNode
Returns a new instance of PolicyNode.
25 26 27 28 29 30 31 32 33 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 25 def initialize policy_hash = {} @class_name = policy_hash[JSON_CLASS_NAME] @instance_method = policy_hash[JSON_INSTANCE_METHOD] @method_name = policy_hash[JSON_METHOD_NAME] @method_scope = policy_hash[JSON_METHOD_SCOPE] @method_visibility = policy_hash[JSON_METHOD_VISIBILITY] @properties = policy_hash[JSON_PROPERTIES] symbolize end |
Instance Attribute Details
#class_name ⇒ Object
Name of the class in which the method is being invoked.
36 37 38 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 36 def class_name @class_name end |
#instance_method ⇒ Object
Check for instance method.
40 41 42 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 40 def instance_method @instance_method end |
#method_name ⇒ Object
The symbol representation of the invoked method.
42 43 44 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 42 def method_name @method_name end |
#method_scope ⇒ Object (readonly)
Scope of the method parsed from our JSON policy.
48 49 50 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 48 def method_scope @method_scope end |
#method_visibility ⇒ Object
Visibility of the invoked method [Private, Public, Protected]
44 45 46 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 44 def method_visibility @method_visibility end |
#properties ⇒ Object (readonly)
Properties parsed from our JSON policy.
46 47 48 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 46 def properties @properties end |
Instance Method Details
#feature ⇒ Object
58 59 60 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 58 def feature raise(NoMethodError, 'specify the name of the feature for which this node patches') end |
#id ⇒ Object
62 63 64 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 62 def id @_id ||= "#{ feature }:#{ node_class }:#{ class_name }#{ instance_method? ? '#' : '.' }#{ method_name }" end |
#instance_method? ⇒ Boolean
just turns this into a ruby-ism
94 95 96 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 94 def instance_method? instance_method end |
#node_class ⇒ Object
52 53 54 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 52 def node_class raise(NoMethodError, 'specify the type of the feature for which this node patches') end |
#validate ⇒ Object
Don’t let nodes be created that will be missing things we need later on. Really, if they don’t have these things, they couldn’t have done their jobs anyway.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/contrast/agent/patching/policy/policy_node.rb', line 71 def validate unless class_name raise(ArgumentError, "#{ node_class } #{ id } did not have a proper class name. Unable to create.") end unless method_name raise(ArgumentError, "#{ node_class } #{ id } did not have a proper method name. Unable to create.") end unless method_name.is_a?(Symbol) raise(ArgumentError, "#{ node_class } #{ id } has a non symbol @method_name value. Unable to create.") end unless method_visibility.is_a?(Symbol) raise(ArgumentError, "#{ node_class } #{ id } has a non symbol @method_visibility value. Unable to create.") end unless method_scope.nil? || Contrast::Agent::Scope.valid_scope?(method_scope) raise(ArgumentError, "#{ node_class } #{ id } requires an undefined scope. Unable to create.") end nil end |