Preliminary error handling around key errors when adding a record

This commit is contained in:
Jeffrey Forman 2011-04-24 21:10:25 -04:00
parent a981711c22
commit 5523e79ded
3 changed files with 18 additions and 5 deletions

View File

@ -62,5 +62,9 @@ def add_record(clean_data):
keyring = dns.tsigkeyring.from_text({ key_name : key_data })
dns_update = dns.update.Update(clean_data['rr_domain'], keyring = keyring, keyalgorithm=key_algorithm)
dns_update.replace(str(clean_data['rr_name']), 10, str(clean_data['rr_type']), str(clean_data['rr_data']))
response = dns.query.tcp(dns_update, clean_data['dns_hostname'])
try:
response = dns.query.tcp(dns_update, clean_data['dns_hostname'])
except dns.tsig.PeerBadKey:
return {'errors' : "There was a problem adding your record due to a TSIG key issue. Please resolve that first." }
return response

View File

@ -74,6 +74,12 @@ def add_record_result(request):
if form.is_valid():
cd = form.cleaned_data
response = add_record(cd)
if 'errors' in response:
return render_to_response('bcommon/add_record_result.htm',
{ 'errors' : response['errors'] },
context_instance=RequestContext(request))
else:
return render_to_response('bcommon/add_record_result.htm',
{ 'response' : response },
context_instance=RequestContext(request))

View File

@ -2,11 +2,14 @@
{% block pageheader %}
Result:
{% endblock pageheader %}
{% block body %}
<pre>
{{ response }}
</pre>
{% if not errors %}
Result:
<pre>
{{ response }}
</pre>
{% endif %}
{% endblock body %}