Class: AbideDataProcessor::Parser::ResourceDataParser
- Inherits:
-
Object
- Object
- AbideDataProcessor::Parser::ResourceDataParser
- Includes:
- Validation
- Defined in:
- lib/abide-data-processor/parser.rb
Overview
Parser class for resource Hiera data. rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#control_maps ⇒ Object
readonly
Returns the value of attribute control_maps.
-
#hiera_data ⇒ Object
readonly
Returns the value of attribute hiera_data.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
-
#initialize(hiera_data, control_maps, control_configs: {}, ignore: [], only: []) ⇒ ResourceDataParser
constructor
A new instance of ResourceDataParser.
-
#parse ⇒ Array
Parse the Hiera data into a Hash used by Puppet to create the resources.
Methods included from Validation
#array_of_hashes?, #not_nil_or_empty?, #validate_control_maps, #validate_hiera_data
Constructor Details
#initialize(hiera_data, control_maps, control_configs: {}, ignore: [], only: []) ⇒ ResourceDataParser
Returns a new instance of ResourceDataParser.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/abide-data-processor/parser.rb', line 78 def initialize(hiera_data, control_maps, control_configs: {}, ignore: [], only: []) @hiera_data = validate_hiera_data(hiera_data) @control_maps = validate_control_maps(control_maps) @control_configs = control_configs @ignore = ignore @only = only @resources = RGL::DirectedAdjacencyGraph.new @controls = Set.new @filtered = Set.new @dependent = {} end |
Instance Attribute Details
#control_maps ⇒ Object (readonly)
Returns the value of attribute control_maps.
76 77 78 |
# File 'lib/abide-data-processor/parser.rb', line 76 def control_maps @control_maps end |
#hiera_data ⇒ Object (readonly)
Returns the value of attribute hiera_data.
76 77 78 |
# File 'lib/abide-data-processor/parser.rb', line 76 def hiera_data @hiera_data end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
76 77 78 |
# File 'lib/abide-data-processor/parser.rb', line 76 def resources @resources end |
Instance Method Details
#parse ⇒ Array
Parse the Hiera data into a Hash used by Puppet to create the resources. The way this works is by first creating a DAG and adding all resources to the graph as vertices, with an edge for each resource pointing from a dummy node, :root, to the resource. We then add edges to the graph based on the ‘before_me` and `after_me` lists of each resource and remove the :root-connected edges for each resource that has a `before_me` list, and remove the :root-connected edges for each resource in a `after_me` list. Finally, we sort the graph into an Array populated with a single Hash of ordered resources and return that Hash. rubocop:disable Metrics/MethodLength
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/abide-data-processor/parser.rb', line 100 def parse @hiera_data.each do |name, data| resource = AbideDataProcessor::Parser.new_resource(name, data, @control_maps) add_control_names(resource) add_dependent_mapping(resource) # Map any controls this resource depends on @resources.add_vertex(resource) # Add all the resources to the graph @resources.add_edge(:root, resource) # Establish the root -> resource edges add_edge_ordering(resource) # Add resource ordering edges end # If the resource should be filtered (i.e. only or ignore), remove it from the graph. filter_resources! # Verify that all dependent resources are in the graph, remove them if not. remove_unsatisfied_dependents! # Sort the graph and return the array of ordered resource hashes sort_resources.map do |r| r.add_control_configs(@control_configs) resource_data(r) end end |