Skip to content

Commit

Permalink
PA-757 - added command to get LE cert for new-style webapp. by: Glenn…
Browse files Browse the repository at this point in the history
…, Filip, Nina
  • Loading branch information
Glenn Jones committed Sep 18, 2024
1 parent efc4667 commit 7572270
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cli/website.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/python3

from pprint import pformat
from typing_extensions import Annotated

import typer
Expand Down Expand Up @@ -114,3 +113,19 @@ def delete(
"""Delete the website at the given domain"""
Website().delete(domain_name=domain_name)
typer.echo(snakesay(f"Website {domain_name} has been deleted!"))


@app.command()
def create_autorenew_cert(
domain_name: Annotated[
str,
typer.Option(
"-d",
"--domain",
help="Domain name, eg. yourusername.pythonanywhere.com or www.mydomain.com",
)
],
):
"""Create and apply an auto-renewing Let's Encrypt certificate for the given domain"""
Website().auto_ssl(domain_name=domain_name)
typer.echo(snakesay(f"Applied auto-renewing SSL certificate for {domain_name}!"))
18 changes: 18 additions & 0 deletions tests/test_cli_website.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,21 @@ def test_delete_with_domain_deletes_it(mocker, mock_echo, mock_website):
mock_snakesay.assert_called_once_with(f"Website www.domain.com has been deleted!")
mock_echo.assert_called_once_with(mock_snakesay.return_value)


def test_create_le_autorenew_cert(mocker, mock_echo, mock_website):
mock_snakesay = mocker.patch("cli.website.snakesay")

result = runner.invoke(
app,
[
"create-autorenew-cert",
"-d",
"www.domain.com",
],
)

assert result.exit_code == 0
mock_website.return_value.auto_ssl.assert_called_once_with(domain_name="www.domain.com")
mock_snakesay.assert_called_once_with(f"Applied auto-renewing SSL certificate for www.domain.com!")
mock_echo.assert_called_once_with(mock_snakesay.return_value)

0 comments on commit 7572270

Please sign in to comment.