Esempio n. 1
0
def _try_login(email: str,
               password: str,
               *,
               store: storeapi.StoreClient = None,
               save: bool = True,
               packages: Iterable[Dict[str, str]] = None,
               acls: Iterable[str] = None,
               channels: Iterable[str] = None,
               config_fd: TextIO = None) -> None:
    try:
        store.login(email,
                    password,
                    packages=packages,
                    acls=acls,
                    channels=channels,
                    config_fd=config_fd,
                    save=save)
        if not config_fd:
            print()
            logger.info(storeapi.constants.TWO_FACTOR_WARNING)
    except storeapi.errors.StoreTwoFactorAuthenticationRequired:
        one_time_password = input('Second-factor auth: ')
        store.login(email,
                    password,
                    one_time_password=one_time_password,
                    acls=acls,
                    packages=packages,
                    channels=channels,
                    config_fd=config_fd,
                    save=save)

    # Continue if agreement and namespace conditions are met.
    _check_dev_agreement_and_namespace_statuses(store)
def _store_session(macaroon_location):
    store = StoreClient()

    with open(macaroon_location) as macaroon:
        log.debug('Logging onto Snap store with macaroon file "{}"...'.format(macaroon.name))
        # XXX Bad API. email and password are mandatory in the function signature, but they are
        # read from the macaroon when config_fd is provided
        store.login(email='', password='', config_fd=macaroon)

    log.info('Logged on Snap store')
    try:
        yield store
    finally:
        log.debug('Logging off Snap store...')
        store.logout()
        log.info('Logged off Snap store')
Esempio n. 3
0
def _try_login(
    email: str,
    password: str,
    *,
    store: storeapi.StoreClient,
    save: bool = True,
    packages: Iterable[Dict[str, str]] = None,
    acls: Iterable[str] = None,
    channels: Iterable[str] = None,
    expires: str = None,
    config_fd: TextIO = None,
) -> None:
    try:
        store.login(
            email=email,
            password=password,
            packages=packages,
            acls=acls,
            channels=channels,
            expires=expires,
            config_fd=config_fd,
            save=save,
        )
        if not config_fd:
            print()
            echo.wrapped(storeapi.constants.TWO_FACTOR_WARNING)
    except storeapi.http_clients.errors.StoreTwoFactorAuthenticationRequired:
        one_time_password = echo.prompt("Second-factor auth")
        store.login(
            email=email,
            password=password,
            otp=one_time_password,
            acls=acls,
            packages=packages,
            channels=channels,
            expires=expires,
            config_fd=config_fd,
            save=save,
        )

    # Continue if agreement and namespace conditions are met.
    _check_dev_agreement_and_namespace_statuses(store)