summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-04 21:33:29 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-04 21:33:29 +0100
commita7de9a63f77faac8c535d1ab340bb5046f3955fd (patch)
tree780d42e58a353594310feebef45926d136c9e4da /src
parent4dcc43061d05f14ceddbb9f3a0c43ab908b89a4b (diff)
downloadrules-sandbox-a7de9a63f77faac8c535d1ab340bb5046f3955fd.tar.gz
rules-sandbox-a7de9a63f77faac8c535d1ab340bb5046f3955fd.tar.bz2
rules-sandbox-a7de9a63f77faac8c535d1ab340bb5046f3955fd.tar.xz
rules-sandbox-a7de9a63f77faac8c535d1ab340bb5046f3955fd.zip
VPN work.
Finding all connections for a VPN host.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/io/trygvis/rules/acme/AcmeIo.java5
-rw-r--r--src/main/resources/io/trygvis/rules/acme/vpn.drl23
2 files changed, 24 insertions, 4 deletions
diff --git a/src/main/java/io/trygvis/rules/acme/AcmeIo.java b/src/main/java/io/trygvis/rules/acme/AcmeIo.java
index 0bd0f1e..498a4a6 100644
--- a/src/main/java/io/trygvis/rules/acme/AcmeIo.java
+++ b/src/main/java/io/trygvis/rules/acme/AcmeIo.java
@@ -57,6 +57,7 @@ public class AcmeIo {
dump(s, factHandles, (o) -> true);
}
+ // This should just sort by all getters instead.
static class FactCollection<T> {
public final Class<T> type;
public final List<T> values;
@@ -74,6 +75,10 @@ public class AcmeIo {
}
if (comparator == null) {
+ comparator = comparable(type, "fqdn");
+ }
+
+ if (comparator == null) {
comparator = Comparator.comparingInt(System::identityHashCode);
}
diff --git a/src/main/resources/io/trygvis/rules/acme/vpn.drl b/src/main/resources/io/trygvis/rules/acme/vpn.drl
index cfdbef9..082ecc0 100644
--- a/src/main/resources/io/trygvis/rules/acme/vpn.drl
+++ b/src/main/resources/io/trygvis/rules/acme/vpn.drl
@@ -1,8 +1,10 @@
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.AcmeServer
+import io.trygvis.rules.acme.WgHost;
dialect "mvel"
@@ -13,7 +15,6 @@ end
declare WgHost
name : String
-// machine : Machine
net : String
publicName : String
netToNetIp : String
@@ -38,8 +39,9 @@ when
$host : WgHost(publicName == null)
$m : Machine(name == $host.name, fqdn != null)
then
- $host.publicName = $m.fqdn;
- update($host)
+ modify($host) {
+ publicName = $m.fqdn
+ }
end
rule "Make DNS entries for all VPN hosts"
@@ -50,3 +52,16 @@ 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