mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2024-11-08 14:40:27 +00:00
Using domain model and added authentication
This commit is contained in:
parent
4958423cc7
commit
b3271e84d6
@ -171,11 +171,3 @@ class UserDeleteFail(StructuredException):
|
||||
StructuredException.__init__(self)
|
||||
self.message = message
|
||||
self.name = name
|
||||
|
||||
class HealthCheckFail(StructuredException):
|
||||
status_code = 500
|
||||
|
||||
def __init__(self,name=None, message="Health check failed"):
|
||||
StructuredException.__init__(self)
|
||||
self.message = message
|
||||
self.name = name
|
@ -23,7 +23,7 @@ from ..lib.errors import (
|
||||
AccountCreateFail, AccountUpdateFail, AccountDeleteFail,
|
||||
AccountCreateDuplicate, AccountNotExists,
|
||||
UserCreateFail, UserCreateDuplicate, UserUpdateFail, UserDeleteFail,
|
||||
UserUpdateFailEmail, HealthCheckFail
|
||||
UserUpdateFailEmail
|
||||
)
|
||||
from ..decorators import (
|
||||
api_basic_auth, api_can_create_domain, is_json, apikey_auth,
|
||||
@ -1184,35 +1184,19 @@ def sync_domains():
|
||||
return 'Finished synchronization in background', 200
|
||||
|
||||
@api_bp.route('/health', methods=['GET'])
|
||||
@apikey_auth
|
||||
def health():
|
||||
domain = Domain()
|
||||
domain_to_query = domain.query.first()
|
||||
|
||||
if not domain_to_query:
|
||||
current_app.logger.error("No domain found to query a health check")
|
||||
raise (HealthCheckFail)
|
||||
|
||||
pdns_api_url = Setting().get('pdns_api_url')
|
||||
pdns_api_key = Setting().get('pdns_api_key')
|
||||
pdns_version = Setting().get('pdns_version')
|
||||
api_uri_with_prefix = utils.pdns_api_extended_uri(pdns_version)
|
||||
api_uri = '/servers/localhost/zones/{}'.format(domain_to_query.name)
|
||||
headers = {}
|
||||
headers['X-API-Key'] = pdns_api_key
|
||||
return make_response("Down", 503)
|
||||
|
||||
try:
|
||||
resp = utils.fetch_remote(urljoin(pdns_api_url, api_uri_with_prefix + api_uri),
|
||||
method='GET',
|
||||
headers=headers,
|
||||
accept='application/json; q=1',
|
||||
verify=Setting().get('verify_ssl_connections'))
|
||||
|
||||
resp = domain.get_domain_info(domain_to_query.name)
|
||||
except Exception as e:
|
||||
current_app.logger.error("Health Check - Failed to query authoritative server for domain {}".format(domain_to_query.name))
|
||||
return make_response("bad", 503)
|
||||
return make_response("Down", 503)
|
||||
|
||||
if resp.status_code == 200:
|
||||
return make_response("good", 200)
|
||||
else:
|
||||
return make_response("bad", 503)
|
||||
|
||||
return make_response("Up", 200)
|
||||
|
Loading…
Reference in New Issue
Block a user