]> git.ipfire.org Git - pakfire.git/commitdiff
hub: Raise a better error for any authentication errors
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Oct 2022 15:54:10 +0000 (15:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Oct 2022 15:54:10 +0000 (15:54 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/hub.py

index 77c143090ad255d522bd7f031ab92563016803c4..d9824d463ac5614dbdda048876d95f210693d45f 100644 (file)
@@ -49,6 +49,13 @@ tornado.httpclient.AsyncHTTPClient.configure(
        },
 )
 
+class AuthError(Exception):
+       """
+               Raised when the client could not authenticate against the hub
+       """
+       pass
+
+
 class Hub(object):
        def __init__(self, url, keytab=None):
                self.url = url
@@ -129,7 +136,7 @@ class Hub(object):
                                # Validate the server response
                                result = kerberos.authGSSClientStep(krb5_context, krb5_server_response)
                                if not result == kerberos.AUTH_GSS_COMPLETE:
-                                       raise RuntimeError("Could not verify the Kerberos server response")
+                                       raise AuthError("Could not verify the Kerberos server response")
 
                                log.debug("Kerberos Server Response validating succeeded")
 
@@ -138,7 +145,7 @@ class Hub(object):
 
                        # If there were no headers
                        else:
-                               raise RuntimeError("Mutual authentication failed")
+                               raise AuthError("Mutual authentication failed")
 
                # Decode JSON response
                if res.body:
@@ -159,7 +166,7 @@ class Hub(object):
                result, krb5_context = kerberos.authGSSClientInit("HTTP@%s" % url.hostname)
 
                if not result == kerberos.AUTH_GSS_COMPLETE:
-                       raise RuntimeError("Could not create Kerberos Client context")
+                       raise AuthError("Could not create Kerberos Client context")
 
                # Next step...
                try:
@@ -167,10 +174,11 @@ class Hub(object):
 
                except kerberos.GSSError as e:
                        log.error("Kerberos authentication failed: %s" % e)
-                       raise e
+
+                       raise AuthError("%s" % e) from e
 
                if not result == kerberos.AUTH_GSS_CONTINUE:
-                       raise RuntimeError("Cloud not continue Kerberos authentication")
+                       raise AuthError("Cloud not continue Kerberos authentication")
 
                return krb5_context