def retryWithAuthOrRaise(original_exception): # in all cases ask for auth, so that in non-interactive mode a # login URL is displayed auth.authorizeUser(provider='github', interactive=interactive) if not interactive: raise original_exception else: logger.debug('trying with authtoken: %s', settings.getProperty('github', 'authtoken')) return fn(*args, **kwargs)
def wrapped(*args, **kwargs): # auth, , authenticate users, internal from yotta.lib import auth # if yotta is being run noninteractively, then we never retry, but we # do call auth.authorizeUser, so that a login URL can be displayed: interactive = globalconf.get('interactive') try: return fn(*args, **kwargs) except requests.exceptions.HTTPError as e: if e.response.status_code == requests.codes.unauthorized: #pylint: disable=no-member logger.debug('%s unauthorised', fn) # any provider is sufficient for registry auth auth.authorizeUser(provider=None, interactive=interactive) if interactive: logger.debug('retrying after authentication...') return fn(*args, **kwargs) raise
def execCommand(args, following_args): registry = args.registry if args.apikey: registry_access.setAPIKey(registry, args.apikey) try: provider = None if args.github_login: provider = 'github' return auth.authorizeUser(registry, provider=provider, interactive=args.interactive) except auth.AuthTimedOut as e: logging.error("Login failed: %s", e) return 1