diff --git a/REFERENCE.md b/REFERENCE.md
index b9be0630..c1c8d410 100644
--- a/REFERENCE.md
+++ b/REFERENCE.md
@@ -75,8 +75,7 @@ start on boot and will be restarted if stopped.
* [`icinga2::icinga2_attributes`](#icinga2icinga2_attributes): Calls the simple parser to decide what to quote.
For more information, see lib/puppet_x/icinga2/utils.rb.
* [`icinga2::icinga2_ticket_id`](#icinga2icinga2_ticket_id): Summarise what the function does here
-* [`icinga2_attributes`](#icinga2_attributes): DEPRECATED. Use the namespaced function [`icinga2::icinga2_attributes`](#icinga2_attributes) instead.
-* [`icinga2_ticket_id`](#icinga2_ticket_id): DEPRECATED. Use the namespaced function [`icinga2::icinga2_ticket_id`](#icinga2_ticket_id) instead.
+* [`icinga2::parse`](#icinga2parse): This function parse icinga object attributes.
### Data types
@@ -5258,18 +5257,35 @@ Type: Ruby 4.x API
Calls the simple parser to decide what to quote.
For more information, see lib/puppet_x/icinga2/utils.rb.
-#### `icinga2::icinga2_attributes(Any *$args)`
+#### `icinga2::icinga2_attributes(Hash $attrs, Array $globals, Hash $constants, Optional[Numeric] $indent)`
The icinga2::icinga2_attributes function.
-Returns: `Data type` Describe what the function returns here
+Returns: `String` Parsed attributes as String.
-##### `*args`
+##### `attrs`
-Data type: `Any`
+Data type: `Hash`
+
+Object attributes to parse.
+
+##### `globals`
+
+Data type: `Array`
+
+A list of addational reserved words.
+
+##### `constants`
+
+Data type: `Hash`
+
+A hash of additional constants.
-The original array of arguments. Port this to individually managed params
-to get the full benefit of the modern function API.
+##### `indent`
+
+Data type: `Optional[Numeric]`
+
+Indent to use.
### `icinga2::icinga2_ticket_id`
@@ -5295,41 +5311,41 @@ Data type: `Variant[String, Sensitive[String]]`
The ticket salt of the Icinga CA.
-### `icinga2_attributes`
+### `icinga2::parse`
-Type: Ruby 4.x API
+Type: Puppet Language
-DEPRECATED. Use the namespaced function [`icinga2::icinga2_attributes`](#icinga2_attributes) instead.
+This function parse icinga object attributes.
-#### `icinga2_attributes(Any *$args)`
+#### `icinga2::parse(Hash[String, Any] $attrs, Integer $indent = 0, Array[String] $reserved = [], Hash[String, Any] $constants = {})`
-The icinga2_attributes function.
+The icinga2::parse function.
-Returns: `Data type` Describe what the function returns here
+Returns: `Any`
-##### `*args`
+##### `attrs`
-Data type: `Any`
+Data type: `Hash[String, Any]`
-The original array of arguments.
-### `icinga2_ticket_id`
-Type: Ruby 4.x API
+##### `indent`
-DEPRECATED. Use the namespaced function [`icinga2::icinga2_ticket_id`](#icinga2_ticket_id) instead.
+Data type: `Integer`
-#### `icinga2_ticket_id(Any *$args)`
-The icinga2_ticket_id function.
-Returns: `String` Calculated ticket to receive a certificate.
+##### `reserved`
+
+Data type: `Array[String]`
+
+
+
+##### `constants`
-##### `*args`
+Data type: `Hash[String, Any]`
-Data type: `Any`
-The original array of arguments.
## Data types
diff --git a/functions/parse.pp b/functions/parse.pp
new file mode 100644
index 00000000..f29e5b8f
--- /dev/null
+++ b/functions/parse.pp
@@ -0,0 +1,28 @@
+# @summary
+# This function parse icinga object attributes.
+#
+function icinga2::parse(
+ Hash[String, Any] $attrs,
+ Integer $indent = 0,
+ Array[String] $reserved = [],
+ Hash[String, Any] $constants = {},
+) {
+ # @param attr
+ # Object attributes to parse.
+ #
+ # @param indent
+ # Indent to use.
+ #
+ # @param reserved
+ # A list of addational reserved words.
+ #
+ # @param constants
+ # A hash of additional constants.
+ #
+ icinga2::icinga2_attributes(
+ $attrs,
+ concat($::icinga2::globals::reserved, $reserved),
+ merge($::icinga2::_constants, $constants),
+ $indent
+ )
+}
diff --git a/lib/puppet/functions/icinga2/icinga2_attributes.rb b/lib/puppet/functions/icinga2/icinga2_attributes.rb
index d73a5cdd..c157fcb7 100644
--- a/lib/puppet/functions/icinga2/icinga2_attributes.rb
+++ b/lib/puppet/functions/icinga2/icinga2_attributes.rb
@@ -5,40 +5,30 @@
# For more information, see lib/puppet_x/icinga2/utils.rb.
#
Puppet::Functions.create_function(:'icinga2::icinga2_attributes') do
- # @param args
- # The original array of arguments. Port this to individually managed params
- # to get the full benefit of the modern function API.
+ # @param attrs
+ # Object attributes to parse.
#
- # @return [Data type]
- # Describe what the function returns here
+ # @param globals
+ # A list of addational reserved words.
#
- dispatch :default_impl do
- # Call the method named 'default_impl' when this is matched
- # Port this to match individual params for better type safety
- repeated_param 'Any', :args
+ # @param constants
+ # A hash of additional constants.
+ #
+ # @return [String]
+ # Parsed attributes as String.
+ #
+ # @param indent
+ # Indent to use.
+ #
+ dispatch :icinga2_attributes do
+ required_param 'Hash', :attrs
+ required_param 'Array', :globals
+ required_param 'Hash', :constants
+ optional_param 'Numeric', :indent
+ return_type 'String'
end
- def default_impl(*args)
- raise Puppet::ParseError, 'icinga2::atributes(): Must provide at least one argument.' if args.length > 4 || args.empty?
-
- indent = if args[1]
- args[1]
- else
- 0
- end
-
- globals = if args[2]
- closure_scope['::icinga2::_reserved'].concat(args[2])
- else
- closure_scope['::icinga2::_reserved']
- end
-
- constants = if args[3]
- closure_scope['::icinga2::_constants'].merge(args[3])
- else
- closure_scope['::icinga2::_constants']
- end
-
- Puppet::Icinga2::Utils.attributes(args[0], globals, constants, indent)
+ def icinga2_attributes(attrs, globals, constants, indent = 0)
+ Puppet::Icinga2::Utils.attributes(attrs, globals, constants, indent)
end
end
diff --git a/lib/puppet/functions/icinga2_attributes.rb b/lib/puppet/functions/icinga2_attributes.rb
deleted file mode 100644
index 8ea573d0..00000000
--- a/lib/puppet/functions/icinga2_attributes.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# @summary DEPRECATED. Use the namespaced function [`icinga2::icinga2_attributes`](#icinga2_attributes) instead.
-Puppet::Functions.create_function(:icinga2_attributes) do
- # @param args
- # The original array of arguments.
- #
- # @return [Data type]
- # Describe what the function returns here
- #
- dispatch :deprecation_gen do
- repeated_param 'Any', :args
- end
- def deprecation_gen(*args)
- call_function('deprecation', 'icinga2_attributes', 'This method is deprecated, please use icinga2::icinga2_attributes instead.')
- call_function('icinga2::icinga2_attributes', *args)
- end
-end
diff --git a/lib/puppet/functions/icinga2_ticket_id.rb b/lib/puppet/functions/icinga2_ticket_id.rb
deleted file mode 100644
index 41cb61d7..00000000
--- a/lib/puppet/functions/icinga2_ticket_id.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# @summary DEPRECATED. Use the namespaced function [`icinga2::icinga2_ticket_id`](#icinga2_ticket_id) instead.
-Puppet::Functions.create_function(:icinga2_ticket_id) do
- # @param args
- # The original array of arguments.
- #
- # @return [String]
- # Calculated ticket to receive a certificate.
- #
- dispatch :deprecation_gen do
- repeated_param 'Any', :args
- end
- def deprecation_gen(*args)
- call_function('deprecation', 'icinga2_ticket_id', 'This method is deprecated, please use icinga2::icinga2_ticket_id instead.')
- call_function('icinga2::icinga2_ticket_id', *args)
- end
-end
diff --git a/manifests/config.pp b/manifests/config.pp
index a65e209b..7c568a94 100644
--- a/manifests/config.pp
+++ b/manifests/config.pp
@@ -16,11 +16,11 @@
$purge_features = $::icinga2::purge_features
if $::facts['kernel'] != 'windows' {
- $template_constants = icinga2::icinga2_attributes($constants)
+ $template_constants = icinga2::parse($constants)
$template_mainconfig = template('icinga2/icinga2.conf.erb')
$file_permissions = '0640'
} else {
- $template_constants = regsubst(icinga2::icinga2_attributes($constants), '\n', "\r\n", 'EMG')
+ $template_constants = regsubst(icinga2::parse($constants), '\n', "\r\n", 'EMG')
$template_mainconfig = regsubst(template('icinga2/icinga2.conf.erb'), '\n', "\r\n", 'EMG')
$file_permissions = undef
}
diff --git a/templates/object.conf.epp b/templates/object.conf.epp
new file mode 100644
index 00000000..ffd44e0b
--- /dev/null
+++ b/templates/object.conf.epp
@@ -0,0 +1,43 @@
+<%- | Hash $attrs,
+ Array $attrs_list,
+ Variant[String, Boolean] $apply,
+ Optional[String] $apply_target = undef,
+ Variant[String, Boolean] $prefix,
+ String $object_type,
+ String $object_name,
+ Boolean $template,
+ Array $import,
+| -%>
+
+<% if $apply =~ String { %>apply <%= $object_type -%>
+<% if $prefix { -%>
+<% if $prefix =~ String { %> "<%= $prefix %>"<% } else { -%>
+<% if $object_name in $icinga2::_constants { -%>
+ <%= $object_name -%>
+<% } else { -%>
+ "<%= $object_name -%>"<% } -%>
+<% } -%>
+<% } -%>
+ for (<%= $apply %>)<% if $apply_target { %> to <%= $apply_target %><% } %> {
+<% } else { -%>
+<% if $apply { %>apply<% } else { -%>
+<% if $template { %>template<% } else { %>object<% } -%>
+<% } %> <%= $object_type -%>
+<% if $object_name in $icinga2::_constants { -%>
+ <%= $object_name -%>
+<% } else { -%>
+ "<%= $object_name %>"<% } -%>
+<% if $apply and $apply_target { %> to <%= $apply_target %><% } %> {
+<% } -%>
+<% $import.each |$i| { -%>
+ import "<%= $i %>"
+<% } -%>
+<% unless $import =~ Array[Data,0,0] { %><%= "\n" %><% } -%>
+<% if $apply =~String and $apply =~ /^([A-Za-z_]+)\s+in\s+.+$/ { -%>
+<%= icinga2::parse($attrs, 2, $attrs_list, {$1=>{}}) -%>
+<% } elsif $apply =~ String and $apply =~ /^([A-Za-z_]+)\s+=>\s+([A-Za-z_]+)\s+in\s+.+$/ { -%>
+<%= icinga2::parse($attrs, 2, $attrs_list+[$1], {$2=>{}}) -%>
+<% } else { -%>
+<%= icinga2::parse($attrs, 2, $attrs_list) -%>
+<% } -%>
+}
diff --git a/templates/object.conf.erb b/templates/object.conf.erb
index 860062c3..4dd454d1 100644
--- a/templates/object.conf.erb
+++ b/templates/object.conf.erb
@@ -24,10 +24,10 @@
<% end -%>
<% unless @import.empty? %><%= "\n" %><% end -%>
<% if @apply.is_a?(String) and @apply =~ /^([A-Za-z_]+)\s+in\s+.+$/ -%>
-<%= scope.call_function('icinga2::icinga2_attributes', [@_attrs,2,@attrs_list,{$1=>{}}]) -%>
+<%= scope.call_function('icinga2::parse', [@_attrs,2,@attrs_list,{$1=>{}}]) -%>
<% elsif @apply.is_a?(String) and @apply =~ /^([A-Za-z_]+)\s+=>\s+([A-Za-z_]+)\s+in\s+.+$/ -%>
-<%= scope.call_function('icinga2::icinga2_attributes', [@_attrs,2,@attrs_list.concat([$1]),{$2=>{}}]) -%>
+<%= scope.call_function('icinga2::parse', [@_attrs,2,@attrs_list.concat([$1]),{$2=>{}}]) -%>
<% else -%>
-<%= scope.call_function('icinga2::icinga2_attributes', [@_attrs,2,@attrs_list]) -%>
+<%= scope.call_function('icinga2::parse', [@_attrs,2,@attrs_list]) -%>
<% end -%>
}