From 1802b91f68b4f65b93c310a5c2d13319f912a4c7 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 3 Sep 2014 15:34:31 +0200 Subject: [PATCH] rename methods dealing with client/server "fault" to more general "result" --- nsupdate/api/views.py | 10 +++++----- nsupdate/main/models.py | 10 ++++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/nsupdate/api/views.py b/nsupdate/api/views.py index 21a8158..77c67c7 100644 --- a/nsupdate/api/views.py +++ b/nsupdate/api/views.py @@ -212,12 +212,12 @@ class NicUpdateView(View): result = 'nohost' # or 'badauth'? logger.warning("rejecting to update wrong host %s (given in query string) " "[instead of %s (given in basic auth)]" % (hostname, username)) - host.register_client_fault() + host.register_client_result(fault=True) return Response(result) agent = request.META.get('HTTP_USER_AGENT', 'unknown') if agent in settings.BAD_AGENTS: logger.warning('%s - received update from bad user agent' % (hostname, )) - host.register_client_fault() + host.register_client_result(fault=True) return Response('badagent') ipaddr = request.GET.get('myip') if not ipaddr: # None or '' @@ -352,13 +352,13 @@ def _update(host, ipaddr, secure=False, logger=None): return Response('good %s' % ipaddr) except SameIpError: logger.warning('%s - received no-change update, ip: %s tls: %r' % (fqdn, ipaddr, secure)) - host.register_client_fault() + host.register_client_result(fault=True) return Response('nochg %s' % ipaddr) except (DnsUpdateError, NameServerNotAvailable) as e: msg = str(e) logger.error('%s - received update that resulted in a dns error [%s], ip: %s tls: %r' % ( fqdn, msg, ipaddr, secure)) - host.register_server_fault() + host.register_server_result(fault=True) return Response('dnserr') @@ -402,5 +402,5 @@ def _delete(host, ipaddr, secure=False, logger=None): msg = str(e) logger.error('%s - received delete for record %s that resulted in a dns error [%s], tls: %r' % ( fqdn, rdtype, msg, secure)) - host.register_server_fault() + host.register_server_result(fault=True) return Response('dnserr') diff --git a/nsupdate/main/models.py b/nsupdate/main/models.py index f43b909..c794710 100644 --- a/nsupdate/main/models.py +++ b/nsupdate/main/models.py @@ -224,12 +224,14 @@ class Host(models.Model): self.tls_update_ipv6 = secure self.save() - def register_client_fault(self, increment=1): - self.client_faults += increment + def register_client_result(self, fault=False): + if fault: + self.client_faults += 1 self.save() - def register_server_fault(self, increment=1): - self.server_faults += increment + def register_server_result(self, fault=False): + if fault: + self.server_faults += 1 self.save() def generate_secret(self, secret=None):