in gui/backend/gui_plugin/core/lib/certs/management.py [0:0]
def reset_deployment(certs, type):
installing = type == "install"
# Identify if any of the locations is scripted
scripted = False
for cert_location in certs:
if cert_location.scripted:
deprecated = cert_location.deprecated
installed = cert_location.installed
valid = cert_location.valid
if installing and ((installed and deprecated) or (not deprecated and (not installed or not valid))):
scripted = True
elif not installing and installed:
scripted = True
# If any of the locations was scripted, all of the install is done through a script
if scripted:
script = create_certificate_script(type, certs)
cert_path = general.get_shell_user_dir(
"plugin_data", "gui_plugin", "web_certs")
Path(cert_path).mkdir(parents=True, exist_ok=True)
script_path = os.path.join(cert_path, f'{type}.sh')
# Save the script
with open(script_path, 'w') as file:
file.write(script)
# Make the script executable
SystemUtils.run_system_command(['chmod', 'u+x', script_path])
terminal_error = None
cmd = None
try:
cmd = SystemUtils.get_terminal_command() + [script_path]
exit_code, output = SystemUtils.run_shell_cmd(cmd)
if not exit_code is None:
raise SystemError(output)
except Exception as e:
logger.error(e)
terminal_error = f"Could not {type} the Shell GUI certificate. Please execute '{script_path}' to install it manually"
if SystemUtils.in_vs_code():
terminal_error += ' and restart Visual Studio Code.'
else:
terminal_error += '.'
if not terminal_error is None:
raise Exception(terminal_error)
# If none of the locations was scripted, then executes individual operations
else:
for cert_location in certs:
if not cert_location.scripted:
while cert_location.installed and (not installing or not cert_location.valid or cert_location.deprecated):
cert_location.uninstall()
if installing:
for cert_location in certs:
if not cert_location.scripted and not cert_location.deprecated and (not cert_location.installed or not cert_location.valid):
cert_location.install()
return True