generated from jCloud/repository-template
Add Gitea API router
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user