mirror of
https://github.com/netinvent/npbackup.git
synced 2025-09-07 21:44:47 +08:00
Upgrader: Inject build type into request
This commit is contained in:
parent
5852dbb5dd
commit
1537e0500a
7 changed files with 46 additions and 16 deletions
|
@ -16,4 +16,5 @@ if __name__ == "__main__":
|
|||
if "--run-as-cli" in sys.argv:
|
||||
# Drop --run-as-cli argument since cli doesn't know about it
|
||||
sys.argv.pop(sys.argv.index("--run-as-cli"))
|
||||
os.environ["NPBACKUP_BUILD_TYPE"] = "cli"
|
||||
main()
|
||||
|
|
|
@ -17,6 +17,8 @@ if __name__ == "__main__":
|
|||
if "--run-as-cli" in sys.argv:
|
||||
# Drop --run-as-cli argument since cli doesn't know about it
|
||||
sys.argv.pop(sys.argv.index("--run-as-cli"))
|
||||
os.environ["NPBACKUP_BUILD_TYPE"] = "cli"
|
||||
main()
|
||||
else:
|
||||
os.environ["NPBACKUP_BUILD_TYPE"] = "gui"
|
||||
main_gui()
|
||||
|
|
|
@ -13,4 +13,5 @@ from npbackup.gui.__main__ import main_gui
|
|||
del sys.path[0]
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ["NPBACKUP_BUILD_TYPE"] = "viewer"
|
||||
main_gui(viewer_mode=True)
|
||||
|
|
|
@ -7,7 +7,7 @@ __intname__ = "npbackup.upgrade_client.upgrader"
|
|||
__author__ = "Orsiris de Jong"
|
||||
__copyright__ = "Copyright (C) 2023-2024 NetInvent"
|
||||
__license__ = "BSD-3-Clause"
|
||||
__build__ = "2024091701"
|
||||
__build__ = "2024112601"
|
||||
|
||||
|
||||
import os
|
||||
|
@ -145,20 +145,24 @@ def auto_upgrader(
|
|||
requestor.create_session(authenticated=True)
|
||||
|
||||
# We'll check python_arch instead of os_arch since we build 32 bit python executables for compat reasons
|
||||
platform_and_arch = "{}/{}".format(get_os(), python_arch()).lower()
|
||||
if IS_LEGACY:
|
||||
platform_and_arch += "-legacy"
|
||||
arch = python_arch() if not IS_LEGACY else f"{python_arch()}-legacy"
|
||||
build_type = os.environ.get("NPBACKUP_BUILD_TYPE", None)
|
||||
if not build_type:
|
||||
logger.critical("Cannot determine build type for upgrade processs")
|
||||
return False
|
||||
target = "{}/{}/{}".format(get_os(), arch, build_type).lower()
|
||||
try:
|
||||
host_id = "{}/{}/{}".format(auto_upgrade_host_identity, npbackup_version, group)
|
||||
id_record = "{}/{}".format(platform_and_arch, host_id)
|
||||
id_record = "{}/{}".format(target, host_id)
|
||||
except TypeError:
|
||||
id_record = platform_and_arch
|
||||
id_record = target
|
||||
|
||||
file_info = requestor.data_model("upgrades", id_record=id_record)
|
||||
try:
|
||||
sha256sum = file_info["sha256sum"]
|
||||
except (KeyError, TypeError):
|
||||
logger.error("Cannot get file description")
|
||||
logger.debug("Trace", exc_info=True)
|
||||
return False
|
||||
if sha256sum is None:
|
||||
logger.info("No upgrade file found has been found for me :/")
|
||||
|
|
|
@ -18,7 +18,7 @@ from argparse import ArgumentParser
|
|||
from fastapi import FastAPI, HTTPException, Response, Depends, status, Request, Header
|
||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||
from fastapi_offline import FastAPIOffline
|
||||
from upgrade_server.models.files import FileGet, FileSend, Platform, Arch
|
||||
from upgrade_server.models.files import FileGet, FileSend, Platform, Arch, BuildType
|
||||
from upgrade_server.models.oper import CurrentVersion
|
||||
import upgrade_server.crud as crud
|
||||
import upgrade_server.configuration as configuration
|
||||
|
@ -125,20 +125,20 @@ async def current_version(
|
|||
|
||||
|
||||
@app.get(
|
||||
"/upgrades/{platform}/{arch}", response_model=Union[FileSend, dict], status_code=200
|
||||
"/upgrades/{platform}/{arch}/{build_type}", response_model=Union[FileSend, dict], status_code=200
|
||||
)
|
||||
@app.get(
|
||||
"/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}",
|
||||
"/upgrades/{platform}/{arch}/{build_type}/{auto_upgrade_host_identity}",
|
||||
response_model=Union[FileSend, dict],
|
||||
status_code=200,
|
||||
)
|
||||
@app.get(
|
||||
"/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}/{installed_version}",
|
||||
"/upgrades/{platform}/{arch}/{build_type}/{auto_upgrade_host_identity}/{installed_version}",
|
||||
response_model=Union[FileSend, dict],
|
||||
status_code=200,
|
||||
)
|
||||
@app.get(
|
||||
"/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}/{installed_version}/{group}",
|
||||
"/upgrades/{platform}/{arch}/{build_type}/{auto_upgrade_host_identity}/{installed_version}/{group}",
|
||||
response_model=Union[FileSend, dict],
|
||||
status_code=200,
|
||||
)
|
||||
|
@ -146,6 +146,7 @@ async def upgrades(
|
|||
request: Request,
|
||||
platform: Platform,
|
||||
arch: Arch,
|
||||
build_type: BuildType,
|
||||
auto_upgrade_host_identity: str = None,
|
||||
installed_version: str = None,
|
||||
group: str = None,
|
||||
|
@ -176,7 +177,7 @@ async def upgrades(
|
|||
|
||||
# TODO:
|
||||
# This can be amended by adding specific rules for host identity or groups or installed
|
||||
file = FileGet(platform=platform, arch=arch)
|
||||
file = FileGet(platform=platform, arch=arch, build_type=build_type)
|
||||
try:
|
||||
result = crud.get_file(file)
|
||||
if not result:
|
||||
|
@ -193,7 +194,20 @@ async def upgrades(
|
|||
|
||||
|
||||
@app.get(
|
||||
"/download/{platform}/{arch}/{auto_upgrade_host_identity}/{installed_version}/{group}",
|
||||
"/download/{platform}/{arch}/{build_type}", response_model=FileSend, status_code=200
|
||||
)
|
||||
@app.get(
|
||||
"/download/{platform}/{arch}/{build_type}/{auto_upgrade_host_identity}",
|
||||
response_model=FileSend,
|
||||
status_code=200,
|
||||
)
|
||||
@app.get(
|
||||
"/download/{platform}/{arch}/{build_type}/{auto_upgrade_host_identity}/{installed_version}",
|
||||
response_model=FileSend,
|
||||
status_code=200,
|
||||
)
|
||||
@app.get(
|
||||
"/download/{platform}/{arch}/{build_type}/{auto_upgrade_host_identity}/{installed_version}/{group}",
|
||||
response_model=FileSend,
|
||||
status_code=200,
|
||||
)
|
||||
|
@ -201,6 +215,7 @@ async def download(
|
|||
request: Request,
|
||||
platform: Platform,
|
||||
arch: Arch,
|
||||
built_type: BuildType,
|
||||
auto_upgrade_host_identity: str = None,
|
||||
installed_version: str = None,
|
||||
group: str = None,
|
||||
|
@ -228,7 +243,7 @@ async def download(
|
|||
crud.store_host_info(config_dict["upgrades"]["statistics_file"], host_id=data)
|
||||
except KeyError:
|
||||
logger.error("No statistics file set.")
|
||||
file = FileGet(platform=platform, arch=arch)
|
||||
file = FileGet(platform=platform, arch=arch, build_type=build_type)
|
||||
try:
|
||||
result = crud.get_file(file, content=True)
|
||||
if not result:
|
||||
|
|
|
@ -7,7 +7,7 @@ __intname__ = "npbackup.upgrade_server.crud"
|
|||
__author__ = "Orsiris de Jong"
|
||||
__copyright__ = "Copyright (C) 2023-2024 NetInvent"
|
||||
__license__ = "GPL-3.0-only"
|
||||
__build__ = "2024091701"
|
||||
__build__ = "2024112601"
|
||||
|
||||
|
||||
import os
|
||||
|
@ -89,7 +89,7 @@ def get_current_version() -> Optional[CurrentVersion]:
|
|||
def get_file(
|
||||
file: FileGet, content: bool = False
|
||||
) -> Optional[Union[FileSend, bytes, dict]]:
|
||||
possible_filename = "npbackup.zip"
|
||||
possible_filename = f"npbackup-{file.build_type.value}.zip"
|
||||
path = os.path.join(
|
||||
config_dict["upgrades"]["data_root"],
|
||||
file.platform.value,
|
||||
|
@ -102,6 +102,7 @@ def get_file(
|
|||
return {
|
||||
"arch": file.arch.value,
|
||||
"platform": file.platform.value,
|
||||
"build_type": file.build_type.value,
|
||||
"sha256sum": None,
|
||||
"filename": None,
|
||||
"file_length": 0,
|
||||
|
@ -116,6 +117,7 @@ def get_file(
|
|||
file_send = FileSend(
|
||||
arch=file.arch.value,
|
||||
platform=file.platform.value,
|
||||
build_type=file.build_type.value,
|
||||
sha256sum=sha256,
|
||||
filename=possible_filename,
|
||||
file_length=length,
|
||||
|
|
|
@ -23,10 +23,15 @@ class Arch(Enum):
|
|||
x86 = "x86"
|
||||
x64 = "x64"
|
||||
|
||||
class BuildType(Enum):
|
||||
gui = "gui"
|
||||
cli = "cli"
|
||||
|
||||
|
||||
class FileBase(BaseModel):
|
||||
arch: Arch
|
||||
platform: Platform
|
||||
build_type: BuildType
|
||||
|
||||
|
||||
class FileGet(FileBase):
|
||||
|
|
Loading…
Add table
Reference in a new issue