Method: CemDataProcessor::Parser::ResourceDataParser#parse
- Defined in:
- lib/cem_data_processor/parser.rb
#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/cem_data_processor/parser.rb', line 100 def parse @hiera_data.each do |name, data| resource = CemDataProcessor::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 |