def login( *, store: storeapi.StoreClient, packages: Iterable[Dict[str, str]] = None, save: bool = True, acls: Iterable[str] = None, channels: Iterable[str] = None, expires: str = None, config_fd: TextIO = None, ) -> bool: if not store: store = storeapi.StoreClient() email = "" password = "" if not config_fd: echo.wrapped("Enter your Ubuntu One e-mail address and password.") echo.wrapped( "If you do not have an Ubuntu One account, you can create one " "at https://snapcraft.io/account" ) email = echo.prompt("Email") if os.getenv("SNAPCRAFT_TEST_INPUT"): # Integration tests do not work well with hidden input. echo.warning("Password will be visible.") hide_input = False else: hide_input = True password = echo.prompt("Password", hide_input=hide_input) try: _try_login( email, password, store=store, packages=packages, acls=acls, channels=channels, expires=expires, config_fd=config_fd, save=save, ) # Let StoreAuthenticationError pass through so we get decent error messages except storeapi.errors.InvalidCredentialsError: return _fail_login(storeapi.constants.INVALID_CREDENTIALS) except storeapi.errors.StoreAccountInformationError: return _fail_login(storeapi.constants.ACCOUNT_INFORMATION_ERROR) except storeapi.errors.NeedTermsSignedError as e: return _fail_login(e.message) # type: ignore return True
def register_decorator(self, *args, snap_name: str, **kwargs): try: return method(self, *args, snap_name=snap_name, **kwargs) except storeapi.errors.StoreUploadError as upload_error: if "resource-not-found" not in upload_error.error_list: raise echo.wrapped( "You are required to register this snap before continuing. " "Refer to 'snapcraft help register' for more options.") if echo.confirm( "Would you like to register {!r} with the Snap Store?". format(snap_name)): self.register(snap_name=snap_name) return method(self, *args, snap_name=snap_name, **kwargs) else: raise
def login( *, store: storeapi.StoreClient, packages: Iterable[Dict[str, str]] = None, save: bool = True, acls: Iterable[str] = None, channels: Iterable[str] = None, expires: str = None, config_fd: TextIO = None, ) -> bool: if not store: store = storeapi.StoreClient() email = "" password = "" if not config_fd: echo.wrapped("Enter your Ubuntu One e-mail address and password.") echo.wrapped( "If you do not have an Ubuntu One account, you can create one " "at https://snapcraft.io/account" ) email = echo.prompt("Email") if os.getenv("SNAPCRAFT_TEST_INPUT"): # Integration tests do not work well with hidden input. echo.warning("Password will be visible.") hide_input = False else: hide_input = True password = echo.prompt("Password", hide_input=hide_input) _try_login( email, password, store=store, packages=packages, acls=acls, channels=channels, expires=expires, config_fd=config_fd, save=save, ) return True
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, 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.errors.StoreTwoFactorAuthenticationRequired: one_time_password = echo.prompt("Second-factor auth") store.login( email, password, one_time_password=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)