From af7b6fe82d690cecb53f27e2103ab27e5889c603 Mon Sep 17 00:00:00 2001 From: Robert Foss Date: Thu, 16 Mar 2023 13:05:41 +0100 Subject: [PATCH] jiralogin: Add support for token_auth authentication Self-hosted Jira instances can't use the API token authentication, but must instead rely on the Personal Access Token authentication scheme. This patch introduces support for this authentication method as the third mode of authenticating. [1] https://jira.readthedocs.io/examples.html#token-auth Signed-off-by: Robert Foss --- cfg.py | 8 +++++--- docs/config.rst | 6 ++++-- jiralogin.py | 10 +++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cfg.py b/cfg.py index 69f75eb..c918232 100644 --- a/cfg.py +++ b/cfg.py @@ -39,12 +39,14 @@ def create_default_config(): # Jira server information #server: -# url: https://linaro.atlassian.net -# token: abcdefghijkl +# url: https://issues.redhat.com +# token: abcdefghijkl # Jira Cloud Token +# token_auth: abcdefghijkl # Jira Personal Access Token #test_server: # url: https://.atlassian.net -# token: abcdefghijkl +# token: abcdefghijkl # Jira Cloud Token +# token_auth: abcdefghijkl # Jira Personal Access Token # Extra comments added to each Jira issue (multiline is OK) comments: diff --git a/docs/config.rst b/docs/config.rst index f9c45d3..a24ef06 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -35,11 +35,13 @@ looks like this: # Jira server information #server: # url: https://linaro.atlassian.net - # token: abcdefghijkl + # token: abcdefghijkl # Jira Cloud Token + # token_auth: abcdefghijkl # Jira Personal Access Token #test_server: # url: https://.atlassian.net - # token: abcdefghijkl + # token: abcdefghijkl # Jira Cloud Token + # token_auth: abcdefghijkl # Jira Personal Access Token # Extra comments added to each Jira issue (multiline is OK) comments: diff --git a/jiralogin.py b/jiralogin.py index 904fd4f..c98e92b 100644 --- a/jiralogin.py +++ b/jiralogin.py @@ -98,14 +98,18 @@ def get_jira_instance(use_test_server): server = cfg.get_server(use_test_server) url = server.get('url') token = server.get('token') + token_auth = server.get('token_auth') # password based authentication - if not token: + if not (token or token_auth): password = get_password() try: - if token: - log.debug("Accessing %s with %s using token based authentication" % (url, username)) + if token_auth: + log.debug("Accessing %s with %s using personal access token authentication" % (url, username)) + j = JIRA(url, token_auth=(token_auth)), username + elif token: + log.debug("Accessing %s with %s using cloud token authentication" % (url, username)) j = JIRA(url, basic_auth=(username, token)), username else: log.debug("Accessing %s with %s using password based authentication" % (url, username))