diff --git a/lib/puppet/functions/icinga2/icinga2_attributes.rb b/lib/puppet/functions/icinga2/icinga2_attributes.rb new file mode 100644 index 000000000..c9eb5ff20 --- /dev/null +++ b/lib/puppet/functions/icinga2/icinga2_attributes.rb @@ -0,0 +1,56 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +require File.join(File.dirname(__FILE__), '../../..', 'puppet_x/icinga2/utils.rb') + +# ---- original file header ---- +# +# @summary +# Summarise what the function does here +# +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. + # + # @return [Data type] + # Describe what the function returns here + # + 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 + end + + + def default_impl(*args) + + raise Puppet::ParseError, 'icinga2_atributes(): Must provide at least one argument.' if args.length > 4 || args.length < 1 + + if args[1] + indent = args[1] + else + indent = 0 + end + + if args[2] + globals = args[2].concat(lookupvar('::icinga2::_reserved')) + else + globals = lookupvar('::icinga2::_reserved') + end + + if args[3] + constants = args[3].merge(lookupvar('::icinga2::_constants')) + else + constants = lookupvar('::icinga2::_constants') + end + + Puppet::Icinga2::Utils.attributes(args[0], globals, constants, indent) + + end +end diff --git a/lib/puppet/functions/icinga2/icinga2_ticket_id.rb b/lib/puppet/functions/icinga2/icinga2_ticket_id.rb new file mode 100644 index 000000000..88060c1bd --- /dev/null +++ b/lib/puppet/functions/icinga2/icinga2_ticket_id.rb @@ -0,0 +1,50 @@ +# This is an autogenerated function, ported from the original legacy version. +# It /should work/ as is, but will not have all the benefits of the modern +# function API. You should see the function docs to learn how to add function +# signatures for type safety and to document this function using puppet-strings. +# +# https://puppet.com/docs/puppet/latest/custom_functions_ruby.html +# +# ---- original file header ---- +require File.join(File.dirname(__FILE__), '../../..', 'puppet_x/icinga2/pbkdf2.rb') + +# ---- original file header ---- +# +# @summary +# Summarise what the function does here +# +Puppet::Functions.create_function(:'icinga2::icinga2_ticket_id') do + # @param args + # The original array of arguments. Port this to individually managed params + # to get the full benefit of the modern function API. + # + # @return [Data type] + # Describe what the function returns here + # + 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 + end + + + def default_impl(*args) + + raise Puppet::ParseError, 'Must provide exactly two arguments to icinga2_ticket_id' if args.length != 2 + + if !args[0] or args[0] == '' + raise Puppet::ParseError, 'first argument (cn) can not be empty for icinga2_ticket_id' + end + if !args[1] or args[1] == '' + raise Puppet::ParseError, 'second argument (salt) can not be empty for icinga2_ticket_id' + end + + PBKDF2.new( + :password => args[0], + :salt => args[1], + :iterations => 50000, + :hash_function => OpenSSL::Digest.new("sha1") + ).hex_string + + end +end diff --git a/spec/functions/icinga2_icinga2_attributes_spec.rb b/spec/functions/icinga2_icinga2_attributes_spec.rb new file mode 100644 index 000000000..68d80db8e --- /dev/null +++ b/spec/functions/icinga2_icinga2_attributes_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'icinga2::icinga2_attributes' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end diff --git a/spec/functions/icinga2_icinga2_ticket_id_spec.rb b/spec/functions/icinga2_icinga2_ticket_id_spec.rb new file mode 100644 index 000000000..ab37b9355 --- /dev/null +++ b/spec/functions/icinga2_icinga2_ticket_id_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'icinga2::icinga2_ticket_id' do + # without knowing details about the implementation, this is the only test + # case that we can autogenerate. You should add more examples below! + it { is_expected.not_to eq(nil) } + +################################# +# Below are some example test cases. You may uncomment and modify them to match +# your needs. Notice that they all expect the base error class of `StandardError`. +# This is because the autogenerated function uses an untyped array for parameters +# and relies on your implementation to do the validation. As you convert your +# function to proper dispatches and typed signatures, you should change the +# expected error of the argument validation examples to `ArgumentError`. +# +# Other error types you might encounter include +# +# * StandardError +# * ArgumentError +# * Puppet::ParseError +# +# Read more about writing function unit tests at https://rspec-puppet.com/documentation/functions/ +# +# it 'raises an error if called with no argument' do +# is_expected.to run.with_params.and_raise_error(StandardError) +# end +# +# it 'raises an error if there is more than 1 arguments' do +# is_expected.to run.with_params({ 'foo' => 1 }, 'bar' => 2).and_raise_error(StandardError) +# end +# +# it 'raises an error if argument is not the proper type' do +# is_expected.to run.with_params('foo').and_raise_error(StandardError) +# end +# +# it 'returns the proper output' do +# is_expected.to run.with_params(123).and_return('the expected output') +# end +################################# + +end