rename key
[mirror/dsa-puppet.git] / modules / onion / manifests / service.pp
1 define onion::service (
2         $port,
3         $target_address,
4         $target_port,
5         $ensure = present,
6         $direct = false
7 ) {
8         if ($ensure == "ifstatic") {
9                 $my_ensure = has_static_component($name) ? {
10                         true => "present",
11                         false => "absent"
12                 }
13         } else {
14                 $my_ensure = $ensure
15         }
16
17         if ($my_ensure == "present") {
18                 include onion
19
20                 concat::fragment { "onion::torrc_onionservice::${name}":
21                         target  => "/etc/tor/torrc",
22                         order   => 50,
23                         content => "HiddenServiceDir /var/lib/tor/onion/${name}\nHiddenServicePort ${port} ${target_address}:${target_port}\n\n",
24                 }
25
26                 $onion_hn = onion_tor_service_hostname($name)
27                 if $onion_hn {
28                         $hostname_without_onion = regsubst($onion_hn, '\.onion$', '')
29                         @@concat::fragment { "onion::balance::instance::$name::$fqdn":
30                                 target  => "/etc/onionbalance/config.yaml",
31                                 content => "      - address: ${hostname_without_onion}\n        name: ${hostname}-${name}\n",
32                                 order   => "50-${name}-20",
33                                 tag     => "onion::balance::$name",
34                         }
35
36                         if ($direct) {
37                                 @@concat::fragment { "onion::balance::onionbalance-services.yaml::${name}":
38                                         target  => "/srv/puppet.torproject.org/puppet-facts/onionbalance-services.yaml",
39                                         content => "{\"${name}\": \"${onion_hn}\"}\n",
40                                         tag     => "onionbalance-services.yaml",
41                                 }
42                         } else {
43                                 @@concat::fragment { "onion::balance::instance::dsa-snippet::$name::$fqdn":
44                                         target  => "/etc/onionbalance/config-dsa-snippet.yaml",
45                                         content => "- service: ${name}\n  address: ${hostname_without_onion}\n  host: ${hostname}-${name}\n",
46                                         tag     => "onion::balance::dsa-snippet",
47                                 }
48                         }
49                 }
50         }
51 }