Add support for disabling the Gitea webhook secret

This commit is contained in:
2026-05-11 22:53:12 +02:00
parent 547edfaef0
commit b8dc240a8a
2 changed files with 12 additions and 7 deletions
+2 -2
View File
@@ -46,6 +46,6 @@
# false. # false.
# enabled= # enabled=
# The file for the Gitea webhook secret. Must be set if Gitea webhooks # The file for the Gitea webhook secret. Leave it empty to disable the
# are enabled. # secret (warning: very insecure).
# webhook_secret_file= # webhook_secret_file=
+7 -2
View File
@@ -20,6 +20,7 @@ import ipaddress
import pathlib import pathlib
import logging import logging
import argparse import argparse
from typing import Optional
__all__ = [ __all__ = [
'load_config', 'load_config',
@@ -118,7 +119,7 @@ def process_host_and_port(
@dataclass @dataclass
class GiteaConfig: class GiteaConfig:
enabled: bool enabled: bool
webhook_secret_file_path: pathlib.Path webhook_secret_file_path: Optional[pathlib.Path]
def _is_readable_file(path: pathlib.Path) -> bool: def _is_readable_file(path: pathlib.Path) -> bool:
''' '''
@@ -161,8 +162,12 @@ def process_gitea_config(
if configuration['gitea'].enabled not in ('true', 'yes', 't', 'y'): if configuration['gitea'].enabled not in ('true', 'yes', 't', 'y'):
return GiteaConfig(False, None) return GiteaConfig(False, None)
secret_file_path = pathlib.Path(configuration['gitea'].webhook_secret_file) secret_file_path = configuration['gitea'].webhook_secret_file
if not secret_file_path: # disable secret
secret_file_path = None
else:
secret_file_path = pathlib.Path(secret_file_path)
if not _is_readable_file(secret_file_path): if not _is_readable_file(secret_file_path):
logger.critical(f'{secret_file_path}: Cannot read Gitea webhook secret file') logger.critical(f'{secret_file_path}: Cannot read Gitea webhook secret file')
raise Fail(f'{secret_file_path}: Cannot read Gitea webhook secret file', exit_code = 2) raise Fail(f'{secret_file_path}: Cannot read Gitea webhook secret file', exit_code = 2)