Files
mgmt/modules/misc/main.mcl
2024-09-26 12:52:27 -04:00

28 lines
781 B
Plaintext

import "os"
# ssh_keygen creates an ssh key pair in the user's home directory if the private
# key doesn't exist.
# TODO: add more parameters such as key size and type in the future
class ssh_keygen($user) {
panic($user == "") # panic if $user is empty
$p = os.expand_home("~${user}/") # eg: ~james/
exec "ssh-keygen-${user}" {
cmd => "/usr/bin/ssh-keygen",
args => [
"-t", "rsa", # type
"-f", "${p}.ssh/id_rsa", # private key file
"-N", "", # empty password
],
creates => "${p}.ssh/id_rsa",
user => $user,
Before => File["${p}.ssh/id_rsa"],
}
# This also serves as a "handle" so that other resources can depend on
# this file getting created before they run.
file "${p}.ssh/id_rsa" {
mode => "u=rw,go=",
owner => $user,
}
}