Bulk rename auto_upgrade vars and fix upgrade status in about gui

This commit is contained in:
Orsiris de Jong 2023-02-02 23:28:08 +01:00
parent 0b5c06cb4e
commit b951220315
8 changed files with 47 additions and 50 deletions

View file

@ -66,9 +66,9 @@ env:
options: options:
auto_upgrade: true auto_upgrade: true
server_url: auto_upgrade_server_url:
server_username: auto_upgrade_server_username:
server_password: auto_upgrade_server_password:
# every 10 NPBackup runs, we'll try an autoupgrade. Never set this lower than 2 since failed upgrades will prevent backups from succeeding # every 10 NPBackup runs, we'll try an autoupgrade. Never set this lower than 2 since failed upgrades will prevent backups from succeeding
interval: 10 interval: 10
backup_admin_password: NPBackup_00 backup_admin_password: NPBackup_00

View file

@ -42,8 +42,8 @@ ENCRYPTED_OPTIONS = [
{"section": "repo", "name": "password", "type": str}, {"section": "repo", "name": "password", "type": str},
{"section": "prometheus", "name": "http_username", "type": str}, {"section": "prometheus", "name": "http_username", "type": str},
{"section": "prometheus", "name": "http_password", "type": str}, {"section": "prometheus", "name": "http_password", "type": str},
{"section": "options", "name": "server_username", "type": str}, {"section": "options", "name": "auto_upgrade_server_username", "type": str},
{"section": "options", "name": "server_password", "type": str}, {"section": "options", "name": "auto_upgrade_server_password", "type": str},
{"section": "options", "name": "backup_admin_password", "type": str}, {"section": "options", "name": "backup_admin_password", "type": str},
] ]

View file

@ -19,33 +19,33 @@ from npbackup.__main__ import __version__ as npbackup_version
logger = getLogger(__intname__) logger = getLogger(__intname__)
def check_new_version(config_dict): def check_new_version(config_dict: dict) -> bool:
try: try:
upgrade_url = config_dict["options"]["server_url"] upgrade_url = config_dict["options"]["auto_upgrade_server_url"]
username = config_dict["options"]["server_username"] username = config_dict["options"]["auto_upgrade_server_username"]
password = config_dict["options"]["server_password"] password = config_dict["options"]["auto_upgrade_server_password"]
except KeyError as exc: except KeyError as exc:
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc) logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
return False return None
else: else:
return _check_new_version(upgrade_url, username, password) return _check_new_version(upgrade_url, username, password)
def run_upgrade(config_dict): def run_upgrade(config_dict):
try: try:
auto_upgrade_upgrade_url = config_dict["options"]["server_url"] auto_upgrade_upgrade_url = config_dict["options"]["auto_upgrade_server_url"]
auto_upgrade_username = config_dict["options"]["server_username"] auto_upgrade_username = config_dict["options"]["auto_upgrade_server_username"]
auto_upgrade_password = config_dict["options"]["server_password"] auto_upgrade_password = config_dict["options"]["auto_upgrade_server_password"]
except KeyError as exc: except KeyError as exc:
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc) logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
return False return False
try: try:
host_identity = configuration.evaluate_variables( auto_upgrade_host_identity = configuration.evaluate_variables(
config_dict, config_dict["options"]["auto_upgrade_host_identity"] config_dict, config_dict["options"]["auto_upgrade_host_identity"]
) )
except KeyError: except KeyError:
host_identity = None auto_upgrade_host_identity = None
try: try:
group = configuration.evaluate_variables( group = configuration.evaluate_variables(
config_dict, config_dict["options"]["auto_ugrade_group"] config_dict, config_dict["options"]["auto_ugrade_group"]
@ -57,7 +57,7 @@ def run_upgrade(config_dict):
upgrade_url=auto_upgrade_upgrade_url, upgrade_url=auto_upgrade_upgrade_url,
username=auto_upgrade_username, username=auto_upgrade_username,
password=auto_upgrade_password, password=auto_upgrade_password,
host_identity=host_identity, auto_upgrade_host_identity=auto_upgrade_host_identity,
installed_version=npbackup_version, installed_version=npbackup_version,
group=group, group=group,
) )

View file

@ -64,8 +64,8 @@ def config_gui(config_dict: dict, config_file: str):
"http_password", "http_password",
"repository", "repository",
"password", "password",
"server_username", "auto_upgrade_server_username",
"server_password", "auto_upgrade_server_password",
]: ]:
try: try:
if config_dict[section][entry] is None: if config_dict[section][entry] is None:
@ -331,15 +331,15 @@ def config_gui(config_dict: dict, config_file: str):
], ],
[ [
sg.Text(_t("config_gui.auto_upgrade_server_url"), size=(30, 1)), sg.Text(_t("config_gui.auto_upgrade_server_url"), size=(30, 1)),
sg.Input(key="options---server_url", size=(50, 1)), sg.Input(key="options---auto_upgrade_server_url", size=(50, 1)),
], ],
[ [
sg.Text(_t("config_gui.auto_upgrade_server_username"), size=(30, 1)), sg.Text(_t("config_gui.auto_upgrade_server_username"), size=(30, 1)),
sg.Input(key="options---server_username", size=(50, 1)), sg.Input(key="options---auto_upgrade_server_username", size=(50, 1)),
], ],
[ [
sg.Text(_t("config_gui.auto_upgrade_server_password"), size=(30, 1)), sg.Text(_t("config_gui.auto_upgrade_server_password"), size=(30, 1)),
sg.Input(key="options---server_password", size=(50, 1)), sg.Input(key="options---auto_upgrade_server_password", size=(50, 1)),
], ],
[ [
sg.Text(_t("config_gui.auto_upgrade_interval"), size=(30, 1)), sg.Text(_t("config_gui.auto_upgrade_interval"), size=(30, 1)),

View file

@ -46,12 +46,9 @@ THREAD_SHARED_DICT = {}
def _about_gui(version_string: str, config_dict: dict) -> None: def _about_gui(version_string: str, config_dict: dict) -> None:
license_content = LICENSE_TEXT license_content = LICENSE_TEXT
try:
upgrade_server = config_dict["options"]["server_url"] result = check_new_version(config_dict)
except KeyError: if result:
upgrade_server = None
if upgrade_server:
if check_new_version(config_dict):
new_version = [ new_version = [
sg.Button( sg.Button(
_t("config_gui.auto_upgrade_launch"), _t("config_gui.auto_upgrade_launch"),
@ -59,9 +56,9 @@ def _about_gui(version_string: str, config_dict: dict) -> None:
size=(12, 2), size=(12, 2),
) )
] ]
else: elif result is False:
new_version = [sg.Text(_t("generic.is_uptodate"))] new_version = [sg.Text(_t("generic.is_uptodate"))]
else: elif result is None:
new_version = [sg.Text(_t("config_gui.auto_upgrade_disabled"))] new_version = [sg.Text(_t("config_gui.auto_upgrade_disabled"))]
try: try:
with open(LICENSE_FILE, "r") as file_handle: with open(LICENSE_FILE, "r") as file_handle:

View file

@ -35,7 +35,7 @@ en:
decrypt: Decrypt decrypt: Decrypt
encrypt: Encrypt encrypt: Encrypt
is_uptodate: Program Uptodate is_uptodate: Program Up to date
succes: Succes succes: Succes
failure: Failure failure: Failure

View file

@ -114,27 +114,27 @@ def _check_new_version(upgrade_url: str, username: str, password: str) -> bool:
logger.info("Upgrade server is %s", upgrade_url) logger.info("Upgrade server is %s", upgrade_url)
else: else:
logger.debug("Upgrade server not set") logger.debug("Upgrade server not set")
return False return None
requestor = Requestor(upgrade_url, username, password) requestor = Requestor(upgrade_url, username, password)
requestor.create_session(authenticated=True) requestor.create_session(authenticated=True)
server_ident = requestor.data_model() server_ident = requestor.data_model()
if server_ident is False: if server_ident is False:
logger.error("Cannot reach upgrade server") logger.error("Cannot reach upgrade server")
return False return None
try: try:
if not server_ident["app"] == "npbackup.upgrader": if not server_ident["app"] == "npbackup.upgrader":
logger.error("Current server is not a recognized NPBackup update server") logger.error("Current server is not a recognized NPBackup update server")
return False return None
except (KeyError, TypeError): except (KeyError, TypeError):
logger.error("Current server is not a NPBackup update server") logger.error("Current server is not a NPBackup update server")
return False return None
result = requestor.data_model("current_version") result = requestor.data_model("current_version")
try: try:
online_version = result["version"] online_version = result["version"]
except KeyError: except KeyError:
logger.error("Upgrade server failed to provide proper version info") logger.error("Upgrade server failed to provide proper version info")
return False return None
else: else:
if online_version: if online_version:
if version.parse(online_version) > version.parse(npbackup_version): if version.parse(online_version) > version.parse(npbackup_version):
@ -157,7 +157,7 @@ def auto_upgrader(
upgrade_url: str, upgrade_url: str,
username: str, username: str,
password: str, password: str,
host_identity: str = None, auto_upgrade_host_identity: str = None,
installed_version: str = None, installed_version: str = None,
group: str = None, group: str = None,
) -> bool: ) -> bool:
@ -181,7 +181,7 @@ def auto_upgrader(
platform_and_arch = "{}/{}".format(get_os(), os_arch()).lower() platform_and_arch = "{}/{}".format(get_os(), os_arch()).lower()
try: try:
host_id = "{}/{}/{}".format(host_identity, installed_version, group) host_id = "{}/{}/{}".format(auto_upgrade_host_identity, installed_version, group)
id_record = "{}/{}".format(platform_and_arch, host_id) id_record = "{}/{}".format(platform_and_arch, host_id)
except TypeError: except TypeError:
id_record = platform_and_arch id_record = platform_and_arch

View file

@ -81,17 +81,17 @@ async def current_version(auth=Depends(get_current_username)):
@app.get("/upgrades/{platform}/{arch}", response_model=FileSend, status_code=200) @app.get("/upgrades/{platform}/{arch}", response_model=FileSend, status_code=200)
@app.get( @app.get(
"/upgrades/{platform}/{arch}/{host_identity}", "/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}",
response_model=FileSend, response_model=FileSend,
status_code=200, status_code=200,
) )
@app.get( @app.get(
"/upgrades/{platform}/{arch}/{host_identity}/{installed_version}", "/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}/{installed_version}",
response_model=FileSend, response_model=FileSend,
status_code=200, status_code=200,
) )
@app.get( @app.get(
"/upgrades/{platform}/{arch}/{host_identity}/{installed_version}/{group}", "/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}/{installed_version}/{group}",
response_model=FileSend, response_model=FileSend,
status_code=200, status_code=200,
) )
@ -99,14 +99,14 @@ async def upgrades(
request: Request, request: Request,
platform: Platform, platform: Platform,
arch: Arch, arch: Arch,
host_identity: str = None, auto_upgrade_host_identity: str = None,
installed_version: str = None, installed_version: str = None,
group: str = None, group: str = None,
auth=Depends(get_current_username), auth=Depends(get_current_username),
): ):
data = { data = {
"ip": request.client.host, "ip": request.client.host,
"host_identity": host_identity, "auto_upgrade_host_identity": auto_upgrade_host_identity,
"installed_version": installed_version, "installed_version": installed_version,
"group": group, "group": group,
"platform": platform.value, "platform": platform.value,