voxpupuli / onceover

Your gateway drug to automated infrastructure testing with Puppet
141 stars 45 forks source link

Need a better way to deal with eyaml in module data #249

Open spidersddd opened 4 years ago

spidersddd commented 4 years ago

Some users of Onceover need seperate site profile module/repo that has eyaml configuration and content in the module data.

We need a way to work around installing the hiera-eyaml gem and all providing the key to Onceover.

Bellow is not a proposed solution but it does work. It removes eyaml configuration information from all modules hiera.yaml files prior to running onceover. This is in the templates/test_spec.rb


# This will remove component module eyaml entries in module hiera.yaml files.
# This is not enabled by default but if you have eyaml in component modules
#  you will need to uncomment the 'clean_hiera_eyaml' on line 83
def clean_hiera_eyaml
  require 'tempfile'
  # look at all hiera below .onceover/etc directory
  Dir.glob('<%= Dir.pwd + '/.onceover' %>/**/hiera.yaml').each do |filename|

    Tempfile.open(".#{File.basename(filename)}", File.dirname(filename)) do |tempfile|
      text = File.read(filename)
      # Look for this pattern
      #     lookup_key: eyaml_lookup_key
      #       options:
      #           pkcs7_private_key: *
      #           pkcs7_public_key: *
      tempfile.puts text.gsub(%r{\s*lookup_key:\s*eyaml_lookup_key\s*\n\s*options:\s*\n\s*pkcs7\w+:.*\n\s*pkcs7\w+:.*}, "")

      tempfile.close
      FileUtils.mv tempfile.path, filename
    end
  end
end

We need a better way to solve for this challange.