0
0
mirror of https://github.com/thegeeklab/corenetworks.git synced 2024-09-21 06:32:44 +02:00

update records with different ttl to prevent duplicate entries

This commit is contained in:
Robert Kaussow 2020-05-11 18:04:08 +02:00
parent fa581cd48d
commit 0edfc084d7
2 changed files with 28 additions and 5 deletions

View File

@ -1,2 +1,4 @@
* ENHANCEMENT
* make `ttl` mandatory for add function
* BUGFIX * BUGFIX
* fix passed variable basic auth to fix broken env variables * update (delete + create) records with different `ttl` to prevent duplicate entries

View File

@ -202,9 +202,25 @@ class CoreNetworks():
""" """
schema = copy.deepcopy(self._schema) schema = copy.deepcopy(self._schema)
schema["required"] = ["name", "type", "data"] schema["required"] = ["name", "type", "data", "ttl"]
self.__validate(params, schema) self.__validate(params, schema)
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. "
"That should be impossible, please open an issue!"
)
# delete existing record with different ttl for a fake update
for r in records:
r["ttl"] = int(r["ttl"])
if r["ttl"] != params["ttl"]:
self._delete_record_raw(zone, params=r)
self.__rest_helper( self.__rest_helper(
"/dnszones/{zone}/records/".format(zone=zone), data=params, method="POST" "/dnszones/{zone}/records/".format(zone=zone), data=params, method="POST"
) )
@ -216,6 +232,13 @@ class CoreNetworks():
return self.__normalize(result) return self.__normalize(result)
def _delete_record_raw(self, zone, params):
r = self.__rest_helper(
"/dnszones/{zone}/records/delete".format(zone=zone), data=params, method="POST"
)
return r
def delete_record(self, zone, params): def delete_record(self, zone, params):
""" """
Delete all DNS records of a zone that match the data. Delete all DNS records of a zone that match the data.
@ -245,9 +268,7 @@ class CoreNetworks():
if params.get("force_all"): if params.get("force_all"):
params = {} params = {}
result = self.__rest_helper( result = self._delete_record_raw(zone, params)
"/dnszones/{zone}/records/delete".format(zone=zone), data=params, method="POST"
)
if self.config["auto_commit"]: if self.config["auto_commit"]:
self.commit(zone=zone) self.commit(zone=zone)