From 03cf26bbbefbbad82743f29c6c5a2aac070b4990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Caletka?= Date: Mon, 20 Aug 2018 13:07:52 +0200 Subject: [PATCH] Add allowfancynames option --- README.rst | 4 ++++ dzonegit.py | 6 +++--- test_dzonegit.py | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 5bc8ce7..a347eae 100644 --- a/README.rst +++ b/README.rst @@ -63,6 +63,10 @@ named ``dzonegit``. All boolean options default to *False*. *dzonegit.ignorewhitespaceerrors* Ignore white space errors in ``pre-commit`` and ``pre-receive``/``update`` hooks. +*dzonegit.allowfancynames* + In ``pre-commit`` and ``pre-receive``/``update`` hooks, do not enforce zone + file name to be similar to the name of the zone. + *dzonegit.noserialupdate* Do not try to automatically update zone serial number if necessary. Valid only in the ``pre-commit`` hook. diff --git a/dzonegit.py b/dzonegit.py index 88c7068..018b3d0 100644 --- a/dzonegit.py +++ b/dzonegit.py @@ -173,15 +173,15 @@ def get_zone_origin(zonedata): def get_zone_name(path, zonedata): """ Try to guess zone name from either filename or the first $ORIGIN. - Throw a HookException if filename and zone ORIGIN differ more than - in slashes. + Unless disabled, throw a HookException if filename and zone ORIGIN differ + more than in slashes. """ stemname = Path(path).stem.lower() originname = get_zone_origin(zonedata) if originname: tt = str.maketrans("", "", "/_,:-+*%^&#$") sn, on = [s.translate(tt) for s in [stemname, originname]] - if sn != on: + if sn != on and not get_config("dzonegit.allowfancynames", bool): raise HookException( "Zone origin {o} differs from zone file.".format(o=originname), fname=path, diff --git a/test_dzonegit.py b/test_dzonegit.py index 20a94b8..8d399fa 100644 --- a/test_dzonegit.py +++ b/test_dzonegit.py @@ -131,6 +131,8 @@ ns.example.com. 60 IN A 192.0.2.1 ) with pytest.raises(ValueError): dzonegit.get_zone_name("zones/example.org.zone", testzone) + subprocess.call(["git", "config", "dzonegit.allowfancynames", "TRUE"]) + dzonegit.get_zone_name("zones/example.org.zone", testzone) testzone = b""" $ORIGIN 240/28.2.0.192.in-addr.arpa. @ 60 IN SOA ns hostmaster 1 60 60 60 60