summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/functions/deprecation.rb6
-rw-r--r--lib/puppet/functions/type_of.rb2
-rw-r--r--lib/puppet/parser/functions/deprecation.rb4
-rw-r--r--lib/puppet/parser/functions/ensure_packages.rb2
-rw-r--r--lib/puppet/parser/functions/fqdn_uuid.rb92
-rw-r--r--lib/puppet/parser/functions/pry.rb30
6 files changed, 133 insertions, 3 deletions
diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb
index a860aa2..39d9bc7 100644
--- a/lib/puppet/functions/deprecation.rb
+++ b/lib/puppet/functions/deprecation.rb
@@ -8,6 +8,12 @@ Puppet::Functions.create_function(:deprecation) do
end
def deprecation(key, message)
+ if defined? Puppet::Pops::PuppetStack.stacktrace()
+ stacktrace = Puppet::Pops::PuppetStack.stacktrace()
+ file = stacktrace[0]
+ line = stacktrace[1]
+ message = "#{message} at #{file}:#{line}"
+ end
# depending on configuration setting of strict
case Puppet.settings[:strict]
when :off
diff --git a/lib/puppet/functions/type_of.rb b/lib/puppet/functions/type_of.rb
index 02cdd4d..01f1f49 100644
--- a/lib/puppet/functions/type_of.rb
+++ b/lib/puppet/functions/type_of.rb
@@ -10,6 +10,8 @@
# See the documentation for "The Puppet Type System" for more information about types.
# See the `assert_type()` function for flexible ways to assert the type of a value.
#
+# The built-in type() function in puppet is generally preferred over this function
+# this function is provided for backwards compatibility.
Puppet::Functions.create_function(:type_of) do
def type_of(value)
Puppet::Pops::Types::TypeCalculator.infer_set(value)
diff --git a/lib/puppet/parser/functions/deprecation.rb b/lib/puppet/parser/functions/deprecation.rb
index e30f3a0..cd64fe2 100644
--- a/lib/puppet/parser/functions/deprecation.rb
+++ b/lib/puppet/parser/functions/deprecation.rb
@@ -1,5 +1,5 @@
module Puppet::Parser::Functions
- newfunction(:deprecation, :type => :rvalue, :doc => <<-EOS
+ newfunction(:deprecation, :doc => <<-EOS
Function to print deprecation warnings (this is the 3.X version of it), The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method.).
EOS
) do |arguments|
@@ -9,7 +9,7 @@ EOS
key = arguments[0]
message = arguments[1]
-
+
if ENV['STDLIB_LOG_DEPRECATIONS'] == "true"
warning("deprecation. #{key}. #{message}")
end
diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb
index 532b702..439af1e 100644
--- a/lib/puppet/parser/functions/ensure_packages.rb
+++ b/lib/puppet/parser/functions/ensure_packages.rb
@@ -25,7 +25,7 @@ third argument to the ensure_resource() function.
end
Puppet::Parser::Functions.function(:ensure_resources)
- function_ensure_resources(['package', Hash(arguments[0]), defaults ])
+ function_ensure_resources(['package', arguments[0].dup, defaults ])
else
packages = Array(arguments[0])
diff --git a/lib/puppet/parser/functions/fqdn_uuid.rb b/lib/puppet/parser/functions/fqdn_uuid.rb
new file mode 100644
index 0000000..30205d0
--- /dev/null
+++ b/lib/puppet/parser/functions/fqdn_uuid.rb
@@ -0,0 +1,92 @@
+require 'digest/sha1'
+
+module Puppet::Parser::Functions
+ newfunction(:fqdn_uuid, :type => :rvalue, :doc => <<-END) do |args|
+
+ Creates a UUID based on a given string, assumed to be the FQDN
+
+ For example, to generate a UUID based on the FQDN of a system:
+
+ Usage:
+
+ $uuid = fqdn_uuid($::fqdn)
+
+ The generated UUID will be the same for the given hostname
+
+ The resulting UUID is returned on the form:
+
+ 1d839dea-5e10-5243-88eb-e66815bd7d5c
+
+ (u.e. without any curly braces.)
+
+ The generated UUID is a version 5 UUID with the V5 DNS namespace:
+
+ 6ba7b810-9dad-11d1-80b4-00c04fd430c8
+
+ This only supports a the V5 SHA-1 hash, using the DNS namespace.
+
+ Please consult http://www.ietf.org/rfc/rfc4122.txt for the details on
+ UUID generation and example implementation.
+
+ No verification is present at the moment as whether the domain name given
+ is in fact a correct fully-qualified domain name. Therefore any arbitrary
+ string and/or alpha-numeric value can subside for a domain name.
+ EOS
+
+ END
+
+ if args.length == 0
+ raise(ArgumentError, "fqdn_uuid: No arguments given")
+ elsif args.length == 1
+ fqdn = args[0]
+ else
+ raise(ArgumentError, "fqdn_uuid: Too many arguments given (#{args.length})")
+ end
+
+ # Code lovingly taken from
+ # https://github.com/puppetlabs/marionette-collective/blob/master/lib/mcollective/ssl.rb
+
+ # This is the UUID version 5 type DNS name space which is as follows:
+ #
+ # 6ba7b810-9dad-11d1-80b4-00c04fd430c8
+ #
+ uuid_name_space_dns = [0x6b,
+ 0xa7,
+ 0xb8,
+ 0x10,
+ 0x9d,
+ 0xad,
+ 0x11,
+ 0xd1,
+ 0x80,
+ 0xb4,
+ 0x00,
+ 0xc0,
+ 0x4f,
+ 0xd4,
+ 0x30,
+ 0xc8
+ ].map {|b| b.chr}.join
+
+ sha1 = Digest::SHA1.new
+ sha1.update(uuid_name_space_dns)
+ sha1.update(fqdn)
+
+ # first 16 bytes..
+ bytes = sha1.digest[0, 16].bytes.to_a
+
+ # version 5 adjustments
+ bytes[6] &= 0x0f
+ bytes[6] |= 0x50
+
+ # variant is DCE 1.1
+ bytes[8] &= 0x3f
+ bytes[8] |= 0x80
+
+ bytes = [4, 2, 2, 2, 6].collect do |i|
+ bytes.slice!(0, i).pack('C*').unpack('H*')
+ end
+
+ bytes.join('-')
+ end
+end
diff --git a/lib/puppet/parser/functions/pry.rb b/lib/puppet/parser/functions/pry.rb
new file mode 100644
index 0000000..c18ef7e
--- /dev/null
+++ b/lib/puppet/parser/functions/pry.rb
@@ -0,0 +1,30 @@
+#
+# pry.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:pry, :type => :statement, :doc => <<-EOS
+This function invokes a pry debugging session in the current scope object. This is useful for debugging manifest code at specific points during a compilation.
+
+*Examples:*
+
+ pry()
+ EOS
+ ) do |arguments|
+ begin
+ require 'pry'
+ rescue LoadError
+ raise(Puppet::Error, "pry(): Requires the 'pry' rubygem to use, but it was not found")
+ end
+ #
+ ## Run `catalog` to see the contents currently compiling catalog
+ ## Run `cd catalog` and `ls` to see catalog methods and instance variables
+ ## Run `@resource_table` to see the current catalog resource table
+ #
+ if $stdout.isatty
+ binding.pry # rubocop:disable Lint/Debugger
+ else
+ Puppet.warning 'pry(): cowardly refusing to start the debugger on a daemonized master'
+ end
+ end
+end