forked from bzed/bzed-dehydrated
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.pp
152 lines (134 loc) · 4.91 KB
/
request.pp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# Does all the necessary things to be able to request a certificate
# from letsencrypt using the csr created and shipped to the
# dehydrated_host.
#
# @summary Prepare everything to request a certifificate for our CSRs.
#
# @example
# dehydrated::certificate::request { 'namevar':
# request_fqdn => 'foo.bar.example.com',
# dn => 'domain.bar.example.com',
# config => {},
# }
#
# @api private
#
define dehydrated::certificate::request (
Stdlib::Fqdn $request_fqdn,
Dehydrated::DN $dn,
Hash $config,
) {
require dehydrated::params
if ! defined(Class['dehydrated']) {
fail('You must include the dehydrated base class first.')
}
$base_filename = $config['base_filename']
$dh_param_size = $config['dh_param_size']
$csr = $config['csr']
$crt_serial = $config['crt_serial']
$subject_alternative_names = $config['subject_alternative_names']
$dehydrated_host = $config['dehydrated_host']
$dehydrated_environment = $config['dehydrated_environment']
$dehydrated_hook = $config['dehydrated_hook']
if (!$dehydrated_hook or $dehydrated_hook == '') {
$dehydrated_hook_script = undef
} else {
$dehydrated_hook_script = join( [$dehydrated::dehydrated_hooks_dir, $dehydrated_hook],
$dehydrated::params::path_seperator,
)
}
$dehydrated_domain_validation_hook = $config['dehydrated_domain_validation_hook']
if (!$dehydrated_domain_validation_hook or $dehydrated_domain_validation_hook == '') {
$dehydrated_domain_validation_hook_script = undef
} else {
$dehydrated_domain_validation_hook_script = join( [$dehydrated::dehydrated_hooks_dir, $dehydrated_domain_validation_hook],
$dehydrated::params::path_seperator,
)
}
$letsencrypt_ca = $config['letsencrypt_ca']
$dehydrated_contact_email = pick_default($config['dehydrated_contact_email'], '')
$challengetype = $config['challengetype']
# added later, handle missing config
$_preferred_chain = $config.dig('preferred_chain')
if !empty($_preferred_chain) {
$preferred_chain = $_preferred_chain
} else {
$preferred_chain = undef
}
$dehydrated_requests_dir = $dehydrated::dehydrated_requests_dir
$request_fqdn_dir = join( [$dehydrated_requests_dir, $request_fqdn],
$dehydrated::params::path_seperator
)
$request_base_dir = join( [$request_fqdn_dir, $base_filename],
$dehydrated::params::path_seperator
)
$request_account_dir = join( [$request_fqdn_dir, 'accounts'],
$dehydrated::params::path_seperator
)
$csr_file = join( [$request_base_dir, "${base_filename}.csr"],
$dehydrated::params::path_seperator
)
$dehydrated_config = join( [$request_base_dir, "${base_filename}.config"],
$dehydrated::params::path_seperator
)
$letsencrypt_ca_url = $dehydrated::letsencrypt_cas[$letsencrypt_ca]['url']
$letsencrypt_ca_hash = $dehydrated::letsencrypt_cas[$letsencrypt_ca]['hash']
$dehydrated_wellknown_dir = $dehydrated::dehydrated_wellknown_dir
$dehydrated_alpncert_dir = $dehydrated::dehydrated_alpncert_dir
File {
owner => $dehydrated::dehydrated_user,
group => $dehydrated::dehydrated_group,
}
ensure_resource(
'file',
$request_fqdn_dir,
{
'ensure' => 'directory',
'owner' => $dehydrated::dehydrated_user,
'group' => $dehydrated::dehydrated_group,
'mode' => '0755',
}
)
ensure_resource(
'file',
$request_base_dir,
{
'ensure' => 'directory',
'owner' => $dehydrated::dehydrated_user,
'group' => $dehydrated::dehydrated_group,
'mode' => '0755',
}
)
file { $csr_file :
ensure => file,
content => $csr,
}
file { $dehydrated_config :
ensure => file,
content => template('dehydrated/dehydrated/config.erb'),
}
$request_config = {
$request_fqdn => {
$dn => {
'subject_alternative_names' => $subject_alternative_names,
'base_filename' => $base_filename,
'crt_serial' => $crt_serial,
'request_fqdn_dir' => $request_fqdn_dir,
'request_base_dir' => $request_base_dir,
'dehydrated_environment' => $dehydrated_environment,
'dehydrated_hook_script' => $dehydrated_hook_script,
'dehydrated_domain_validation_hook_script' => $dehydrated_domain_validation_hook_script,
'dehydrated_contact_email' => $dehydrated_contact_email,
'letsencrypt_ca_url' => $letsencrypt_ca_url,
'letsencrypt_ca_hash' => $letsencrypt_ca_hash,
'dehydrated_config' => $dehydrated_config,
},
},
}
$json_fragment = to_json($request_config)
::concat::fragment { "${facts['dehydrated::dehydrated_requests_config']}-${name}" :
target => $dehydrated::dehydrated_requests_config,
content => $json_fragment,
order => '50',
}
}