From 6db805d507f93cff571bca9eb78c35661f42df9a Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 11 May 2020 18:42:57 +0200 Subject: [PATCH] add a workaround to prevent CNAME creation if a record with the same name already exists --- CHANGELOG.md | 1 + corenetworks/client.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d71715..9823700 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,3 +2,4 @@ * make `ttl` mandatory for add function * BUGFIX * update (delete + create) records with different `ttl` to prevent duplicate entries + * add a workaround to prevent CNAME creation if a record with the same name already exists diff --git a/corenetworks/client.py b/corenetworks/client.py index 63eace0..d21db8c 100644 --- a/corenetworks/client.py +++ b/corenetworks/client.py @@ -205,10 +205,23 @@ class CoreNetworks(): schema["required"] = ["name", "type", "data", "ttl"] self.__validate(params, schema) + if params["type"] == "CNAME": + if params["name"] == "@": + raise CorenetworksError("CNAME records are not allowed for the zone itself.") + + records = self.records(zone, params={"name": params["name"]}) + for r in records: + raise CorenetworksError( + "A record with the same name already exist ({name}). " + "CNAME records cannot use the same name with other records.".format( + name=r["name"] + ) + ) + curr = copy.deepcopy(params) curr.pop("ttl") - records = self.records(zone, curr) + if len(records) > 1: raise CorenetworksError( "More than one record already exists for the given attributes. "