Merge pull request #1160 from AdvanticGmbH/json_load_error

Json load error
This commit is contained in:
jbe-dw 2022-04-26 17:54:08 +02:00 committed by GitHub
commit 82f03a4de2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 69 deletions

View File

@ -93,7 +93,7 @@ def extract_changelogs_from_a_history_entry(out_changes, history_entry, change_n
return return
if "add_rrests" in history_entry.detail: if "add_rrests" in history_entry.detail:
detail_dict = json.loads(history_entry.detail.replace("\'", '')) detail_dict = json.loads(history_entry.detail)
else: # not a record entry else: # not a record entry
return return
@ -362,13 +362,13 @@ def edit_key(key_id=None):
current_app.logger.error('Error: {0}'.format(e)) current_app.logger.error('Error: {0}'.format(e))
history = History(msg=history_message, history = History(msg=history_message,
detail=str({ detail = json.dumps({
'key': apikey.id, 'key': apikey.id,
'role': apikey.role.name, 'role': apikey.role.name,
'description': apikey.description, 'description': apikey.description,
'domains': [domain.name for domain in apikey.domains], 'domains': [domain.name for domain in apikey.domains],
'accounts': [a.name for a in apikey.accounts] 'accounts': [a.name for a in apikey.accounts]
}), }),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
@ -411,12 +411,12 @@ def manage_keys():
current_app.logger.info('Delete API key {0}'.format(apikey.id)) current_app.logger.info('Delete API key {0}'.format(apikey.id))
history = History(msg='Delete API key {0}'.format(apikey.id), history = History(msg='Delete API key {0}'.format(apikey.id),
detail=str({ detail = json.dumps({
'key': history_apikey_id, 'key': history_apikey_id,
'role': history_apikey_role, 'role': history_apikey_role,
'description': history_apikey_description, 'description': history_apikey_description,
'domains': history_apikey_domains 'domains': history_apikey_domains
}), }),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
@ -763,10 +763,7 @@ class DetailedHistory():
self.detailed_msg = "" self.detailed_msg = ""
return return
if 'add_rrest' in history.detail: detail_dict = json.loads(history.detail)
detail_dict = json.loads(history.detail.replace("\'", ''))
else:
detail_dict = json.loads(history.detail.replace("'", '"'))
if 'domain_type' in detail_dict and 'account_id' in detail_dict: # this is a domain creation if 'domain_type' in detail_dict and 'account_id' in detail_dict: # this is a domain creation
self.detailed_msg = render_template_string(""" self.detailed_msg = render_template_string("""
@ -883,6 +880,16 @@ class DetailedHistory():
domain_type=DetailedHistory.get_key_val(detail_dict, "domain_type"), domain_type=DetailedHistory.get_key_val(detail_dict, "domain_type"),
domain_master_ips=DetailedHistory.get_key_val(detail_dict, "domain_master_ips")) domain_master_ips=DetailedHistory.get_key_val(detail_dict, "domain_master_ips"))
elif DetailedHistory.get_key_val(detail_dict, 'msg') and DetailedHistory.get_key_val(detail_dict, 'status'):
self.detailed_msg = render_template_string('''
<table class="table table-bordered table-striped">
<tr><td>Status: </td><td>{{ history_status }}</td></tr>
<tr><td>Message:</td><td>{{ history_msg }}</td></tr>
</table>
''',
history_status=DetailedHistory.get_key_val(detail_dict, 'status'),
history_msg=DetailedHistory.get_key_val(detail_dict, 'msg'))
# check for lower key as well for old databases # check for lower key as well for old databases
@staticmethod @staticmethod
def get_key_val(_dict, key): def get_key_val(_dict, key):
@ -1663,10 +1670,10 @@ def create_template():
result = t.create() result = t.create()
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Add domain template {0}'.format(name), history = History(msg='Add domain template {0}'.format(name),
detail=str({ detail = json.dumps({
'name': name, 'name': name,
'description': description 'description': description
}), }),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
return redirect(url_for('admin.templates')) return redirect(url_for('admin.templates'))
@ -1710,10 +1717,10 @@ def create_template_from_zone():
result = t.create() result = t.create()
if result['status'] == 'ok': if result['status'] == 'ok':
history = History(msg='Add domain template {0}'.format(name), history = History(msg='Add domain template {0}'.format(name),
detail=str({ detail = json.dumps({
'name': name, 'name': name,
'description': description 'description': description
}), }),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
@ -1843,7 +1850,7 @@ def apply_records(template):
history = History( history = History(
msg='Apply domain template record changes to domain template {0}' msg='Apply domain template record changes to domain template {0}'
.format(template), .format(template),
detail=str(json.dumps(jdata)), detail = json.dumps(jdata),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
return make_response(jsonify(result), 200) return make_response(jsonify(result), 200)
@ -1873,7 +1880,7 @@ def delete_template(template):
if result['status'] == 'ok': if result['status'] == 'ok':
history = History( history = History(
msg='Deleted domain template {0}'.format(template), msg='Deleted domain template {0}'.format(template),
detail=str({'name': template}), detail = json.dumps({'name': template}),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
return redirect(url_for('admin.templates')) return redirect(url_for('admin.templates'))

View File

@ -409,7 +409,7 @@ def add():
domain_id = Domain().get_id_by_name(domain_name) domain_id = Domain().get_id_by_name(domain_name)
history = History(msg='Add domain {0}'.format( history = History(msg='Add domain {0}'.format(
pretty_domain_name(domain_name)), pretty_domain_name(domain_name)),
detail=str({ detail = json.dumps({
'domain_type': domain_type, 'domain_type': domain_type,
'domain_master_ips': domain_master_ips, 'domain_master_ips': domain_master_ips,
'account_id': account_id 'account_id': account_id
@ -445,17 +445,16 @@ def add():
history = History( history = History(
msg='Applying template {0} to {1} successfully.'. msg='Applying template {0} to {1} successfully.'.
format(template.name, domain_name), format(template.name, domain_name),
detail=str( detail = json.dumps({
json.dumps({ 'domain':
"domain":
domain_name, domain_name,
"template": 'template':
template.name, template.name,
"add_rrests": 'add_rrests':
result['data'][0]['rrsets'], result['data'][0]['rrsets'],
"del_rrests": 'del_rrests':
result['data'][1]['rrsets'] result['data'][1]['rrsets']
})), }),
created_by=current_user.username, created_by=current_user.username,
domain_id=domain_id) domain_id=domain_id)
history.add() history.add()
@ -464,7 +463,7 @@ def add():
msg= msg=
'Failed to apply template {0} to {1}.' 'Failed to apply template {0} to {1}.'
.format(template.name, domain_name), .format(template.name, domain_name),
detail=str(result), detail = json.dumps(result),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
return redirect(url_for('dashboard.dashboard')) return redirect(url_for('dashboard.dashboard'))
@ -617,9 +616,9 @@ def change_soa_edit_api(domain_name):
history = History( history = History(
msg='Update soa_edit_api for domain {0}'.format( msg='Update soa_edit_api for domain {0}'.format(
pretty_domain_name(domain_name)), pretty_domain_name(domain_name)),
detail=str({ detail = json.dumps({
"domain": domain_name, 'domain': domain_name,
"soa_edit_api": new_setting 'soa_edit_api': new_setting
}), }),
created_by=current_user.username, created_by=current_user.username,
domain_id=d.get_id_by_name(domain_name)) domain_id=d.get_id_by_name(domain_name))
@ -684,12 +683,11 @@ def record_apply(domain_name):
if result['status'] == 'ok': if result['status'] == 'ok':
history = History( history = History(
msg='Apply record changes to domain {0}'.format(pretty_domain_name(domain_name)), msg='Apply record changes to domain {0}'.format(pretty_domain_name(domain_name)),
detail=str( detail = json.dumps({
json.dumps({ 'domain': domain_name,
"domain": domain_name, 'add_rrests': result['data'][0]['rrsets'],
"add_rrests": result['data'][0]['rrsets'], 'del_rrests': result['data'][1]['rrsets']
"del_rrests": result['data'][1]['rrsets'] }),
})),
created_by=current_user.username, created_by=current_user.username,
domain_id=domain.id) domain_id=domain.id)
history.add() history.add()
@ -698,11 +696,10 @@ def record_apply(domain_name):
history = History( history = History(
msg='Failed to apply record changes to domain {0}'.format( msg='Failed to apply record changes to domain {0}'.format(
pretty_domain_name(domain_name)), pretty_domain_name(domain_name)),
detail=str( detail = json.dumps({
json.dumps({ 'domain': domain_name,
"domain": domain_name, 'msg': result['msg'],
"msg": result['msg'], }),
})),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
return make_response(jsonify(result), 400) return make_response(jsonify(result), 400)

View File

@ -549,12 +549,12 @@ def signin_history(username, authenticator, success):
# Write history # Write history
History(msg='User {} authentication {}'.format(username, str_success), History(msg='User {} authentication {}'.format(username, str_success),
detail=str({ detail = json.dumps({
"username": username, 'username': username,
"authenticator": authenticator, 'authenticator': authenticator,
"ip_address": request_ip, 'ip_address': request_ip,
"success": 1 if success else 0 'success': 1 if success else 0
}), }),
created_by='System').add() created_by='System').add()
# Get a list of Azure security groups the user is a member of # Get a list of Azure security groups the user is a member of
@ -863,13 +863,13 @@ def dyndns_update():
if result['status'] == 'ok': if result['status'] == 'ok':
history = History( history = History(
msg='DynDNS update: updated {} successfully'.format(hostname), msg='DynDNS update: updated {} successfully'.format(hostname),
detail=str({ detail = json.dumps({
"domain": domain.name, 'domain': domain.name,
"record": hostname, 'record': hostname,
"type": rtype, 'type': rtype,
"old_value": oldip, 'old_value': oldip,
"new_value": str(ip) 'new_value': str(ip)
}), }),
created_by=current_user.username, created_by=current_user.username,
domain_id=domain.id) domain_id=domain.id)
history.add() history.add()
@ -905,11 +905,11 @@ def dyndns_update():
msg= msg=
'DynDNS update: created record {0} in zone {1} successfully' 'DynDNS update: created record {0} in zone {1} successfully'
.format(hostname, domain.name, str(ip)), .format(hostname, domain.name, str(ip)),
detail=str({ detail = json.dumps({
"domain": domain.name, 'domain': domain.name,
"record": hostname, 'record': hostname,
"value": str(ip) 'value': str(ip)
}), }),
created_by=current_user.username, created_by=current_user.username,
domain_id=domain.id) domain_id=domain.id)
history.add() history.add()