mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-04-19 02:07:31 +00:00
Added custom header in created_by segment option
This commit is contained in:
parent
b8ab0d3478
commit
ee68b18e27
@ -28,7 +28,8 @@ class Setting(db.Model):
|
|||||||
'allow_user_create_domain': False,
|
'allow_user_create_domain': False,
|
||||||
'allow_user_remove_domain': False,
|
'allow_user_remove_domain': False,
|
||||||
'allow_user_view_history': False,
|
'allow_user_view_history': False,
|
||||||
'delete_sso_accounts': False,
|
'delete_sso_accounts': False,
|
||||||
|
'custom_history_header': '',
|
||||||
'bg_domain_updates': False,
|
'bg_domain_updates': False,
|
||||||
'enable_api_rr_history': True,
|
'enable_api_rr_history': True,
|
||||||
'preserve_history': False,
|
'preserve_history': False,
|
||||||
|
@ -1391,6 +1391,7 @@ def setting_basic():
|
|||||||
'default_domain_table_size',
|
'default_domain_table_size',
|
||||||
'default_record_table_size',
|
'default_record_table_size',
|
||||||
'delete_sso_accounts',
|
'delete_sso_accounts',
|
||||||
|
'custom_history_header',
|
||||||
'deny_domain_override',
|
'deny_domain_override',
|
||||||
'dnssec_admins_only',
|
'dnssec_admins_only',
|
||||||
'enable_api_rr_history',
|
'enable_api_rr_history',
|
||||||
|
@ -48,6 +48,12 @@ user_detailed_schema = UserDetailedSchema()
|
|||||||
account_schema = AccountSchema(many=True)
|
account_schema = AccountSchema(many=True)
|
||||||
account_single_schema = AccountSchema()
|
account_single_schema = AccountSchema()
|
||||||
|
|
||||||
|
def is_custom_header_api():
|
||||||
|
custom_header_setting = Setting().get('custom_history_header')
|
||||||
|
if custom_header_setting != '' and custom_header_setting in request.headers:
|
||||||
|
return request.headers[custom_header_setting]
|
||||||
|
else:
|
||||||
|
return g.apikey.description
|
||||||
|
|
||||||
def get_user_domains():
|
def get_user_domains():
|
||||||
domains = db.session.query(Domain) \
|
domains = db.session.query(Domain) \
|
||||||
@ -1104,6 +1110,7 @@ def api_zone_forward(server_id, zone_id):
|
|||||||
domain = Domain()
|
domain = Domain()
|
||||||
domain.update()
|
domain.update()
|
||||||
status = resp.status_code
|
status = resp.status_code
|
||||||
|
created_by_value=is_custom_header_api()
|
||||||
if 200 <= status < 300:
|
if 200 <= status < 300:
|
||||||
current_app.logger.debug("Request to powerdns API successful")
|
current_app.logger.debug("Request to powerdns API successful")
|
||||||
if Setting().get('enable_api_rr_history'):
|
if Setting().get('enable_api_rr_history'):
|
||||||
@ -1116,19 +1123,19 @@ def api_zone_forward(server_id, zone_id):
|
|||||||
'add_rrsets': list(filter(lambda r: r['changetype'] == "REPLACE", data['rrsets'])),
|
'add_rrsets': list(filter(lambda r: r['changetype'] == "REPLACE", data['rrsets'])),
|
||||||
'del_rrsets': list(filter(lambda r: r['changetype'] == "DELETE", data['rrsets']))
|
'del_rrsets': list(filter(lambda r: r['changetype'] == "DELETE", data['rrsets']))
|
||||||
}),
|
}),
|
||||||
created_by=g.apikey.description,
|
created_by=created_by_value,
|
||||||
domain_id=Domain().get_id_by_name(zone_id.rstrip('.')))
|
domain_id=Domain().get_id_by_name(zone_id.rstrip('.')))
|
||||||
history.add()
|
history.add()
|
||||||
elif request.method == 'DELETE':
|
elif request.method == 'DELETE':
|
||||||
history = History(msg='Deleted zone {0}'.format(zone_id.rstrip('.')),
|
history = History(msg='Deleted zone {0}'.format(zone_id.rstrip('.')),
|
||||||
detail='',
|
detail='',
|
||||||
created_by=g.apikey.description,
|
created_by=created_by_value,
|
||||||
domain_id=Domain().get_id_by_name(zone_id.rstrip('.')))
|
domain_id=Domain().get_id_by_name(zone_id.rstrip('.')))
|
||||||
history.add()
|
history.add()
|
||||||
elif request.method != 'GET':
|
elif request.method != 'GET':
|
||||||
history = History(msg='Updated zone {0}'.format(zone_id.rstrip('.')),
|
history = History(msg='Updated zone {0}'.format(zone_id.rstrip('.')),
|
||||||
detail='',
|
detail='',
|
||||||
created_by=g.apikey.description,
|
created_by=created_by_value,
|
||||||
domain_id=Domain().get_id_by_name(zone_id.rstrip('.')))
|
domain_id=Domain().get_id_by_name(zone_id.rstrip('.')))
|
||||||
history.add()
|
history.add()
|
||||||
return resp.content, resp.status_code, resp.headers.items()
|
return resp.content, resp.status_code, resp.headers.items()
|
||||||
@ -1152,6 +1159,7 @@ def api_create_zone(server_id):
|
|||||||
|
|
||||||
if resp.status_code == 201:
|
if resp.status_code == 201:
|
||||||
current_app.logger.debug("Request to powerdns API successful")
|
current_app.logger.debug("Request to powerdns API successful")
|
||||||
|
created_by_value=is_custom_header_api()
|
||||||
data = request.get_json(force=True)
|
data = request.get_json(force=True)
|
||||||
|
|
||||||
if g.apikey.role.name not in ['Administrator', 'Operator']:
|
if g.apikey.role.name not in ['Administrator', 'Operator']:
|
||||||
@ -1166,7 +1174,7 @@ def api_create_zone(server_id):
|
|||||||
history = History(msg='Add domain {0}'.format(
|
history = History(msg='Add domain {0}'.format(
|
||||||
data['name'].rstrip('.')),
|
data['name'].rstrip('.')),
|
||||||
detail=json.dumps(data),
|
detail=json.dumps(data),
|
||||||
created_by=g.apikey.description,
|
created_by=created_by_value,
|
||||||
domain_id=domain.get_id_by_name(data['name'].rstrip('.')))
|
domain_id=domain.get_id_by_name(data['name'].rstrip('.')))
|
||||||
history.add()
|
history.add()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user