Puppet Function: wireguard::genpsk
- Defined in:
-
lib/puppet/functions/wireguard/genpsk.rb
- Function type:
- Ruby 4.x API
Overview
wireguard::genpsk(String $name, Optional[String] $path) ⇒ String
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
30
|
# File 'lib/puppet/functions/wireguard/genpsk.rb', line 1
Puppet::Functions.create_function(:'wireguard::genpsk') do
dispatch :genpsk do
required_param 'String', :name
optional_param 'String', :path
return_type 'String'
end
def genpsk(name, path='/etc/wireguard')
psk_path = File.join(path, "#{name}.psk")
raise Puppet::ParseError, "#{psk_path} is a directory" if File.directory?(psk_path)
dir = File.dirname(psk_path)
raise Puppet::ParseError, "#{dir} is not writable" if not File.writable?(dir)
unless File.exists?(psk_path)
psk = Puppet::Util::Execution.execute(
['/usr/bin/wg', 'genpsk'],
)
File.open(psk_path, 'w') do |f|
f << psk
end
end
File.read(psk_path)
end
end
|