Пример #1
0
def finalize_system(session: HISSession, system: int, *, serial_number: str,
                    operating_system: str, model: str, pubkey: str) -> bool:
    """Finalizes the system."""

    json = {'system': system}

    if serial_number is not None:
        json['sn'] = serial_number

    if operating_system is not None:
        json['os'] = operating_system

    if model is not None:
        json['model'] = model

    if pubkey is not None:
        json['wg_pubkey'] = pubkey

    response = session.post(FINALIZE_URL, json=json)

    if response.status_code != 200:
        LOGGER.error('Could not finalize system.')
        LOGGER.debug(response.content)
        return False

    return True
Пример #2
0
    def wrapper(*args, **kwargs) -> int:
        try:
            return_code = function(*args, **kwargs)
        except KeyboardInterrupt:
            LOGGER.error('Aborted by user.')
            return 1

        return 0 if return_code is None else return_code
Пример #3
0
    def __exit__(self, _, value, __):
        """Handles login and download errors."""
        if isinstance(value, LoginError):
            LOGGER.error('Error during login.')
            LOGGER.debug(value)
            exit(2)

        if isinstance(value, DownloadError):
            LOGGER.error(self.error_text)
            LOGGER.debug(value)
            exit(3)
Пример #4
0
def update_credentials(account: str | None,
                       passwd: str | None = None) -> tuple[str, str]:
    """Reads the credentials for a HIS account."""

    if not account:
        try:
            account = input('User name: ')
        except (EOFError, KeyboardInterrupt):
            print()
            LOGGER.error('Aborted by user.')
            exit(1)

    if not passwd:
        try:
            passwd = getpass('Password: '******'Aborted by user.')
            exit(1)

    return account, passwd