generated from jCloud/repository-template
Add support for disabling the Gitea webhook secret
This commit is contained in:
+2
-2
@@ -46,6 +46,6 @@
|
||||
# false.
|
||||
# enabled=
|
||||
|
||||
# The file for the Gitea webhook secret. Must be set if Gitea webhooks
|
||||
# are enabled.
|
||||
# The file for the Gitea webhook secret. Leave it empty to disable the
|
||||
# secret (warning: very insecure).
|
||||
# webhook_secret_file=
|
||||
@@ -20,6 +20,7 @@ import ipaddress
|
||||
import pathlib
|
||||
import logging
|
||||
import argparse
|
||||
from typing import Optional
|
||||
|
||||
__all__ = [
|
||||
'load_config',
|
||||
@@ -118,7 +119,7 @@ def process_host_and_port(
|
||||
@dataclass
|
||||
class GiteaConfig:
|
||||
enabled: bool
|
||||
webhook_secret_file_path: pathlib.Path
|
||||
webhook_secret_file_path: Optional[pathlib.Path]
|
||||
|
||||
def _is_readable_file(path: pathlib.Path) -> bool:
|
||||
'''
|
||||
@@ -161,10 +162,14 @@ def process_gitea_config(
|
||||
if configuration['gitea'].enabled not in ('true', 'yes', 't', 'y'):
|
||||
return GiteaConfig(False, None)
|
||||
|
||||
secret_file_path = pathlib.Path(configuration['gitea'].webhook_secret_file)
|
||||
secret_file_path = configuration['gitea'].webhook_secret_file
|
||||
|
||||
if not _is_readable_file(secret_file_path):
|
||||
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)
|
||||
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):
|
||||
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)
|
||||
|
||||
return GiteaConfig(True, secret_file_path)
|
||||
Reference in New Issue
Block a user