5 module Puppet::Parser::Functions
6 newfunction(:fqdn_uuid, :type => :rvalue, :doc => <<-DOC) do |args|
8 Returns a [RFC 4122](https://tools.ietf.org/html/rfc4122) valid version 5 UUID based
9 on an FQDN string under the DNS namespace
12 Returns a [RFC 4122](https://tools.ietf.org/html/rfc4122) valid version 5 UUID
14 @example Example Usage:
15 fqdn_uuid('puppetlabs.com') # Returns '9c70320f-6815-5fc5-ab0f-debe68bf764c'
16 fqdn_uuid('google.com') # Returns '64ee70a4-8cc1-5d25-abf2-dea6c79a09c8'
19 raise(ArgumentError, 'fqdn_uuid: No arguments given') if args.empty?
20 raise(ArgumentError, "fqdn_uuid: Too many arguments given (#{args.length})") unless args.length == 1
23 # Code lovingly taken from
24 # https://github.com/puppetlabs/marionette-collective/blob/master/lib/mcollective/ssl.rb
26 # This is the UUID version 5 type DNS name space which is as follows:
28 # 6ba7b810-9dad-11d1-80b4-00c04fd430c8
30 uuid_name_space_dns = [0x6b,
45 0xc8].map { |b| b.chr }.join
47 sha1 = Digest::SHA1.new
48 sha1.update(uuid_name_space_dns)
52 bytes = sha1.digest[0, 16].bytes.to_a
54 # version 5 adjustments
62 bytes = [4, 2, 2, 2, 6].map do |i|
63 bytes.slice!(0, i).pack('C*').unpack('H*')