Class: Onceover::Node
- Inherits:
-
Object
- Object
- Onceover::Node
- Defined in:
- lib/onceover/node.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#beaker_node ⇒ Object
Returns the value of attribute beaker_node.
-
#fact_set ⇒ Object
Returns the value of attribute fact_set.
-
#name ⇒ Object
Returns the value of attribute name.
-
#trusted_external_set ⇒ Object
Returns the value of attribute trusted_external_set.
-
#trusted_set ⇒ Object
Returns the value of attribute trusted_set.
Class Method Summary collapse
- .all ⇒ Object
-
.clean_facts(factset) ⇒ Object
This method ensures that all facts are valid and clean anoything that we can’t handle.
- .find(node_name) ⇒ Object
Instance Method Summary collapse
-
#initialize(name) ⇒ Node
constructor
A new instance of Node.
Constructor Details
#initialize(name) ⇒ Node
Returns a new instance of Node.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/onceover/node.rb', line 13 def initialize(name) @name = name @beaker_node = nil # If we can't find the factset it will fail, so just catch that error and ignore it begin facts_file_index = Onceover::Controlrepo.facts_files.index {|facts_file| File.basename(facts_file, '.json') == name } @fact_set = Onceover::Node.clean_facts(Onceover::Controlrepo.facts[facts_file_index]) # First see if we can find a 'trusted' hash at the top level of our factset @trusted_set = Onceover::Controlrepo.trusted_facts[facts_file_index] # If we don't find it, attempt to find a 'trusted.extensions' hash nested in our fact_set @trusted_set = @fact_set.dig('trusted', 'extensions') if @trusted_set.nil? # If we still can't find any, return an empty hash so the following doesn't blow up user written tests: # let(:trusted_facts) { trusted_facts } @trusted_set = {} if @trusted_set.nil? # First see if we can find a 'trusted_external' hash at the top level of our factset @trusted_external_set = Onceover::Controlrepo.trusted_external_facts[facts_file_index] # If we don't find it, attempt to find a 'trusted.external' hash nested in our fact_set @trusted_external_set = @fact_set.dig('trusted', 'external') if @trusted_external_set.nil? # If we still can't find any, return an empty hash so the following doesn't blow up user written tests: # let(:trusted_external_data) { trusted_external_data } @trusted_external_set = {} if @trusted_external_set.nil? rescue TypeError @fact_set = {} @trusted_set = {} @trusted_external_set = {} end @@all << self end |
Instance Attribute Details
#beaker_node ⇒ Object
Returns the value of attribute beaker_node.
8 9 10 |
# File 'lib/onceover/node.rb', line 8 def beaker_node @beaker_node end |
#fact_set ⇒ Object
Returns the value of attribute fact_set.
9 10 11 |
# File 'lib/onceover/node.rb', line 9 def fact_set @fact_set end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/onceover/node.rb', line 7 def name @name end |
#trusted_external_set ⇒ Object
Returns the value of attribute trusted_external_set.
11 12 13 |
# File 'lib/onceover/node.rb', line 11 def trusted_external_set @trusted_external_set end |
#trusted_set ⇒ Object
Returns the value of attribute trusted_set.
10 11 12 |
# File 'lib/onceover/node.rb', line 10 def trusted_set @trusted_set end |
Class Method Details
.all ⇒ Object
62 63 64 |
# File 'lib/onceover/node.rb', line 62 def self.all @@all end |
.clean_facts(factset) ⇒ Object
This method ensures that all facts are valid and clean anoything that we can’t handle
67 68 69 70 |
# File 'lib/onceover/node.rb', line 67 def self.clean_facts(factset) factset.delete('environment') factset end |
.find(node_name) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/onceover/node.rb', line 48 def self.find(node_name) @@all.each do |node| if node_name.is_a?(Onceover::Node) if node = node_name return node end elsif node.name == node_name return node end end logger.warn "Node #{node_name} not found" nil end |