#2152 cli: api: better error message when authentication fails
Closed 2 years ago by praiskup. Opened 2 years ago by schlupov.
copr/ schlupov/copr better_error_reporting  into  main

file modified
+4 -1
@@ -153,7 +153,10 @@ 

  

          def wrapper(self, args):

              if "no_config" in self.config:

-                 sys.stderr.write("Error: Operation requires api authentication\n")

+                 sys.stderr.write("Error: Operation requires api authentication\n"

+                                  "Take a kerberos ticket https://fedoraproject.org/wiki/Infrastructure/Kerberos, "

+                                  "or obtain an API token, "

+                                  "https://python-copr.readthedocs.io/en/latest/ClientV3.html#example-usage\n")

                  sys.exit(6)

  

              return func(self, args)

file modified
+10 -2
@@ -7,7 +7,8 @@ 

  import requests

  import requests_gssapi

  from munch import Munch

- from .exceptions import CoprConfigException, CoprException

+ from future.utils import raise_from

+ from .exceptions import CoprConfigException, CoprException, CoprGssapiException

  

  

  class List(list):
@@ -147,6 +148,13 @@ 

      """

      url = config["copr_url"] + "/api_v3/gssapi_login/"

      session = requests.Session()

-     response = session.get(url, auth=requests_gssapi.HTTPSPNEGOAuth(opportunistic_auth=True), allow_redirects=False)

+     response = None

+     try:

+         response = session.get(url, auth=requests_gssapi.HTTPSPNEGOAuth(opportunistic_auth=True), allow_redirects=False)

+     except requests_gssapi.exceptions.SPNEGOExchangeError as e:

+         error_msg = """Operation requires api authentication, take a kerberos ticket

+       (https://fedoraproject.org/wiki/Infrastructure/Kerberos), or obtain an API token

+       (https://python-copr.readthedocs.io/en/latest/ClientV3.html#example-usage)"""

+         raise_from(CoprGssapiException(error_msg), e)

      cookies = response.cookies.get("session")

      return cookies

no initial comment

Build succeeded.

Thanks, the patch is taken into #2151.

Pull-Request has been closed by praiskup

2 years ago