fix(nixos): validate route protocol fields
This commit is contained in:
@@ -1,49 +1,4 @@
|
|||||||
{ lib, util, ... }:
|
{ lib, util, ... }:
|
||||||
let
|
|
||||||
# NOLINT(let_order)
|
|
||||||
routeType =
|
|
||||||
protocols: options:
|
|
||||||
lib.types.submodule {
|
|
||||||
options = {
|
|
||||||
domain = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
example = "files.alexion.dev";
|
|
||||||
description = "Public domain for this route.";
|
|
||||||
};
|
|
||||||
|
|
||||||
protocol = lib.mkOption {
|
|
||||||
type = lib.types.enum protocols;
|
|
||||||
description = "Public protocol for this route.";
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// options;
|
|
||||||
};
|
|
||||||
|
|
||||||
webRoute =
|
|
||||||
routeType
|
|
||||||
[
|
|
||||||
"http"
|
|
||||||
"https"
|
|
||||||
]
|
|
||||||
{
|
|
||||||
port = lib.mkOption {
|
|
||||||
type = lib.types.port;
|
|
||||||
example = 3923;
|
|
||||||
description = "HTTP backend port for this route.";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
udpRoute = routeType [ "udp" ] {
|
|
||||||
ports = lib.mkOption {
|
|
||||||
type = lib.types.nonEmptyListOf lib.types.port;
|
|
||||||
example = [
|
|
||||||
2456
|
|
||||||
2457
|
|
||||||
];
|
|
||||||
description = "UDP ports for this route.";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
checks = [
|
checks = [
|
||||||
{
|
{
|
||||||
@@ -54,16 +9,69 @@ in
|
|||||||
assertion =
|
assertion =
|
||||||
entries:
|
entries:
|
||||||
util.registry.predicates.uniqueValue (entry: entry.value) (
|
util.registry.predicates.uniqueValue (entry: entry.value) (
|
||||||
lib.concatMap (entry: map (port: entry // { value = port; }) entry.value.ports) (
|
lib.concatMap (entry: map (port: entry // { value = port; }) entry.value.ports) entries
|
||||||
lib.filter (entry: entry.value.protocol == "udp") entries
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
message = "Route UDP ports must be unique.";
|
message = "Route UDP ports must be unique.";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
assertion =
|
||||||
|
entries:
|
||||||
|
lib.all (
|
||||||
|
entry:
|
||||||
|
let
|
||||||
|
route = entry.value;
|
||||||
|
in
|
||||||
|
!lib.elem route.protocol [
|
||||||
|
"http"
|
||||||
|
"https"
|
||||||
|
]
|
||||||
|
|| (route.port != null && route.ports == [ ])
|
||||||
|
) entries;
|
||||||
|
message = "HTTP and HTTPS routes must set port and not ports.";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assertion =
|
||||||
|
entries:
|
||||||
|
lib.all (
|
||||||
|
entry: entry.value.protocol != "udp" || (entry.value.port == null && entry.value.ports != [ ])
|
||||||
|
) entries;
|
||||||
|
message = "UDP routes must set ports and not port.";
|
||||||
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
type = lib.types.oneOf [
|
type = lib.types.submodule {
|
||||||
webRoute
|
options = {
|
||||||
udpRoute
|
domain = lib.mkOption {
|
||||||
];
|
type = lib.types.str;
|
||||||
|
example = "files.alexion.dev";
|
||||||
|
description = "Public domain for this route.";
|
||||||
|
};
|
||||||
|
|
||||||
|
protocol = lib.mkOption {
|
||||||
|
type = lib.types.enum [
|
||||||
|
"http"
|
||||||
|
"https"
|
||||||
|
"udp"
|
||||||
|
];
|
||||||
|
description = "Public protocol for this route.";
|
||||||
|
};
|
||||||
|
|
||||||
|
port = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.port;
|
||||||
|
default = null;
|
||||||
|
example = 3923;
|
||||||
|
description = "HTTP backend port for an HTTP or HTTPS route.";
|
||||||
|
};
|
||||||
|
|
||||||
|
ports = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.port;
|
||||||
|
default = [ ];
|
||||||
|
example = [
|
||||||
|
2456
|
||||||
|
2457
|
||||||
|
];
|
||||||
|
description = "UDP ports for a UDP route.";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user