-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* This adds experimental support for the puppetfile resolver. Since the resolver is better, faster, stronger it might be useful to use this library in the future. A resolve task task has been added but it is not clear what that yet provides.
- Loading branch information
1 parent
4ba308b
commit ca90029
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'puppetfile-resolver' | ||
require 'puppetfile-resolver/puppetfile/parser/r10k_eval' | ||
|
||
module Ra10ke | ||
module Resolver | ||
|
||
def define_task_resolver(*args) | ||
desc 'Run the puppetfile Resolver' | ||
task :resolver do | ||
resolver = Ra10ke::Resolver::Instance.new(get_puppetfile.puppetfile_path) | ||
result = resolver.resolve | ||
# Output resolution validation errors | ||
result.validation_errors.each { |err| puts "Resolution Validation Error: #{err}\n"} | ||
end | ||
end | ||
|
||
class Instance | ||
attr_reader :puppetfile | ||
|
||
def initialize(puppetfile_path = File.expand_path(Dir.pwd)) | ||
|
||
# Parse the Puppetfile into an object model | ||
content = File.open(puppetfile_path, 'rb') { |f| f.read } | ||
|
||
@puppetfile = ::PuppetfileResolver::Puppetfile::Parser::R10KEval.parse(content) | ||
|
||
# Make sure the Puppetfile is valid | ||
unless puppetfile.valid? | ||
puts 'Puppetfile is not valid' | ||
puppetfile.validation_errors.each { |err| puts err } | ||
exit 1 | ||
end | ||
end | ||
|
||
def resolve | ||
# Create the resolver | ||
# - Use the document we just parsed (puppetfile) | ||
# - Don't restrict by Puppet version (nil) | ||
resolver = ::PuppetfileResolver::Resolver.new(puppetfile, nil) | ||
|
||
# Configure the resolver | ||
cache = nil # Use the default inmemory cache | ||
ui = nil # Don't output any information | ||
module_paths = [] # List of paths to search for modules on the local filesystem | ||
allow_missing_modules = true # Allow missing dependencies to be resolved | ||
opts = { cache: cache, ui: ui, module_paths: module_paths, allow_missing_modules: allow_missing_modules } | ||
|
||
# Resolve | ||
result = resolver.resolve(opts) | ||
|
||
|
||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'ra10ke/resolver' | ||
RSpec::Mocks.configuration.allow_message_expectations_on_nil = true | ||
|
||
RSpec.describe 'Ra10ke::Resolver::Instance' do | ||
include Ra10ke::Resolver | ||
let(:instance) do | ||
Ra10ke::Resolver::Instance.new(puppetfile) | ||
end | ||
|
||
let(:puppetfile) do | ||
File.join(fixtures_dir, 'Puppetfile') | ||
end | ||
|
||
it 'resolves the puppetfile' do | ||
expect(instance.resolve).to be nil | ||
end | ||
end |