Skip to content

Commit

Permalink
fix: support asterisk and multiple domains
Browse files Browse the repository at this point in the history
  • Loading branch information
KiraLT committed Jan 18, 2022
1 parent d012fe5 commit 9e299e7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/services/aws.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from boto3 import client
import json
from slugify import slugify

from .certbot import Cert

Expand All @@ -13,7 +14,7 @@ def upload_certs_as_secrets(
certs: list[Cert], name: str, secret_names: list[str] = None, description: str = ''
) -> None:
for cert in certs:
name = name.format(domain=cert.domain)
name = name.format(domain=slugify(cert.domain))

create_or_update_secret(
name=name,
Expand Down
18 changes: 11 additions & 7 deletions app/services/certbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,24 @@ def obtain_certbot_certs(
]
certbot.main.main(certbot_args)

return read_certs_from_path(certbot_dir.joinpath("live"), domains)
return read_certs_from_path(certbot_dir.joinpath("live"))


def read_certs_from_path(path: Path, domains: list[str]) -> list[Cert]:
def read_certs_from_path(path: Path) -> list[Cert]:
certs: list[Cert] = []
cert_files = ["fullchain.pem", "chain.pem", "privkey.pem", "cert.pem"]

domains = [
v.name
for v in path.iterdir()
if v.is_dir()
]

for domain in domains:
domain_path = path.joinpath(domain)
if domain.startswith('*.'):
domain = domain[2:]

if not domain_path.is_dir():
raise RuntimeError(
f"Failed to generate cert for {domain}: {domain_path} is not a directory"
)
domain_path = path.joinpath(domain)

cert = Cert(domain=domain, files=[])

Expand Down
32 changes: 31 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ certbot-dns-ovh = "^1.22.0"
certbot-dns-rfc2136 = "^1.22.0"
certbot-dns-sakuracloud = "^1.22.0"
python-dotenv = "^0.19.2"
python-slugify = "^5.0.2"

[tool.poetry.dev-dependencies]
taskipy = "^1.9.0"
Expand Down

0 comments on commit 9e299e7

Please sign in to comment.