From 9257cb02ee8d98572cdc35c440c3955e7bb29999 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Tue, 22 Jul 2025 18:06:27 +0200 Subject: [PATCH] validator: hostname init --- pkgs/clan-cli/clan_lib/validator/hostname.py | 30 ++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 pkgs/clan-cli/clan_lib/validator/hostname.py diff --git a/pkgs/clan-cli/clan_lib/validator/hostname.py b/pkgs/clan-cli/clan_lib/validator/hostname.py new file mode 100644 index 000000000..ec65641df --- /dev/null +++ b/pkgs/clan-cli/clan_lib/validator/hostname.py @@ -0,0 +1,30 @@ +import re + +from clan_lib.errors import ClanError + + +def hostname(host: str) -> str: + """ + Validates a hostname according to the expected format in NixOS. + + Usage Example + + @dataclass + class Clan: + name: str + + def validate(self) -> None: + from clan_lib.validator.hostname import hostname + try: + hostname(self.name) + except ValueError as e: + raise ClanError(str(e), location="name") + """ + + # TODO: Generate from nix schema + hostname_regex = r"^(?!-)[A-Za-z0-9-]{1,63}(?