1 # Class: profiles::cacert_selfservice_api
2 # =======================================
4 # This class defines the cacert_selfservice_api profile that installs the
5 # CAcert community self service system API backend
10 # @param server_certificate PEM encoded X.509 server certificate
12 # @param server_private_key PEM encoded unencrypted RSA private key
14 # @param db_username MariaDB/MySQL user name
16 # @param db_password MariaDB/MySQL password
18 # @param db_name MariaDB/MySQL database name
20 # @param notification_recipient_address notification email recipient address
22 # @param notification_recipient_name notification email recipient name
24 # @param notification_sender_address notification email sender address
26 # @param mail_host hostname or IP address of the outgoing
29 # @param mail_port TCP port number of the outgoing email
32 # @param client_identities List of client identies consisting of an
33 # id and key field for each client
39 # class roles::myhost {
40 # include profiles::cacert_selfservice_api
46 # Jan Dittberner <jandd@cacert.org>
51 # Copyright 2019 Jan Dittberner
53 class profiles::cacert_selfservice_api (
54 String $server_certificate,
55 String $server_private_key,
56 String $listen_address = ":9443",
59 String $db_name = 'cacertusers',
60 String $notification_recipient_address = 'email-admin@cacert.org',
61 String $notification_recipient_name = 'CAcert email administrators',
62 String $notification_sender_address = 'returns@cacert.org',
63 String $mail_host = 'localhost',
64 Integer $mail_port = 25,
65 Array[Hash[String, String]] $client_identities,
67 include profiles::cacert_debrepo
69 $service_name = 'cacert-selfservice-api'
70 $config_directory = "/etc/${service_name}"
71 $config_file = "${config_directory}/config.yaml"
72 $server_certificate_file = "${config_directory}/certs/server.crt.pem"
73 $server_key_file = "${config_directory}/private/server.key.pem"
74 $log_directory = "/var/log/${service_name}"
76 package { $service_name:
78 require => Apt::Source['cacert'],
81 file { $log_directory:
83 owner => $service_name,
86 require => Package[$service_name],
88 file { "${config_directory}/certs":
90 owner => $service_name,
93 require => Package[$service_name],
95 file { "${config_directory}/private":
97 owner => $service_name,
100 require => Package[$service_name],
102 file { $server_certificate_file:
104 owner => $service_name,
107 content => $server_certificate,
108 require => File["${config_directory}/certs"],
109 notify => Service[$service_name],
111 file { $server_key_file:
113 owner => $service_name,
116 content => $server_private_key,
117 require => File["${config_directory}/private"],
118 notify => Service[$service_name],
121 $api_clients = $client_identities.map |$identity| {
123 id => $identity['id'],
124 key_lines => split($identity['key'], "\n"),
130 owner => $service_name,
133 content => epp('profiles/cacert_selfservice_api/config.yaml.epp', {
134 server_certificate => $server_certificate_file,
135 server_key => $server_key_file,
136 listen_address => $listen_address,
137 db_username => $db_username,
138 db_password => $db_password,
140 notification_sender => $notification_sender_address,
141 notification_recipient_address => $notification_recipient_address,
142 notification_recipient_name => $notification_recipient_name,
143 mail_host => $mail_host,
144 mail_port => $mail_port,
145 clients => $api_clients,
146 log_directory => $log_directory,
148 require => Package[$service_name],
149 notify => Service[$service_name],
152 service { $service_name:
155 require => Package[$service_name],