From fb14c7d804465ba62311e1c947337e5f99ba3caa Mon Sep 17 00:00:00 2001 From: Arian Nasr Date: Sun, 15 Mar 2026 12:25:51 -0400 Subject: [PATCH] framework --- Dockerfile | 8 ++++++++ certman.py | 20 ++++++++++++++++++++ requirements.txt | 3 ++- schemas.py | 6 ++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 schemas.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ef0680d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,8 @@ +FROM python:latest + +WORKDIR /app +COPY . /app +RUN pip install --no-cache-dir -r requirements.txt + +ENTRYPOINT ["python", "certman.py"] +CMD ["--help"] \ No newline at end of file diff --git a/certman.py b/certman.py index e69de29..6d7019e 100644 --- a/certman.py +++ b/certman.py @@ -0,0 +1,20 @@ +from schemas import DomainRequest +import subprocess + +def request_certificate(domain_request: DomainRequest): + domain = domain_request.domain + credentials_file = domain_request.credentials_file + email = domain_request.email + certbot_command = [ + 'certbot', 'certonly', + '--dns-cloudflare', + '--dns-cloudflare-credentials', credentials_file, + '--email', email, + '--agree-tos', + '--non-interactive', + '-d', domain, + ] + result = subprocess.run(certbot_command, capture_output=True, text=True) + if result.returncode != 0: + raise RuntimeError(f'Certbot returned non-zero exit code:\n{result.stderr}') + return result.stdout \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index fe30be5..9c9919f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ certbot==5.4.0 -certbot-dns-cloudflare==5.4.0 \ No newline at end of file +certbot-dns-cloudflare==5.4.0 +pydantic==2.12.5 \ No newline at end of file diff --git a/schemas.py b/schemas.py new file mode 100644 index 0000000..222dac6 --- /dev/null +++ b/schemas.py @@ -0,0 +1,6 @@ +from pydantic import BaseModel, FilePath, EmailStr + +class DomainRequest(BaseModel): + domain: str + credentials_file: FilePath + email: EmailStr \ No newline at end of file