Puppet Function: secret

Defined in:
puppet/modules/wmflib/lib/puppet/parser/functions/secret.rb
Function type:
Ruby 3.x API

Overview

secret()Any

Returns:

  • (Any)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'puppet/modules/wmflib/lib/puppet/parser/functions/secret.rb', line 4

newfunction(:secret, :type => :rvalue) do |args|
  mod_name = 'secret'
  secs_subdir = '/secrets/'

  if args.length != 1 || !args.first.is_a?(String)
    fail(ArgumentError, 'secret(): exactly one string arg')
  end
  in_path = args.first

  if mod = Puppet::Module.find(mod_name)
     mod_path = mod.path()
  else
    fail("secret(): Module #{mod_name} not found")
  end

  sec_path = mod_path + secs_subdir + in_path
  final_path = Pathname.new(sec_path).cleanpath()

  # Bail early if it's not a regular, readable file
  if !final_path.file? || !final_path.readable?
    fail(ArgumentError, "secret(): invalid secret #{in_path}")
  end

  return final_path.read()
end