From 36692b5ac1766e2d589775ac77f5165d57c6c7e7 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 15 Jun 2025 14:07:38 +0000 Subject: [PATCH] API: Move the app into __init__.py Signed-off-by: Michael Tremer --- Makefile.am | 1 - src/api/__init__.py | 25 +++++++++++++++++++++++-- src/api/app.py | 42 ------------------------------------------ src/api/builds.py | 2 +- 4 files changed, 24 insertions(+), 46 deletions(-) delete mode 100644 src/api/app.py diff --git a/Makefile.am b/Makefile.am index d139bc3f..bc99be56 100644 --- a/Makefile.am +++ b/Makefile.am @@ -122,7 +122,6 @@ CLEANFILES += \ api_PYTHON = \ src/api/__init__.py \ - src/api/app.py \ src/api/builds.py apidir = $(pkgpythondir)/api diff --git a/src/api/__init__.py b/src/api/__init__.py index e55f07f5..c98c56ff 100644 --- a/src/api/__init__.py +++ b/src/api/__init__.py @@ -18,11 +18,32 @@ # # ############################################################################### +import fastapi +import fastapi.middleware.cors + from .. import Backend # Initialize the backend backend = Backend("/etc/pakfire/pbs.conf") #backend.launch_background_tasks() -# Import the app -from .app import app +# Initialize the app +app = fastapi.FastAPI( + title = "Pakfire Build Service API", + version = "0.0.1", + + # Enable debug mode + debug = True, +) + +# Add CORS +app.add_middleware( + fastapi.middleware.cors.CORSMiddleware, + allow_origins=["https://pakfire.ipfire.org"], + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + +# Load all further modules +from . import builds diff --git a/src/api/app.py b/src/api/app.py deleted file mode 100644 index bd87bebc..00000000 --- a/src/api/app.py +++ /dev/null @@ -1,42 +0,0 @@ -############################################################################### -# # -# Pakfire - The IPFire package management system # -# Copyright (C) 2025 Pakfire development team # -# # -# This program is free software: you can redistribute it and/or modify # -# it under the terms of the GNU General Public License as published by # -# the Free Software Foundation, either version 3 of the License, or # -# (at your option) any later version. # -# # -# This program is distributed in the hope that it will be useful, # -# but WITHOUT ANY WARRANTY; without even the implied warranty of # -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # -# GNU General Public License for more details. # -# # -# You should have received a copy of the GNU General Public License # -# along with this program. If not, see . # -# # -############################################################################### - -import fastapi -import fastapi.middleware.cors - -app = fastapi.FastAPI( - title = "Pakfire Build Service API", - version = "0.0.1", - - # Enable debug mode - debug = True, -) - -# Add CORS -app.add_middleware( - fastapi.middleware.cors.CORSMiddleware, - allow_origins=["https://pakfire.ipfire.org"], - allow_credentials=True, - allow_methods=["*"], - allow_headers=["*"], -) - -# Load all further modules -from . import builds diff --git a/src/api/builds.py b/src/api/builds.py index f93fab7b..a22b57ae 100644 --- a/src/api/builds.py +++ b/src/api/builds.py @@ -21,7 +21,7 @@ import fastapi import uuid -from .app import app +from . import app from . import backend @app.get("/builds/{build_id}") -- 2.47.3