from ...Machine.PaedMLMachineCollection import MACHINE_COLLECTION
from ...Logging.Logger import log, Severity
from ...SetupSteps.Playbooks.Playbook import FileCleanupTask, PlaybookCredentialCollection
from ...SetupSteps.SetupStep import SetupStep


class UpdateAppCerts(SetupStep):
    def run(self, file_cleanup_stack: list[FileCleanupTask], credentials: PlaybookCredentialCollection) -> bool:
        log('Updating application certificates...')
        stdout, stderr, retval = MACHINE_COLLECTION.server.execute_shell_command('univention-app', 'update-certificates')
        if retval != 0:
            log(f'Failed to update application certificates: {stderr}', Severity.ERROR)
            return False

        log('Application certificates updated successfully.', Severity.DEBUG)
        return True