Skip to content

Commit 7572270

Browse files
author
Glenn Jones
committed
PA-757 - added command to get LE cert for new-style webapp. by: Glenn, Filip, Nina
1 parent efc4667 commit 7572270

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

cli/website.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/python3
22

3-
from pprint import pformat
43
from typing_extensions import Annotated
54

65
import typer
@@ -114,3 +113,19 @@ def delete(
114113
"""Delete the website at the given domain"""
115114
Website().delete(domain_name=domain_name)
116115
typer.echo(snakesay(f"Website {domain_name} has been deleted!"))
116+
117+
118+
@app.command()
119+
def create_autorenew_cert(
120+
domain_name: Annotated[
121+
str,
122+
typer.Option(
123+
"-d",
124+
"--domain",
125+
help="Domain name, eg. yourusername.pythonanywhere.com or www.mydomain.com",
126+
)
127+
],
128+
):
129+
"""Create and apply an auto-renewing Let's Encrypt certificate for the given domain"""
130+
Website().auto_ssl(domain_name=domain_name)
131+
typer.echo(snakesay(f"Applied auto-renewing SSL certificate for {domain_name}!"))

tests/test_cli_website.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,21 @@ def test_delete_with_domain_deletes_it(mocker, mock_echo, mock_website):
268268
mock_snakesay.assert_called_once_with(f"Website www.domain.com has been deleted!")
269269
mock_echo.assert_called_once_with(mock_snakesay.return_value)
270270

271+
272+
def test_create_le_autorenew_cert(mocker, mock_echo, mock_website):
273+
mock_snakesay = mocker.patch("cli.website.snakesay")
274+
275+
result = runner.invoke(
276+
app,
277+
[
278+
"create-autorenew-cert",
279+
"-d",
280+
"www.domain.com",
281+
],
282+
)
283+
284+
assert result.exit_code == 0
285+
mock_website.return_value.auto_ssl.assert_called_once_with(domain_name="www.domain.com")
286+
mock_snakesay.assert_called_once_with(f"Applied auto-renewing SSL certificate for www.domain.com!")
287+
mock_echo.assert_called_once_with(mock_snakesay.return_value)
288+

0 commit comments

Comments
 (0)