-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add configuration to allow skipping missing template files/keys #48
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,6 +19,10 @@ def initialize(name, config) | |||||
end | ||||||
|
||||||
def render(save: true) | ||||||
if contents.empty? && @config[:skip_missing_template] | ||||||
return | ||||||
end | ||||||
|
||||||
# Attempt to render | ||||||
renderer = ERB.new(contents, nil, '-') | ||||||
result = renderer.result(binding) | ||||||
|
@@ -76,20 +80,34 @@ def ordered_locations | |||||
|
||||||
# Concatenate all the source templates together, in the order provided | ||||||
def contents | ||||||
ordered_locations.map do |location| | ||||||
@_contents ||= ordered_locations.map do |location| | ||||||
location.to_s.start_with?('consul') ? consul_contents(location) : disk_contents(location) | ||||||
end.join | ||||||
end.compact.join | ||||||
end | ||||||
|
||||||
def consul_contents(location) | ||||||
[@config[location]].compact.flatten.map do |key| | ||||||
Diplomat::Kv.get(key, options: {}, not_found: :return, found: :return).force_encoding 'utf-8' | ||||||
Diplomat::Kv.get(key, {}, :reject, :return).force_encoding 'utf-8' | ||||||
rescue Diplomat::KeyNotFound | ||||||
if @config[:skip_missing_template] | ||||||
STDERR.puts "Consult: Skipping missing template: #{name}" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, currently the thing being skipped is the template. Maybe it'd be better to include the file path or consul key causing the skip, so you know what's missing? |
||||||
next | ||||||
end | ||||||
|
||||||
raise | ||||||
end.join | ||||||
end | ||||||
|
||||||
def disk_contents(location) | ||||||
[public_send(location)].compact.flatten.map do |file_path| | ||||||
File.read file_path, encoding: 'utf-8' | ||||||
rescue Errno::ENOENT | ||||||
if @config[:skip_missing_template] | ||||||
STDERR.puts "Consult: Skipping missing template: #{name}" | ||||||
next | ||||||
end | ||||||
|
||||||
raise | ||||||
end.join | ||||||
end | ||||||
end | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume you had to remove the
not_found
andfound
args here in order to implement the rescue logic?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in this commit message: 28220a8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the clarification