From 676695eacf75aa01920b89bb1809ee96e47d20bb Mon Sep 17 00:00:00 2001 From: Jeff Dyke Date: Wed, 22 Apr 2026 19:30:24 -0400 Subject: [PATCH] Merge pull request #701 from jeffdyke/feature/certs-with-cert-name Support --cert-name being passed to certbot certificates --- jc/parsers/certbot.py | 2 +- .../generic/certbot-certs-cert-name.json | 1 + .../fixtures/generic/certbot-certs-cert-name.out | 12 ++++++++++++ tests/fixtures/generic/certbot-certs.json | 2 +- tests/test_certbot.py | 16 ++++++++++++++-- 5 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tests/fixtures/generic/certbot-certs-cert-name.json create mode 100644 tests/fixtures/generic/certbot-certs-cert-name.out diff --git a/jc/parsers/certbot.py b/jc/parsers/certbot.py index 99ae223c..7a9de2ce 100644 --- a/jc/parsers/certbot.py +++ b/jc/parsers/certbot.py @@ -201,7 +201,7 @@ def parse( if jc.utils.has_data(data): - cert_pattern = re.compile(r'^Found the following certs:\r?$', re.MULTILINE) + cert_pattern = re.compile(r'^Found the following (matching )?certs:\r?$', re.MULTILINE) if re.search(cert_pattern, data): cmd_option = 'certificates' diff --git a/tests/fixtures/generic/certbot-certs-cert-name.json b/tests/fixtures/generic/certbot-certs-cert-name.json new file mode 100644 index 00000000..4d9ec3a5 --- /dev/null +++ b/tests/fixtures/generic/certbot-certs-cert-name.json @@ -0,0 +1 @@ +{"certificates":[{"name":"example.com","serial_number":"3f7axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","key_type":"RSA","domains":["example.com","www.example.com"],"expiration_date":"2023-05-11 01:33:10+00:00","validity":"63 days","certificate_path":"/etc/letsencrypt/live/example.com/fullchain.pem","private_key_path":"/etc/letsencrypt/live/example.com/privkey.pem","expiration_date_epoch":1683783190,"expiration_date_epoch_utc":1776781855,"expiration_date_iso":"2026-04-21T07:30:55-0700"}]} diff --git a/tests/fixtures/generic/certbot-certs-cert-name.out b/tests/fixtures/generic/certbot-certs-cert-name.out new file mode 100644 index 00000000..ac30e259 --- /dev/null +++ b/tests/fixtures/generic/certbot-certs-cert-name.out @@ -0,0 +1,12 @@ +Saving debug log to /var/log/letsencrypt/letsencrypt.log + +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Found the following matching certs: + Certificate Name: example.com + Serial Number: 3f7axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + Key Type: RSA + Domains: example.com www.example.com + Expiry Date: 2023-05-11 01:33:10+00:00 (VALID: 63 days) + Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem + Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/tests/fixtures/generic/certbot-certs.json b/tests/fixtures/generic/certbot-certs.json index cec83684..7a8696e8 100644 --- a/tests/fixtures/generic/certbot-certs.json +++ b/tests/fixtures/generic/certbot-certs.json @@ -1 +1 @@ -{"certificates":[{"name":"example.com","serial_number":"3f7axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","key_type":"RSA","domains":["example.com","www.example.com"],"expiration_date":"2023-05-11 01:33:10+00:00","validity":"63 days","certificate_path":"/etc/letsencrypt/live/example.com/fullchain.pem","private_key_path":"/etc/letsencrypt/live/example.com/privkey.pem","expiration_date_epoch":1683793990,"expiration_date_epoch_utc":1683768790,"expiration_date_iso":"2023-05-11T01:33:10+00:00"},{"name":"example.org","serial_number":"3bcyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy","key_type":"RSA","domains":["example.org","www.example.org"],"expiration_date":"2023-06-12 01:35:30+00:00","validity":"63 days","certificate_path":"/etc/letsencrypt/live/example.org/fullchain.pem","private_key_path":"/etc/letsencrypt/live/example.org/privkey.pem","expiration_date_epoch":1686558930,"expiration_date_epoch_utc":1686533730,"expiration_date_iso":"2023-06-12T01:35:30+00:00"}]} +{"certificates":[{"name":"example.com","serial_number":"3f7axxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","key_type":"RSA","domains":["example.com","www.example.com"],"expiration_date":"2023-05-11 01:33:10+00:00","validity":"63 days","certificate_path":"/etc/letsencrypt/live/example.com/fullchain.pem","private_key_path":"/etc/letsencrypt/live/example.com/privkey.pem","expiration_date_epoch":1683783190,"expiration_date_epoch_utc":1683768790,"expiration_date_iso":"2023-05-11T01:33:10+00:00"},{"name":"example.org","serial_number":"3bcyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy","key_type":"RSA","domains":["example.org","www.example.org"],"expiration_date":"2023-06-12 01:35:30+00:00","validity":"63 days","certificate_path":"/etc/letsencrypt/live/example.org/fullchain.pem","private_key_path":"/etc/letsencrypt/live/example.org/privkey.pem","expiration_date_epoch":1686548130,"expiration_date_epoch_utc":1776781855,"expiration_date_iso":"2026-04-21T07:30:55-0700"}]} diff --git a/tests/test_certbot.py b/tests/test_certbot.py index 27379a73..16d83df6 100644 --- a/tests/test_certbot.py +++ b/tests/test_certbot.py @@ -10,7 +10,7 @@ THIS_DIR = os.path.dirname(os.path.abspath(__file__)) class MyTests(unittest.TestCase): f_in: Dict = {} f_json: Dict = {} - + maxDiff = None @classmethod def setUpClass(cls): fixtures = { @@ -19,7 +19,11 @@ class MyTests(unittest.TestCase): 'fixtures/generic/certbot-account.json'), 'certificates': ( 'fixtures/generic/certbot-certs.out', - 'fixtures/generic/certbot-certs.json') + 'fixtures/generic/certbot-certs.json'), + 'certificates-cert-name': ( + 'fixtures/generic/certbot-certs-cert-name.out', + 'fixtures/generic/certbot-certs-cert-name.json') + } for file, filepaths in fixtures.items(): @@ -45,6 +49,14 @@ class MyTests(unittest.TestCase): self.f_json['certificates'] ) + def test_certbot_certificates_cert_name(self): + """ + Test 'certbot certificates' with cert name + """ + self.assertEqual( + parse(self.f_in['certificates-cert-name'], quiet=True), + self.f_json['certificates-cert-name'] + ) def test_certbot_account(self): """ Test 'certbot account'