From 04bad39685da09d8a7a867cb6d67f0cc35969446 Mon Sep 17 00:00:00 2001 From: Varun Valada Date: Wed, 4 Dec 2024 17:52:19 -0600 Subject: [PATCH 1/2] Add better messages for 401 and 403 errors from job submissions --- cli/testflinger_cli/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cli/testflinger_cli/__init__.py b/cli/testflinger_cli/__init__.py index e5bcf0f8..37171606 100644 --- a/cli/testflinger_cli/__init__.py +++ b/cli/testflinger_cli/__init__.py @@ -541,6 +541,22 @@ def submit_job_data(self, data: dict, headers: dict = None): "Received 404 error from server. Are you " "sure this is a testflinger server?" ) + if exc.status == 401: + sys.exit( + "Received 401 error from server. You are " + "attempting to use a feature that requires " + "client authorisation without using client " + "credentials. See https://testflinger.readthedocs" + ".io/en/latest/how-to/authentication/ for more details" + ) + if exc.status == 403: + sys.exit( + "Received 403 error from server with reason " + f"{exc.msg}The specified client credentials do " + "not have sufficient permissions for the resource(s) " + "you are trying to access." + ) + # This shouldn't happen, so let's get more information sys.exit( "Unexpected error status from testflinger " From 26453a3164885d86c0ea9d1d684ff39ead3e0c6a Mon Sep 17 00:00:00 2001 From: Varun Valada Date: Mon, 9 Dec 2024 16:34:47 -0500 Subject: [PATCH 2/2] Update error message Co-authored-by: Paul Larson --- cli/testflinger_cli/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/testflinger_cli/__init__.py b/cli/testflinger_cli/__init__.py index 37171606..fd5d74fa 100644 --- a/cli/testflinger_cli/__init__.py +++ b/cli/testflinger_cli/__init__.py @@ -552,7 +552,8 @@ def submit_job_data(self, data: dict, headers: dict = None): if exc.status == 403: sys.exit( "Received 403 error from server with reason " - f"{exc.msg}The specified client credentials do " + f"{exc.msg}" + "The specified client credentials do " "not have sufficient permissions for the resource(s) " "you are trying to access." )