1
2
3
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
29
|
# File 'modules/wmflib/lib/puppet/functions/wmflib/secret.rb', line 1
Puppet::Functions.create_function(:'wmflib::secret', Puppet::Functions::InternalFunction) do
dispatch :secret do
scope_param
param 'String', :secret
optional_param 'Boolean', :binary
optional_param 'String', :mod_name
optional_param 'String', :secs_subdir
return_type 'Variant[String,Binary]'
end
def secret(scope, secret, binary = false, mod_name = 'secret', secs_subdir = '/secrets/')
mod = Puppet::Module.find(mod_name)
fail("secret(): Module #{mod_name} not found") unless mod
path = File.join(mod.path + secs_subdir + secret)
path = Puppet::Parser::Files.find_file(path, scope.compiler.environment)
fail(ArgumentError, "secret(): invalid secret #{secret}") unless path && Puppet::FileSystem.exist?(path)
if binary
Puppet::Pops::Types::PBinaryType::Binary.from_binary_string(Puppet::FileSystem.binread(path))
else
Puppet::FileSystem.read_preserve_line_endings(path)
end
end
end
|