Skip to content

Commit

Permalink
Merge branch 'enhancement/use-a-tag-to-disable-parsing-for-a-single-a…
Browse files Browse the repository at this point in the history
…ttribute-value-254'

closes #254
  • Loading branch information
bobapple committed Mar 13, 2017
2 parents 9679267 + 82d699c commit 9cedd81
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,10 @@ To generate a valid Icinga 2 configuration all object attributes are parsed. Thi
decision for each attribute, whether part of the string is to be quoted or not, and how an array or dictionary is to be
formatted.

Parsing of a single attribute can be disabled by tagging it with -: at the front of the string.
```
attr => '-:"unparsed string with quotes"'
```
An array, a hash or a string can be assigned to an object attribute. True and false are also valid values.

Hashes and arrays are created recursively, and all parts – such as single items of an array, keys and its values
Expand Down
14 changes: 14 additions & 0 deletions lib/puppet_x/icinga2/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# simple parsing algorithm takes a decision for each attribute, whether part of the
# string is to be quoted or not, and how an array or dictionary is to be formatted.
#
# Parsing of a single attribute can be disabled by tagging it with -: at the front
# of the string.
#
# attr => '-:"unparsed string with quotes"'
#
# An array, a hash or a string can be assigned to an object attribute. True and false
# are also valid values.
#
Expand Down Expand Up @@ -62,6 +67,10 @@
#
# attr => 'array1 + [ item1, item2, ... ]' or attr => 'hash1 + { item1, ... }'
#
# Assignments other than simple attribution are not currently possible either, e.g. building something like
#
# vars += config
#
#
require 'puppet'

Expand Down Expand Up @@ -101,6 +110,11 @@ def self.attribute_types(attr)
def self.parse(row)
result = ''

# parser is disabled
if row =~ /^-:(.*)$/
return $1
end

# scan function
if row =~ /^\{{2}(.+)\}{2}$/
result += "{{%s}}" % [ $1 ]
Expand Down
16 changes: 16 additions & 0 deletions spec/defines/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@
end


context "#{os} with attrs => { vars => { bar => unparsed string } }" do
let(:params) { {:attrs => { 'vars' => { 'bar' => '-:"unparsed string"' } }, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/vars.bar = "unparsed string"/) }
end


context "#{os} with attrs => { vars => { bar => {} } }" do
let(:params) { {:attrs => { 'vars' => { 'bar' => {} } }, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }

Expand Down Expand Up @@ -447,6 +455,14 @@
end


context "Windows 2012 R2 with attrs => { vars => { bar => unparsed string } }" do
let(:params) { {:attrs => { 'vars' => { 'bar' => '-:"unparsed string"' } }, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/vars.bar = "unparsed string"/) }
end


context "Windows 2012 R2 with attrs => { vars => { bar => {} } }" do
let(:params) { {:attrs => { 'vars' => { 'bar' => {} } }, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }

Expand Down

0 comments on commit 9cedd81

Please sign in to comment.