Puppet Function: krb5::munge_conf_filename

Defined in:
lib/puppet/functions/krb5/munge_conf_filename.rb
Function type:
Ruby 4.x API

Overview

krb5::munge_conf_filename(String $name)Any

Returns a string that is safe to use as a filename for including in

krb5 configuration files.

Parameters:

  • name (String)

    String to be converted to a k4b6 configuration filename

Returns:

  • (Any)

    String transformed filename



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puppet/functions/krb5/munge_conf_filename.rb', line 5

Puppet::Functions.create_function(:'krb5::munge_conf_filename') do
  # @param name String to be converted to a k4b6 configuration filename
  # @return String transformed filename
  dispatch(:munge_conf_filename) do
    required_param 'String', :name
  end

  def munge_conf_filename(name)
    filename = name.strip.split('').map { |chr|
      if chr =~ %r{^[A-Za-z0-9_-]$}
        chr
      else
        '-'
      end
    }.join
    # filenames that start with '-' are hard to work with
    # because the '-' gets confused with command options
    filename[0] = '_' if filename[0] == '-'
    filename
  end
end