1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

dnsmadeeasy: Fix HTTP 400 errors when creating a TXT record (#1654)

* dnsmadeeasy: Fix HTTP 400 errors when creating a TXT record

* When creating a record the module fails on monitor API call
* TXT records are surrounded by quotes in the API response

Fixes: #1237

* dnsmadeeasy: Add changelog fragment

* dnsmadeeasy: Fix pylint error

* Update changelogs/fragments/1654-dnsmadeeasy-http-400-fixes.yaml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/net_tools/dnsmadeeasy.py

The dictionary might be empty

Co-authored-by: Felix Fontein <felix@fontein.de>

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
Orosz Dávid 2021-01-25 13:00:13 +01:00 committed by GitHub
parent 73b3ec09e5
commit ebaa17f59f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- dnsmadeeasy - fix HTTP 400 errors when creating a TXT record (https://github.com/ansible-collections/community.general/issues/1237).

View file

@ -467,6 +467,9 @@ class DME2(object):
for result in self.all_records:
if record_type == "MX":
value = record_value.split(" ")[1]
# Note that TXT records are surrounded by quotes in the API response.
elif record_type == "TXT":
value = '"{0}"'.format(record_value)
elif record_type == "SRV":
value = record_value.split(" ")[3]
else:
@ -651,7 +654,9 @@ def main():
record_changed = False
if current_record:
for i in new_record:
if str(current_record[i]) != str(new_record[i]):
# Remove leading and trailing quote character from values because TXT records
# are surrounded by quotes.
if str(current_record[i]).strip('"') != str(new_record[i]):
record_changed = True
new_record['id'] = str(current_record['id'])
@ -673,8 +678,11 @@ def main():
# create record and monitor as the record does not exist
if not current_record:
record = DME.createRecord(DME.prepareRecord(new_record))
if new_monitor.get('monitor') and record_type == "A":
monitor = DME.updateMonitor(record['id'], DME.prepareMonitor(new_monitor))
module.exit_json(changed=True, result=dict(record=record, monitor=monitor))
else:
module.exit_json(changed=True, result=dict(record=record, monitor=current_monitor))
# update the record
updated = False