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:
auto_upgrade: true
server_url:
server_username:
server_password:
auto_upgrade_server_url:
auto_upgrade_server_username:
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
interval: 10
backup_admin_password: NPBackup_00

View file

@ -42,8 +42,8 @@ ENCRYPTED_OPTIONS = [
{"section": "repo", "name": "password", "type": str},
{"section": "prometheus", "name": "http_username", "type": str},
{"section": "prometheus", "name": "http_password", "type": str},
{"section": "options", "name": "server_username", "type": str},
{"section": "options", "name": "server_password", "type": str},
{"section": "options", "name": "auto_upgrade_server_username", "type": str},
{"section": "options", "name": "auto_upgrade_server_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__)
def check_new_version(config_dict):
def check_new_version(config_dict: dict) -> bool:
try:
upgrade_url = config_dict["options"]["server_url"]
username = config_dict["options"]["server_username"]
password = config_dict["options"]["server_password"]
upgrade_url = config_dict["options"]["auto_upgrade_server_url"]
username = config_dict["options"]["auto_upgrade_server_username"]
password = config_dict["options"]["auto_upgrade_server_password"]
except KeyError as exc:
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
return False
return None
else:
return _check_new_version(upgrade_url, username, password)
def run_upgrade(config_dict):
try:
auto_upgrade_upgrade_url = config_dict["options"]["server_url"]
auto_upgrade_username = config_dict["options"]["server_username"]
auto_upgrade_password = config_dict["options"]["server_password"]
auto_upgrade_upgrade_url = config_dict["options"]["auto_upgrade_server_url"]
auto_upgrade_username = config_dict["options"]["auto_upgrade_server_username"]
auto_upgrade_password = config_dict["options"]["auto_upgrade_server_password"]
except KeyError as exc:
logger.error("Missing auto upgrade info: %s, cannot launch auto upgrade", exc)
return False
try:
host_identity = configuration.evaluate_variables(
auto_upgrade_host_identity = configuration.evaluate_variables(
config_dict, config_dict["options"]["auto_upgrade_host_identity"]
)
except KeyError:
host_identity = None
auto_upgrade_host_identity = None
try:
group = configuration.evaluate_variables(
config_dict, config_dict["options"]["auto_ugrade_group"]
@ -57,7 +57,7 @@ def run_upgrade(config_dict):
upgrade_url=auto_upgrade_upgrade_url,
username=auto_upgrade_username,
password=auto_upgrade_password,
host_identity=host_identity,
auto_upgrade_host_identity=auto_upgrade_host_identity,
installed_version=npbackup_version,
group=group,
)

View file

@ -64,8 +64,8 @@ def config_gui(config_dict: dict, config_file: str):
"http_password",
"repository",
"password",
"server_username",
"server_password",
"auto_upgrade_server_username",
"auto_upgrade_server_password",
]:
try:
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.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.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.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)),

View file

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

View file

@ -35,7 +35,7 @@ en:
decrypt: Decrypt
encrypt: Encrypt
is_uptodate: Program Uptodate
is_uptodate: Program Up to date
succes: Succes
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)
else:
logger.debug("Upgrade server not set")
return False
return None
requestor = Requestor(upgrade_url, username, password)
requestor.create_session(authenticated=True)
server_ident = requestor.data_model()
if server_ident is False:
logger.error("Cannot reach upgrade server")
return False
return None
try:
if not server_ident["app"] == "npbackup.upgrader":
logger.error("Current server is not a recognized NPBackup update server")
return False
return None
except (KeyError, TypeError):
logger.error("Current server is not a NPBackup update server")
return False
return None
result = requestor.data_model("current_version")
try:
online_version = result["version"]
except KeyError:
logger.error("Upgrade server failed to provide proper version info")
return False
return None
else:
if online_version:
if version.parse(online_version) > version.parse(npbackup_version):
@ -157,7 +157,7 @@ def auto_upgrader(
upgrade_url: str,
username: str,
password: str,
host_identity: str = None,
auto_upgrade_host_identity: str = None,
installed_version: str = None,
group: str = None,
) -> bool:
@ -181,7 +181,7 @@ def auto_upgrader(
platform_and_arch = "{}/{}".format(get_os(), os_arch()).lower()
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)
except TypeError:
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}/{host_identity}",
"/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}",
response_model=FileSend,
status_code=200,
)
@app.get(
"/upgrades/{platform}/{arch}/{host_identity}/{installed_version}",
"/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}/{installed_version}",
response_model=FileSend,
status_code=200,
)
@app.get(
"/upgrades/{platform}/{arch}/{host_identity}/{installed_version}/{group}",
"/upgrades/{platform}/{arch}/{auto_upgrade_host_identity}/{installed_version}/{group}",
response_model=FileSend,
status_code=200,
)
@ -99,14 +99,14 @@ async def upgrades(
request: Request,
platform: Platform,
arch: Arch,
host_identity: str = None,
auto_upgrade_host_identity: str = None,
installed_version: str = None,
group: str = None,
auth=Depends(get_current_username),
):
data = {
"ip": request.client.host,
"host_identity": host_identity,
"auto_upgrade_host_identity": auto_upgrade_host_identity,
"installed_version": installed_version,
"group": group,
"platform": platform.value,