Add Gitea API router

This commit is contained in:
2026-05-12 18:56:34 +02:00
parent b8dc240a8a
commit 7c6ca3b5a4
2 changed files with 67 additions and 2 deletions
+20 -2
View File
@@ -12,16 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from fastapi import FastAPI
from fastapi import FastAPI, Header
import os
import uvicorn
import ipaddress
import jcloud_config_parser
import logging
from .arguments import parse_args
from .config import load_config, process_host_and_port
from .config import load_config, process_host_and_port, process_gitea_config
from .logging import setup_logging
from ..integrations.gitea.middlewares.signature import GiteaSignatureMiddleware
from ..integrations.gitea.middlewares.check_enabled import GiteaCheckEnabledMiddleware
from ..integrations.gitea.api.webhooks import make_router
import sys
def main():
@@ -38,6 +40,8 @@ def main():
logger_info.logger
)
gitea_config = process_gitea_config(configuration, logger_info.logger)
# Initialize FastAPI
app = FastAPI(
docs_url=configuration.docs.swagger,
@@ -45,6 +49,20 @@ def main():
openapi_url=configuration.docs.openapi
)
if gitea_config.webhook_secret_file_path is not None:
app.add_middleware(
GiteaSignatureMiddleware,
secret = gitea_config.webhook_secret_file_path.read_bytes(),
logger = logger_info.logger
) # empty secret is an example value!
app.add_middleware(
GiteaCheckEnabledMiddleware,
configuration = configuration,
logger = logger_info.logger
)
app.include_router(make_router(gitea_config.webhook_secret_file_path is not None))
uvicorn.run(
app,
host = host,