Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 6f26724

Browse files
committed
(maint) Add flag to ignore :latest validation errors
Previously the resolution validator would raise an error if the PuppetFile document specified a version of :latest, as typically this is bad idea. However there are cases when this is required. This commit adds a flag so that the validator does NOT raise an error.
1 parent 8aca2a9 commit 6f26724

6 files changed

Lines changed: 26 additions & 0 deletions

File tree

docs/parsers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ The available settings are:
5757
| --------------------| ----------- |
5858
| `Dependency/Puppet` | Instructs the resolver to ignore any Puppet version in its dependency traversal for the specified modules. Useful for modules with outdated metadata.json information |
5959
| `Dependency/All` | Instructs the resolver to ignore any, and all, dependencies in its dependency traversal of the specified module. Useful for modules with outdated metadata.json information. |
60+
| `Validation/LatestVersion` | Instructs the resolution validator to ignore modules that have a version of :latest |

lib/puppetfile-resolver/puppetfile.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ module Puppetfile
66
#
77
# DISABLE_PUPPET_DEPENDENCY_FLAG - Instructs the resolver to not consider Puppet version in its dependency traversal. Useful for modules with outdated metadata.json information.
88
# DISABLE_ALL_DEPENDENCIES_FLAG - Instructs the resolver to ignore any dependencies in its dependency traversal. Useful for modules with outdated metadata.json information.
9+
# DISABLE_LATEST_VALIDATION_FLAG - Instructs the resolution validator to ignore modules that have a version of :latest
910
#
1011
DISABLE_PUPPET_DEPENDENCY_FLAG = :disable_puppet_dependency
1112
DISABLE_ALL_DEPENDENCIES_FLAG = :disable_all_dependencies
13+
DISABLE_LATEST_VALIDATION_FLAG = :disable_latest_validation
1214
end
1315
end
1416

lib/puppetfile-resolver/puppetfile/document.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def resolution_validation_errors(resolution_result)
7575
next unless mod.version == :latest
7676
resolved_module = resolution_result.specifications[mod.name]
7777
next if resolved_module.nil? || resolved_module.is_a?(PuppetfileResolver::Models::MissingModuleSpecification)
78+
next if mod.resolver_flags.include?(PuppetfileResolver::Puppetfile::DISABLE_LATEST_VALIDATION_FLAG)
7879
@validation_errors << DocumentLatestVersionError.new(
7980
"Latest version of #{mod.name} is #{resolved_module.version}",
8081
mod,

lib/puppetfile-resolver/puppetfile/parser/r10k_eval.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ def self.flags_from_line(line)
105105
PuppetfileResolver::Puppetfile::DISABLE_PUPPET_DEPENDENCY_FLAG
106106
when 'dependency/all'
107107
PuppetfileResolver::Puppetfile::DISABLE_ALL_DEPENDENCIES_FLAG
108+
when 'validation/latestversion'
109+
PuppetfileResolver::Puppetfile::DISABLE_LATEST_VALIDATION_FLAG
108110
else # rubocop:disable Style/EmptyElse We will be adding something here later
109111
# TODO: Should we log a warning/info here?
110112
nil

spec/unit/puppetfile-resolver/puppetfile/document_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126
@document_modules = document_fixtures.map do |doc_mod|
127127
mod = doc_mod[:class].new(doc_mod[:name])
128128
mod.version = doc_mod[:version]
129+
mod.resolver_flags = doc_mod[:flags] unless doc_mod[:flags].nil?
129130
subject.add_module(mod)
130131
mod
131132
end
@@ -207,6 +208,19 @@
207208
puppet_module: @document_modules[0]
208209
)
209210
end
211+
212+
context 'and using the DISABLE_LATEST_VALIDATION_FLAG flag' do
213+
let(:document_fixtures) do
214+
[
215+
{ class: PuppetfileResolver::Puppetfile::ForgeModule, name: 'foo', version: :latest, flags: [PuppetfileResolver::Puppetfile::DISABLE_LATEST_VALIDATION_FLAG] }
216+
]
217+
end
218+
219+
it 'should not return a DocumentLatestVersionError' do
220+
errors = subject.resolution_validation_errors(resolution_result)
221+
expect(errors.count).to eq(0)
222+
end
223+
end
210224
end
211225

212226
context 'Given a document with a missing module' do

spec/unit/puppetfile-resolver/puppetfile/parser/r10k_eval_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ def get_module(document, title)
351351
352352
mod 'puppetlabs-magic1', :latest # resolver:disable Dependency/Puppet
353353
mod 'puppetlabs-magic2', :latest # resolver:disable Dependency/all
354+
mod 'puppetlabs-magic3', :latest # resolver:disable Validation/LatestVersion
354355
EOT
355356
end
356357
let(:puppetfile) { subject.parse(puppetfile_content) }
@@ -364,6 +365,11 @@ def get_module(document, title)
364365
mod = get_module(puppetfile, 'puppetlabs-magic2')
365366
expect(mod.resolver_flags).to eq([PuppetfileResolver::Puppetfile::DISABLE_ALL_DEPENDENCIES_FLAG])
366367
end
368+
369+
it 'should add the DISABLE_LATEST_VALIDATION_FLAG flag for Validation/LatestVersion' do
370+
mod = get_module(puppetfile, 'puppetlabs-magic3')
371+
expect(mod.resolver_flags).to eq([PuppetfileResolver::Puppetfile::DISABLE_LATEST_VALIDATION_FLAG])
372+
end
367373
end
368374
end
369375

0 commit comments

Comments
 (0)