forked from puppetlabs/puppet
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request puppetlabs#1964 from zaphod42/hlindberg-issues/iss…
…ue-19955-data-binding-rescue-and-log (#19955) Give better error msg when Hiera databindings fail.
- Loading branch information
Showing
9 changed files
with
166 additions
and
204 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 |
---|---|---|
@@ -1,6 +1,50 @@ | ||
require 'puppet/indirector/hiera' | ||
require 'puppet/indirector/code' | ||
require 'hiera/scope' | ||
|
||
class Puppet::DataBinding::Hiera < Puppet::Indirector::Hiera | ||
class Puppet::DataBinding::Hiera < Puppet::Indirector::Code | ||
desc "Retrieve data using Hiera." | ||
|
||
def initialize(*args) | ||
if ! Puppet.features.hiera? | ||
raise "Hiera terminus not supported without hiera library" | ||
end | ||
super | ||
end | ||
|
||
if defined?(::Psych::SyntaxError) | ||
DataBindingExceptions = [::StandardError, ::Psych::SyntaxError] | ||
else | ||
DataBindingExceptions = [::StandardError] | ||
end | ||
|
||
def find(request) | ||
hiera.lookup(request.key, nil, Hiera::Scope.new(request.options[:variables]), nil, nil) | ||
rescue *DataBindingExceptions => detail | ||
raise Puppet::DataBinding::LookupError.new(detail.message, detail) | ||
end | ||
|
||
private | ||
|
||
def self.hiera_config | ||
hiera_config = Puppet.settings[:hiera_config] | ||
config = {} | ||
|
||
if File.exist?(hiera_config) | ||
config = Hiera::Config.load(hiera_config) | ||
else | ||
Puppet.warning "Config file #{hiera_config} not found, using Hiera defaults" | ||
end | ||
|
||
config[:logger] = 'puppet' | ||
config | ||
end | ||
|
||
def self.hiera | ||
@hiera ||= Hiera.new(:config => hiera_config) | ||
end | ||
|
||
def hiera | ||
self.class.hiera | ||
end | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
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
File renamed without changes.
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 @@ | ||
{ invalid: |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.