Skip to content

Commit

Permalink
Merge pull request #94 from adferrand/avoild-wilcard-in-lineages
Browse files Browse the repository at this point in the history
Avoild wilcard in lineages
  • Loading branch information
adferrand authored Mar 31, 2020
2 parents 00d3783 + 36e8425 commit f240815
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## master - CURRENT
### Modified
* Ensure a certificate name does not have wildcard characters when migrating from legacy config
(eg. `example.com` for domains `[*.example.com`, `example.com]` instead of `*.example.com`).

## 3.1.4 - 30/03/2020
### Modified
Expand Down
5 changes: 3 additions & 2 deletions src/dnsrobocert/core/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import logging
import os
import re
from typing import Any, Dict, Optional, Set

import coloredlogs
import jsonschema
import pkg_resources
import yaml

from dnsrobocert.core import utils

LOGGER = logging.getLogger(__name__)
coloredlogs.install(logger=LOGGER)

Expand Down Expand Up @@ -96,7 +97,7 @@ def get_lineage(certificate_config: Dict[str, Any]) -> str:
lineage = (
certificate_config.get("name")
if certificate_config.get("name")
else re.sub(r"^\*\.", "", certificate_config.get("domains", [None])[0])
else utils.normalize_lineage(certificate_config.get("domains", [None])[0])
)
if not lineage:
raise ValueError(
Expand Down
4 changes: 3 additions & 1 deletion src/dnsrobocert/core/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import yaml
from lexicon import config, parser

from dnsrobocert.core import utils

LEGACY_CONFIGURATION_PATH = "/etc/letsencrypt/domains.conf"
LOGGER = logging.getLogger(__name__)
coloredlogs.install(logger=LOGGER)
Expand Down Expand Up @@ -257,7 +259,7 @@ def _extract_certificates(envs: Dict[str, str], profile: str) -> List[Dict[str,

if domains:
certificate: Dict[str, Any] = {
"name": domains[0],
"name": utils.normalize_lineage(domains[0]),
"domains": domains,
"profile": profile,
}
Expand Down
7 changes: 6 additions & 1 deletion src/dnsrobocert/core/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hashlib
import logging
import os
import re
import subprocess
import sys
from typing import Any, Dict, List
Expand Down Expand Up @@ -100,7 +101,7 @@ def configure_certbot_workspace(
fix_permissions(certificate_permissions, archive_path)


def digest(path):
def digest(path: str):
if not os.path.exists(path):
return None

Expand All @@ -110,3 +111,7 @@ def digest(path):
md5 = hashlib.md5()
md5.update(config_data)
return md5.digest()


def normalize_lineage(domain: str):
return re.sub(r"^\*\.", "", domain)
10 changes: 10 additions & 0 deletions test/unit_tests/legacy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_legacy_migration(tmp_path, monkeypatch):
f.write(
"""\
test1.sub.example.com test2.sub.example.com autorestart-containers=container1,container2 autocmd-containers=container3:cmd3 arg3,container4:cmd4 arg4a arg4b
*.sub.example.com sub.example.com
"""
)

Expand Down Expand Up @@ -102,6 +103,15 @@ def test_legacy_migration(tmp_path, monkeypatch):
export: true
passphrase: PASSPHRASE
profile: ovh
- deploy_hook: ./deploy.sh
domains:
- '*.sub.example.com'
- sub.example.com
name: sub.example.com
pfx:
export: true
passphrase: PASSPHRASE
profile: ovh
profiles:
- delegated_subdomain: sub.example.com
max_checks: 3
Expand Down

0 comments on commit f240815

Please sign in to comment.