From 548061112d2e2627317f9379d2f501fcf3f6ea54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 30 Aug 2017 22:16:39 +0200 Subject: Add LDAP support --- .../puppet/parser/functions/generate_password.rb | 31 +++++++++++++++ .../lib/puppet/type/notify_refresh.rb | 45 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 modules/base_installation/lib/puppet/parser/functions/generate_password.rb create mode 100644 modules/base_installation/lib/puppet/type/notify_refresh.rb (limited to 'modules/base_installation/lib/puppet') diff --git a/modules/base_installation/lib/puppet/parser/functions/generate_password.rb b/modules/base_installation/lib/puppet/parser/functions/generate_password.rb new file mode 100644 index 0000000..384d81b --- /dev/null +++ b/modules/base_installation/lib/puppet/parser/functions/generate_password.rb @@ -0,0 +1,31 @@ +module Puppet::Parser::Functions + newfunction(:generate_password, :type => :rvalue, :doc => <<-EOS +Returns a semi-random string based on a seed and a value. Will always generate the same value with the same entry. +Prototype: + generate_password(length, seed_file, password_key) +EOS +) do |*arguments| + arguments = arguments.shift if arguments.first.is_a?(Array) + + raise Puppet::ParseError, "generate_password(): Wrong number of arguments " + + "given (#{arguments.size} for 3)" if arguments.size != 3 + + size = arguments.shift + seed_file = arguments.shift + password_key = arguments.shift + + unless size.class.ancestors.include?(Numeric) or size.is_a?(String) + raise Puppet::ParseError, 'generate_password(): Requires a numeric first argument' + end + + size = size.to_i + + set = ('a' .. 'z').to_a + ('A' .. 'Z').to_a + ('0' .. '9').to_a + + key = "#{File.open(seed_file).read}:#{password_key}" + + size.times.collect do |i| + set[OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, i.to_s).to_i(16) % set.size] + end.join +end +end diff --git a/modules/base_installation/lib/puppet/type/notify_refresh.rb b/modules/base_installation/lib/puppet/type/notify_refresh.rb new file mode 100644 index 0000000..35f0cda --- /dev/null +++ b/modules/base_installation/lib/puppet/type/notify_refresh.rb @@ -0,0 +1,45 @@ +# +# Simple module for logging messages on the client-side + + +module Puppet + Type.newtype(:notify_refresh) do + @doc = "Sends an arbitrary message to the agent run-time log." + + apply_to_all + + newproperty(:message, :idempotent => false) do + desc "The message to be sent to the log." + def sync(refreshing = false) + if refreshing || !@resource.refreshonly? + Puppet.send(@resource[:loglevel], self.should) + end + return + end + + def retrieve + :absent + end + + def insync?(is) + true + end + + defaultto { @resource[:name] } + end + + def refresh + self.property(:message).sync(true) + end + + newparam(:name) do + desc "An arbitrary tag for your own reference; the name of the message." + isnamevar + end + + newparam(:refreshonly, :boolean => true, :parent => Puppet::Parameter::Boolean) do + defaultto false + end + + end +end -- cgit v1.2.3