Remove unnecessary call to str()

* json.dumps() already returns a str
This commit is contained in:
AdvanticGmbH 2022-04-26 09:11:05 +02:00
parent 44c9aff5db
commit 26c60f175d
3 changed files with 50 additions and 62 deletions

View File

@ -362,14 +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({
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()
@ -412,13 +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({
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()
@ -1672,11 +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({
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'))
@ -1720,11 +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({
json.dumps({
'name': name, 'name': name,
'description': description 'description': description
})), }),
created_by=current_user.username) created_by=current_user.username)
history.add() history.add()
@ -1854,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)
@ -1884,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(json.dumps({'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,12 +409,11 @@ 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({
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
})), }),
created_by=current_user.username, created_by=current_user.username,
domain_id=domain_id) domain_id=domain_id)
history.add() history.add()
@ -446,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()
@ -465,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(json.dumps(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'))
@ -618,11 +616,10 @@ 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({
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))
history.add() history.add()
@ -686,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()
@ -700,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

@ -550,13 +550,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({
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
@ -865,14 +864,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({
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()
@ -908,12 +906,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({
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()