package io.trygvis.rules.acme; import java.util.ArrayList import io.trygvis.rules.machine.Machine; import io.trygvis.rules.dns.DnsEntry; import io.trygvis.rules.acme.AcmeServer import io.trygvis.rules.acme.WgHost; dialect "mvel" declare WgNet name : String domain : String end declare WgHost name : String net : String publicName : String netToNetIp : String networkIp : String end rule "WgHost VPN machines" when $machine : Machine() $wgNet : WgNet(name == "vpn0") not(WgHost(name == $machine.name)) then var wgHost = new WgHost(); wgHost.name = $machine.name; wgHost.net = $wgNet.name; wgHost.publicName = $machine.fqdn; insert(wgHost) end rule "Set public name of WgHost" when $host : WgHost(publicName == null) $m : Machine(name == $host.name, fqdn != null) then modify($host) { publicName = $m.fqdn } end rule "Make DNS entries for all VPN hosts" when $h : WgHost() $net : WgNet(name == $h.net) then var fqdn = "%s.%s".formatted($h.name, $net.domain); insert(DnsEntry.a(fqdn)) end rule "Connect VPN nodes" salience -1 when $h : WgHost() $others : ArrayList() from collect(WgHost(publicName != null, name != $h.name)) then System.out.printf("Connection from %s%n", $h.name); for (WgHost host : $others) { System.out.printf(" %s%n", host.name); } end