refactor(nixos): validate UDP routes in registry
This commit is contained in:
@@ -80,36 +80,12 @@ let
|
|||||||
) registry.route
|
) registry.route
|
||||||
);
|
);
|
||||||
|
|
||||||
udpStreamsByPort = lib.foldl' (
|
generatedStreamConfig = lib.concatMapStringsSep "\n" (stream: ''
|
||||||
acc: stream:
|
server {
|
||||||
acc
|
listen ${toString stream.port} udp;
|
||||||
// {
|
proxy_pass ${stream.address}:${toString stream.port};
|
||||||
${toString stream.port} = (acc.${toString stream.port} or [ ]) ++ [ stream ];
|
|
||||||
}
|
}
|
||||||
) { } generatedUdpStreams;
|
'') generatedUdpStreams;
|
||||||
|
|
||||||
duplicateUdpPortMessages = lib.concatLists (
|
|
||||||
lib.mapAttrsToList (
|
|
||||||
port: streams:
|
|
||||||
if lib.length streams > 1 then
|
|
||||||
[
|
|
||||||
"duplicate UDP route port ${port} in ${lib.concatMapStringsSep " and " (stream: mkRegistryPath "route" stream.host stream.entry) streams}"
|
|
||||||
]
|
|
||||||
else
|
|
||||||
[ ]
|
|
||||||
) udpStreamsByPort
|
|
||||||
);
|
|
||||||
|
|
||||||
generatedStreamConfig =
|
|
||||||
if duplicateUdpPortMessages != [ ] then
|
|
||||||
throw (builtins.head duplicateUdpPortMessages)
|
|
||||||
else
|
|
||||||
lib.concatMapStringsSep "\n" (stream: ''
|
|
||||||
server {
|
|
||||||
listen ${toString stream.port} udp;
|
|
||||||
proxy_pass ${stream.address}:${toString stream.port};
|
|
||||||
}
|
|
||||||
'') generatedUdpStreams;
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.modules.services.reverse-proxy = {
|
options.modules.services.reverse-proxy = {
|
||||||
|
|||||||
@@ -5,6 +5,14 @@
|
|||||||
assertion = lib.registry.predicates.uniqueValue (entry: entry.value.domain);
|
assertion = lib.registry.predicates.uniqueValue (entry: entry.value.domain);
|
||||||
message = "Route domains must be unique.";
|
message = "Route domains must be unique.";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
assertion = entries:
|
||||||
|
let
|
||||||
|
ports = lib.concatMap (entry: entry.value.udp.ports) entries;
|
||||||
|
in
|
||||||
|
builtins.length (lib.unique ports) == builtins.length ports;
|
||||||
|
message = "Route UDP ports must be unique.";
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
type = lib.types.submodule {
|
type = lib.types.submodule {
|
||||||
|
|||||||
Reference in New Issue
Block a user