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}(?