Files
release-server/src/jcloud_deployment_server/api/main.py
T
2026-05-12 18:56:34 +02:00

72 lines
2.3 KiB
Python

# Copyright 2026 jCloud
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
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, 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():
args = parse_args(sys.argv[1:])
configuration, default_configuration = load_config(args.config)
logger_info = setup_logging(configuration)
host, port = process_host_and_port(
configuration,
default_configuration,
args,
logger_info.logger
)
gitea_config = process_gitea_config(configuration, logger_info.logger)
# Initialize FastAPI
app = FastAPI(
docs_url=configuration.docs.swagger,
redoc_url=configuration.docs.redoc,
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,
port = port,
server_header = False,
log_config = logger_info.uvicorn_config
)