From 9c1561ff26bbba599944b67cb05e2a40d210eb84 Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Tue, 9 Aug 2022 12:07:31 -0400 Subject: [PATCH 1/4] lpapicache: remove try-except around login that only logs the error and then re-raises --- ubuntutools/lp/lpapicache.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/ubuntutools/lp/lpapicache.py b/ubuntutools/lp/lpapicache.py index 7d5e44e..b9a5571 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -74,12 +74,8 @@ class _Launchpad(object): def login(self, service=service, api_version=api_version): '''Enforce a non-anonymous login.''' if not self.logged_in: - try: - self.__lp = LP.login_with('ubuntu-dev-tools', service, - version=api_version) - except IOError as error: - Logger.error(str(error)) - raise + self.__lp = LP.login_with('ubuntu-dev-tools', service, + version=api_version) else: raise AlreadyLoggedInError('Already logged in to Launchpad.') From 562e6b13cdfac28567918719a68c76e586c8f1d6 Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Tue, 9 Aug 2022 12:08:50 -0400 Subject: [PATCH 2/4] lpapicache: force lp access on login to workaround possibly invalid cached creds --- ubuntutools/lp/lpapicache.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ubuntutools/lp/lpapicache.py b/ubuntutools/lp/lpapicache.py index b9a5571..3d82cd7 100644 --- a/ubuntutools/lp/lpapicache.py +++ b/ubuntutools/lp/lpapicache.py @@ -76,6 +76,12 @@ class _Launchpad(object): if not self.logged_in: self.__lp = LP.login_with('ubuntu-dev-tools', service, version=api_version) + # Unfortunately launchpadlib may 'login' using cached + # credentials, without actually verifying if the credentials + # are valid; which can lead to this 'login' not actually + # logging in. + # So, this forces actual LP access here, to force actual login. + self.__lp.me else: raise AlreadyLoggedInError('Already logged in to Launchpad.') From ad402231dbbd9ed0bf22145f6f6daf5bc06a75c7 Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Tue, 9 Aug 2022 12:10:05 -0400 Subject: [PATCH 3/4] ubuntu-build: explicitly login to LP LP: #1984113 --- ubuntu-build | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ubuntu-build b/ubuntu-build index a08a7ef..a557d1e 100755 --- a/ubuntu-build +++ b/ubuntu-build @@ -135,12 +135,14 @@ def main(): Logger.error(error) sys.exit(1) - # Get the ubuntu archive try: - ubuntu_archive = Distribution('ubuntu').getArchive() - # Will fail here if we have no credentials, bail out + # Will fail here if we have no credentials, bail out + Launchpad.login() except IOError: sys.exit(1) + + # Get the ubuntu archive + ubuntu_archive = Distribution('ubuntu').getArchive() # Get list of published sources for package in question. try: sources = ubuntu_archive.getSourcePackage(package, release, pocket) From 7d278cde21aa23aea0e111c290be0b9264291c16 Mon Sep 17 00:00:00 2001 From: Dan Streetman Date: Tue, 9 Aug 2022 12:12:31 -0400 Subject: [PATCH 4/4] ubuntu-build: use correct exception from LP login failure --- ubuntu-build | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ubuntu-build b/ubuntu-build index a557d1e..3e02141 100755 --- a/ubuntu-build +++ b/ubuntu-build @@ -30,6 +30,7 @@ from ubuntutools.lp.udtexceptions import (SeriesNotFoundException, PackageNotFoundException, PocketDoesNotExistError,) from ubuntutools.lp.lpapicache import Distribution, PersonTeam +from launchpadlib.credentials import TokenAuthorizationException from ubuntutools.misc import split_release_pocket from ubuntutools import getLogger @@ -138,7 +139,7 @@ def main(): try: # Will fail here if we have no credentials, bail out Launchpad.login() - except IOError: + except TokenAuthorizationException: sys.exit(1) # Get the ubuntu archive