Permalink
Browse files

kdbkey: handle comments in a uniform way

handle comments both for 'hosts' and 'ini' style comment metadata.
  • Loading branch information...
BernhardDenner committed Apr 28, 2017
1 parent f3d2c04 commit e56f1557d1057fe365ce4ce555b31a088998408b
Showing with 14 additions and 4 deletions.
  1. +2 −0 lib/puppet/provider/kdbkey/kdb.rb
  2. +10 −3 lib/puppet/provider/kdbkey/ruby.rb
  3. +2 −1 spec/unit/provider/key_ruby_helper.rb
@@ -128,6 +128,8 @@ def read_metadata_values_from_key(key_to_read_from)
next
end
next if metadata_reached == false
# end of metadata reached
break if line.empty?
key_name, key_value = line.split(" = ")
key_name.strip!
@@ -282,6 +282,7 @@ def comments
# update comments
#
def comments=(value)
default_comment_start = '#'
# why do we have to init this inst var again???
@comments_key_name ||= "comments"
# split specified comment into lines
@@ -290,10 +291,16 @@ def comments=(value)
comment_lines.each_with_index do |line, index|
puts "comments keyname: #{@comments_key_name}" if @verbose
# currently hosts plugin treats #0 comment as inline comment
#@resource_key.set_meta array_key_name(@comments_key_name, index + 1), "##{line}"
@resource_key.set_meta array_key_name(@comments_key_name, index), "##{line}"
if @resource_key.has_meta? "#{array_key_name @comments_key_name, index}/start"
comment_start = ""
else
comment_start = default_comment_start
end
@resource_key.set_meta array_key_name(@comments_key_name, index), "#{comment_start}#{line}"
if index == 0
@resource_key.set_meta "#{array_key_name @comments_key_name, index}/space", "1"
end
end
#@resource_key.set_meta "#{@comments_key_name}/#0", ''
# iterate over all meta keys and remove all comment keys which
# represent a comment line, which does not exist any more
@@ -114,7 +114,8 @@ def key_get_comment(keyname)
key = @ks.lookup keyname
unless key.nil?
key.meta.find_all do |e|
e.name.start_with? COMMENT+"/#"
#e.name.start_with? COMMENT+"/#"
e.name =~ /#{COMMENT}+\/#\d+$/
end.each do |c|
comment = [] if comment.nil?
if c.value.start_with? "#"

0 comments on commit e56f155

Please sign in to comment.