...
Excerpt |
---|
If you are writing a script that interacts with Jira through a REST API, you should authenticate using an OAuth token, rather than an embedded username/password. Here we describe one way to do the 'oauth dance' to generate a trusted token using Python 3 - specifically the |
Warning | ||
---|---|---|
| ||
Personal Access Tokens make this approach obsolete. Use them instead if you are using Jira 8.14 and above. | ||
Warning | ||
These instructions no longer work for me on tested combinations {Ubuntu 18.04 + Python 3.6.9}, { Ubuntu 20.04 + Python 3.8.5}. The Code Block | |
Table of Contents |
---|
Establishing OAuth trust
...
Install Python libraries
Code Block |
---|
pip3 install -U pip # upgrade pip to avoid "No module named 'setuptools_rust'" error pip3 install jira ipython pyjwt 'jira[cli]==3.5.0' ipython==8.10 pyjwt |
Yes, you need those particular versions. The jira
library >3.5.0 broke backwards-compat with older Jiras, and ipython > 8.10 is broken for our purposes.
Expand | ||
---|---|---|
| ||
If you get an error:
then pip3 install -U pip should fix it. |
...
Code Block |
---|
$ cp venv/bin/jirashell check-jira-license $ vim check-jira-license # Make changes $ cat check-jira-license #!/home/jturner/src/redradish/nagios-jira-license/venv/bin/python3 # -*- coding: utf-8 -*- import re import sys from jira.jirashell import get_config, JIRA def main()if __name__ == '__main__': options, basic_auth, oauth, kerberos_auth = get_config() jira = JIRA( options=options, oauth=oauth) print(jira.server_info()) if __name__ == '__main__': ) sys.exit(mainprint(jira.server_info()) |
This command can then be invoked using the same command-line flags as jirashell
:
...