Method: Onceover::VendoredModules#initialize
- Defined in:
- lib/onceover/vendored_modules.rb
#initialize(opts = {}) ⇒ VendoredModules
Returns a new instance of VendoredModules.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/onceover/vendored_modules.rb', line 27 def initialize(opts = {}) @repo = opts[:repo] || Onceover::Controlrepo.new @cachedir = opts[:cachedir] || File.join(@repo.tempdir, 'vendored_modules') @puppet_version = Gem::Version.new(Puppet.version) @puppet_major_version = Gem::Version.new(@puppet_version.segments[0]) @force_update = opts[:force_update] || false @missing_vendored = [] # This only applies to puppet >= 6 so bail early raise 'Auto resolving vendored modules only applies to puppet versions >= 6' unless @puppet_major_version >= Gem::Version.new('6') # Create cachedir unless File.directory?(@cachedir) logger.debug "Creating #{@cachedir}" FileUtils.mkdir_p(@cachedir) end # Location of user provided caches: # control-repo/spec/vendored_modules/<component>-puppet_agent-<agent version>.json @manual_vendored_dir = File.join(@repo.spec_dir, 'vendored_modules') # Get the entire file tree of the puppetlabs/puppet-agent repository # https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#get-a-tree puppet_agent_tree = query_or_cache( "https://api.github.com/repos/OpenVoxProject/openvox-agent/git/trees/#{@puppet_version}", { recursive: true }, component_cache('repo_tree'), ) # Get only the module-puppetlabs-<something>_core.json component files vendored_components = puppet_agent_tree['tree'].select { |file| %r{configs/components/module-puppetlabs-\w+\.json}.match(file['path']) } # Get the contents of each component file # https://docs.github.com/en/rest/git/blobs?apiVersion=2022-11-28#get-a-blob @vendored_references = vendored_components.map do |component| mod_slug = component['path'].match(/.*(puppetlabs-\w+).json$/)[1] mod_name = mod_slug.match(/puppetlabs-(\w+)/)[1] query_or_cache( component['url'], nil, component_cache(mod_name), ) end end |