diff options
author | Ismaël Bouya <ismael.bouya@normalesup.org> | 2017-08-30 22:16:39 +0200 |
---|---|---|
committer | Ismaël Bouya <ismael.bouya@normalesup.org> | 2017-08-31 22:59:53 +0200 |
commit | 548061112d2e2627317f9379d2f501fcf3f6ea54 (patch) | |
tree | 19fb949ad1fb965b4705897650809b4ffb6e9f29 /modules/base_installation/lib | |
parent | 1508e956adaa97b7a82c27537f4b124266dacdf0 (diff) | |
download | Puppet-548061112d2e2627317f9379d2f501fcf3f6ea54.tar.gz Puppet-548061112d2e2627317f9379d2f501fcf3f6ea54.tar.zst Puppet-548061112d2e2627317f9379d2f501fcf3f6ea54.zip |
Add LDAP support
Diffstat (limited to 'modules/base_installation/lib')
-rw-r--r-- | modules/base_installation/lib/puppet/parser/functions/generate_password.rb | 31 | ||||
-rw-r--r-- | modules/base_installation/lib/puppet/type/notify_refresh.rb | 45 |
2 files changed, 76 insertions, 0 deletions
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 @@ | |||
1 | module Puppet::Parser::Functions | ||
2 | newfunction(:generate_password, :type => :rvalue, :doc => <<-EOS | ||
3 | Returns a semi-random string based on a seed and a value. Will always generate the same value with the same entry. | ||
4 | Prototype: | ||
5 | generate_password(length, seed_file, password_key) | ||
6 | EOS | ||
7 | ) do |*arguments| | ||
8 | arguments = arguments.shift if arguments.first.is_a?(Array) | ||
9 | |||
10 | raise Puppet::ParseError, "generate_password(): Wrong number of arguments " + | ||
11 | "given (#{arguments.size} for 3)" if arguments.size != 3 | ||
12 | |||
13 | size = arguments.shift | ||
14 | seed_file = arguments.shift | ||
15 | password_key = arguments.shift | ||
16 | |||
17 | unless size.class.ancestors.include?(Numeric) or size.is_a?(String) | ||
18 | raise Puppet::ParseError, 'generate_password(): Requires a numeric first argument' | ||
19 | end | ||
20 | |||
21 | size = size.to_i | ||
22 | |||
23 | set = ('a' .. 'z').to_a + ('A' .. 'Z').to_a + ('0' .. '9').to_a | ||
24 | |||
25 | key = "#{File.open(seed_file).read}:#{password_key}" | ||
26 | |||
27 | size.times.collect do |i| | ||
28 | set[OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, i.to_s).to_i(16) % set.size] | ||
29 | end.join | ||
30 | end | ||
31 | 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 @@ | |||
1 | # | ||
2 | # Simple module for logging messages on the client-side | ||
3 | |||
4 | |||
5 | module Puppet | ||
6 | Type.newtype(:notify_refresh) do | ||
7 | @doc = "Sends an arbitrary message to the agent run-time log." | ||
8 | |||
9 | apply_to_all | ||
10 | |||
11 | newproperty(:message, :idempotent => false) do | ||
12 | desc "The message to be sent to the log." | ||
13 | def sync(refreshing = false) | ||
14 | if refreshing || !@resource.refreshonly? | ||
15 | Puppet.send(@resource[:loglevel], self.should) | ||
16 | end | ||
17 | return | ||
18 | end | ||
19 | |||
20 | def retrieve | ||
21 | :absent | ||
22 | end | ||
23 | |||
24 | def insync?(is) | ||
25 | true | ||
26 | end | ||
27 | |||
28 | defaultto { @resource[:name] } | ||
29 | end | ||
30 | |||
31 | def refresh | ||
32 | self.property(:message).sync(true) | ||
33 | end | ||
34 | |||
35 | newparam(:name) do | ||
36 | desc "An arbitrary tag for your own reference; the name of the message." | ||
37 | isnamevar | ||
38 | end | ||
39 | |||
40 | newparam(:refreshonly, :boolean => true, :parent => Puppet::Parameter::Boolean) do | ||
41 | defaultto false | ||
42 | end | ||
43 | |||
44 | end | ||
45 | end | ||