mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-13 10:30:16 +00:00
letsencrypt: Implement re-obtain separately
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
parent
8cae72c441
commit
9c6efad55d
@ -119,10 +119,21 @@ def diagnose():
|
|||||||
def certificate_obtain(domain):
|
def certificate_obtain(domain):
|
||||||
"""Obtain a certificate for a domain and notify handlers."""
|
"""Obtain a certificate for a domain and notify handlers."""
|
||||||
actions.superuser_run('letsencrypt', ['obtain', '--domain', domain])
|
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
|
def certificate_reobtain(domain):
|
||||||
# way to distinguish if the event is an initial event or a renewal event.
|
"""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):
|
def certificate_revoke(domain):
|
||||||
|
|||||||
@ -94,7 +94,7 @@
|
|||||||
<td>
|
<td>
|
||||||
{% if domain_status.certificate_available %}
|
{% if domain_status.certificate_available %}
|
||||||
<form class="form form-inline" method="post"
|
<form class="form form-inline" method="post"
|
||||||
action="{% url 'letsencrypt:obtain' domain %}">
|
action="{% url 'letsencrypt:re-obtain' domain %}">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<button class="btn btn-sm btn-default" type="submit">
|
<button class="btn btn-sm btn-default" type="submit">
|
||||||
{% trans "Re-obtain" %}</button>
|
{% trans "Re-obtain" %}</button>
|
||||||
|
|||||||
@ -24,10 +24,12 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^sys/letsencrypt/$', views.index, name='index'),
|
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,
|
url(r'^sys/letsencrypt/obtain/(?P<domain>[^/]+)/$', views.obtain,
|
||||||
name='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,
|
url(r'^sys/letsencrypt/delete/(?P<domain>[^/]+)/$', views.delete,
|
||||||
name='delete'),
|
name='delete'),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -82,6 +82,23 @@ def obtain(request, domain):
|
|||||||
return redirect(reverse_lazy('letsencrypt:index'))
|
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
|
@require_POST
|
||||||
def delete(request, domain):
|
def delete(request, domain):
|
||||||
"""Delete a certificate for a given domain, and cleanup renewal config."""
|
"""Delete a certificate for a given domain, and cleanup renewal config."""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user