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.
|
# 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=
|
||||||
@@ -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,10 +162,14 @@ 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 _is_readable_file(secret_file_path):
|
if not secret_file_path: # disable secret
|
||||||
logger.critical(f'{secret_file_path}: Cannot read Gitea webhook secret file')
|
secret_file_path = None
|
||||||
raise Fail(f'{secret_file_path}: Cannot read Gitea webhook secret file', exit_code = 2)
|
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)
|
return GiteaConfig(True, secret_file_path)
|
||||||
Reference in New Issue
Block a user