diff options
| author | Dennis Fink | 2026-10-25 22:26:40 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-25 22:26:40 +0100 |
| commit | ce802830c37565d325ba2ecc060443550abb1955 (patch) | |
| tree | b2cdf65353b1eb28d2c8d394b0dcd24461c4db6c /webmentions_ssg | |
| parent | a231913ab273f427697f2d27d615b495f6e160bb (diff) | |
| download | webmentions-ssg-ce802830c37565d325ba2ecc060443550abb1955.tar.gz webmentions-ssg-ce802830c37565d325ba2ecc060443550abb1955.zip | |
refactor(core): simplify configuration keys
Remove the WEBMENTIONS_SSG prefix from application-specific
configuration settings and update validators, tasks, and tests to use
the shorter names.
Diffstat (limited to 'webmentions_ssg')
| -rw-r--r-- | webmentions_ssg/config.py | 16 | ||||
| -rw-r--r-- | webmentions_ssg/forms/validators.py | 5 | ||||
| -rw-r--r-- | webmentions_ssg/tasks/consumer.py | 4 | ||||
| -rw-r--r-- | webmentions_ssg/tasks/notifications.py | 2 | ||||
| -rw-r--r-- | webmentions_ssg/tasks/receiver.py | 10 | ||||
| -rw-r--r-- | webmentions_ssg/tasks/scanner.py | 15 | ||||
| -rw-r--r-- | webmentions_ssg/tasks/sender.py | 8 |
7 files changed, 23 insertions, 37 deletions
diff --git a/webmentions_ssg/config.py b/webmentions_ssg/config.py index afe7126..cbdd614 100644 --- a/webmentions_ssg/config.py +++ b/webmentions_ssg/config.py @@ -19,10 +19,10 @@ class DefaultConfig: LOGFILE_BACKUP_COUNT = 10 SQLALCHEMY_DATABASE_URI = "sqlite:///webmentions-ssg.db" - WEBMENTIONS_SSG_SOURCE_DIRECTORY = None - WEBMENTIONS_SSG_SOURCE_BASE_URL = None - WEBMENTIONS_SSG_SCANNER_SCHEDULE = "0 * * * *" - WEBMENTIONS_SSG_NOTIFICATION_EMAIL = None + SOURCE_DIRECTORY = None + BASE_URL = None + SCANNER_SCHEDULE = "0 * * * *" + NOTIFICATION_EMAIL = None MAIL_SERVER = "localhost" MAIL_PORT = 25 @@ -58,8 +58,8 @@ class TestingConfig(DefaultConfig): HUEY_URL = "memory://" - WEBMENTIONS_SSG_ALLOWED_HOSTNAMES = {"dennisfink.me"} + ALLOWED_HOSTNAMES = {"dennisfink.me"} - WEBMENTIONS_SSG_MAX_REDIRECTS = 20 - WEBMENTIONS_SSG_MAX_SOURCE_BYTES = 1_000_000 - WEBMENTIONS_SSG_REQUEST_TIMEOUT = 5.0 + MAX_REDIRECTS = 20 + MAX_SOURCE_BYTES = 1_000_000 + REQUEST_TIMEOUT = 5.0 diff --git a/webmentions_ssg/forms/validators.py b/webmentions_ssg/forms/validators.py index 761dc46..990d91a 100644 --- a/webmentions_ssg/forms/validators.py +++ b/webmentions_ssg/forms/validators.py @@ -83,10 +83,7 @@ class AllowedHostname: :param field: Field containing the URL to validate. :raises ValidationError: If the URL hostname is not configured as allowed. """ - if ( - urlsplit(field.data).hostname - in current_app.config["WEBMENTIONS_SSG_ALLOWED_HOSTNAMES"] - ): + if urlsplit(field.data).hostname in current_app.config["ALLOWED_HOSTNAMES"]: return raise ValidationError(self.message or field.gettext("Invalid input.")) diff --git a/webmentions_ssg/tasks/consumer.py b/webmentions_ssg/tasks/consumer.py index d71f2fa..3ba2638 100644 --- a/webmentions_ssg/tasks/consumer.py +++ b/webmentions_ssg/tasks/consumer.py @@ -21,9 +21,7 @@ def create_consumer() -> Huey: from . import notifications, receiver, scanner, sender # noqa: F401 - schedule = crontab( - *app.config["WEBMENTIONS_SSG_SCANNER_SCHEDULE"].split(), strict=True - ) + schedule = crontab(*app.config["SCANNER_SCHEDULE"].split(), strict=True) HUEY.periodic_task(schedule)(scanner.scan_sources) return HUEY.huey diff --git a/webmentions_ssg/tasks/notifications.py b/webmentions_ssg/tasks/notifications.py index 473216b..04c968a 100644 --- a/webmentions_ssg/tasks/notifications.py +++ b/webmentions_ssg/tasks/notifications.py @@ -16,7 +16,7 @@ from ..models import ReceivedWebmention @huey.task(retries=2, retry_delay=60) def send_webmention_notification(webmention_uuid: uuid.UUID) -> None: """Send an email when a received webmention has been verified.""" - recipient = current_app.config.get("WEBMENTIONS_SSG_NOTIFICATION_EMAIL") + recipient = current_app.config.get("NOTIFICATION_EMAIL") if not recipient: return diff --git a/webmentions_ssg/tasks/receiver.py b/webmentions_ssg/tasks/receiver.py index e99eea3..8c9c05a 100644 --- a/webmentions_ssg/tasks/receiver.py +++ b/webmentions_ssg/tasks/receiver.py @@ -137,11 +137,9 @@ def fetch_source(source_url: str) -> tuple[httpx.Response, bytes]: "Accept": "text/html, application/xhtml+xml;q=0.9, text/plain;q=0.8", "User-Agent": f"{APP_NAME}/{VERSION} ReceivedWebmention", }, - timeout=httpx.Timeout( - current_app.config.get("WEBMENTIONS_SSG_REQUEST_TIMEOUT", 5.0) - ), + timeout=httpx.Timeout(current_app.config.get("REQUEST_TIMEOUT", 5.0)), follow_redirects=True, - max_redirects=current_app.config.get("WEBMENTIONS_SSG_MAX_REDIRECTS", 20), + max_redirects=current_app.config.get("MAX_REDIRECTS", 20), trust_env=False, event_hooks={"request": [ensure_public_request]}, ) as client, @@ -158,9 +156,7 @@ def fetch_source(source_url: str) -> tuple[httpx.Response, bytes]: else: raise VerificationError(f"Source returned HTTP {status}") - max_source_bytes = current_app.config.get( - "WEBMENTIONS_SSG_MAX_SOURCE_BYTES", 1_000_000 - ) + max_source_bytes = current_app.config.get("MAX_SOURCE_BYTES", 1_000_000) if (content_length := response.headers.get("Content-Length")) is not None: try: diff --git a/webmentions_ssg/tasks/scanner.py b/webmentions_ssg/tasks/scanner.py index 17898ba..1980abb 100644 --- a/webmentions_ssg/tasks/scanner.py +++ b/webmentions_ssg/tasks/scanner.py @@ -79,7 +79,7 @@ def canonical_url( if base_url is None: raise SourceScanError( "Document contains a relative canonical URL, but " - "WEBMENTIONS_SSG_SOURCE_BASE_URL is not configured" + "SOURCE_BASE_URL is not configured" ) resolved = urljoin(source_url_for_path(relative_path, base_url), href) @@ -292,8 +292,7 @@ def scan_source_file( if source_url is None: if base_url is None: raise SourceScanError( - "Document has no canonical URL and " - "WEBMENTIONS_SSG_SOURCE_BASE_URL is not configured" + "Document has no canonical URL and SOURCE_BASE_URL is not configured" ) source_url = source_url_for_path(relative_path, base_url) @@ -410,7 +409,7 @@ def scan_sources() -> None: :raises RuntimeError: If the configured source directory or base URL is invalid. """ - directory = current_app.config.get("WEBMENTIONS_SSG_SOURCE_DIRECTORY") + directory = current_app.config.get("SOURCE_DIRECTORY") if directory is None: return @@ -420,18 +419,16 @@ def scan_sources() -> None: if not root.is_dir(): raise RuntimeError(f"Source directory is not a directory: {root}") - base_url = current_app.config.get("WEBMENTIONS_SSG_SOURCE_BASE_URL") + base_url = current_app.config.get("SOURCE_BASE_URL") if base_url is not None: if not is_http_url(base_url): - raise RuntimeError( - "WEBMENTIONS_SSG_SOURCE_BASE_URL must be an absolute HTTP or HTTPS URL" - ) + raise RuntimeError("SOURCE_BASE_URL must be an absolute HTTP or HTTPS URL") base_url = f"{base_url.rstrip('/')}/" ignored_hostnames = tuple( pattern.lower().rstrip(".") - for pattern in current_app.config.get("WEBMENTIONS_SSG_IGNORED_HOSTNAMES", ()) + for pattern in current_app.config.get("IGNORED_HOSTNAMES", ()) ) sources_by_path = { diff --git a/webmentions_ssg/tasks/sender.py b/webmentions_ssg/tasks/sender.py index 1d22ad9..3b79448 100644 --- a/webmentions_ssg/tasks/sender.py +++ b/webmentions_ssg/tasks/sender.py @@ -175,7 +175,7 @@ def read_target_body(response: httpx.Response) -> bytes: :raises PermanentSenderError: If the document exceeds the configured maximum size. """ - max_bytes = current_app.config.get("WEBMENTIONS_SSG_MAX_TARGET_BYTES", 1_000_000) + max_bytes = current_app.config.get("MAX_TARGET_BYTES", 1_000_000) if (content_length := response.headers.get("Content-Length")) is not None: try: @@ -324,11 +324,9 @@ def send_webmention(webmention_uuid: uuid.UUID) -> None: try: with httpx.Client( headers={"User-Agent": (f"{APP_NAME}/{VERSION} SentWebmention")}, - timeout=httpx.Timeout( - current_app.config.get("WEBMENTIONS_SSG_REQUEST_TIMEOUT", 5.0) - ), + timeout=httpx.Timeout(current_app.config.get("REQUEST_TIMEOUT", 5.0)), follow_redirects=True, - max_redirects=current_app.config.get("WEBMENTIONS_SSG_MAX_REDIRECTS", 20), + max_redirects=current_app.config.get("MAX_REDIRECTS", 20), trust_env=False, event_hooks={"request": [ensure_public_request]}, ) as client: |
