Commit 9c6efad5 authored by Sunil Mohan Adapa's avatar Sunil Mohan Adapa Committed by Joseph Nuthalapati

letsencrypt: Implement re-obtain separately

Signed-off-by: Sunil Mohan Adapa's avatarSunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati's avatarJoseph Nuthalapati <njoseph@thoughtworks.com>
parent 8cae72c4
......@@ -119,10 +119,21 @@ def diagnose():
def certificate_obtain(domain):
"""Obtain a certificate for a domain and notify handlers."""
actions.superuser_run('letsencrypt', ['obtain', '--domain', domain])
components.on_certificate_event('obtained', [domain], None)
# Don't trigger an obtained event. Obtaining a certificate freshly also
# leads to a renewal (deploy) event from Let's Encrypt. There is no easy
# way to distinguish if the event is an initial event or a renewal event.
def certificate_reobtain(domain):
"""Re-obtain a certificate for a domain and notify handlers.
Don't trigger an obtained event. Re-obtaining a certificate also leads to a
renewal (deploy) event from Let's Encrypt. Further, this event is not sent
when obtaining the certificate for the first time. There is no easy way to
distinguish if a renewal event is trigger because of obtain or because of
re-obtain. Hence, handle re-obtain differently from obtain and don't
trigger obtain event (LE will trigger a renewal event).
"""
actions.superuser_run('letsencrypt', ['obtain', '--domain', domain])
def certificate_revoke(domain):
......
......@@ -94,7 +94,7 @@
<td>
{% if domain_status.certificate_available %}
<form class="form form-inline" method="post"
action="{% url 'letsencrypt:obtain' domain %}">
action="{% url 'letsencrypt:re-obtain' domain %}">
{% csrf_token %}
<button class="btn btn-sm btn-default" type="submit">
{% trans "Re-obtain" %}</button>
......
......@@ -24,10 +24,12 @@ from . import views
urlpatterns = [
url(r'^sys/letsencrypt/$', views.index, name='index'),
url(r'^sys/letsencrypt/revoke/(?P<domain>[^/]+)/$', views.revoke,
name='revoke'),
url(r'^sys/letsencrypt/obtain/(?P<domain>[^/]+)/$', views.obtain,
name='obtain'),
url(r'^sys/letsencrypt/re-obtain/(?P<domain>[^/]+)/$', views.reobtain,
name='re-obtain'),
url(r'^sys/letsencrypt/revoke/(?P<domain>[^/]+)/$', views.revoke,
name='revoke'),
url(r'^sys/letsencrypt/delete/(?P<domain>[^/]+)/$', views.delete,
name='delete'),
]
......@@ -82,6 +82,23 @@ def obtain(request, domain):
return redirect(reverse_lazy('letsencrypt:index'))
@require_POST
def reobtain(request, domain):
"""Re-obtain a certificate for a given domain."""
try:
letsencrypt.certificate_reobtain(domain)
messages.success(
request,
_('Certificate successfully obtained for domain {domain}').format(
domain=domain))
except ActionError as exception:
messages.error(
request,
_('Failed to obtain certificate for domain {domain}: {error}').
format(domain=domain, error=exception.args[2]))
return redirect(reverse_lazy('letsencrypt:index'))
@require_POST
def delete(request, domain):
"""Delete a certificate for a given domain, and cleanup renewal config."""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment