from ..Playbooks.Playbook import FileCleanupTask, PlaybookCredentialCollection
from ... import Configuration
from ...Logging.Logger import log, Severity
from ..SetupStep import SetupStep
import requests

class TestInternetConnection(SetupStep):
    def run(self, file_cleanup_stack : list[FileCleanupTask], credentials: PlaybookCredentialCollection) -> bool:
        try:
            url = f'https://{Configuration.get_val("repository", "server")}'
            requests.get(url, timeout=5)
            log("Internet connection test succeeded.")
            return True
        except requests.RequestException:
            log("No internet connection!", Severity.ERROR)
            return False