Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def jira_login(endpoint, user=None):
try:
basic_auth = None
if user:
if sys.stdin.isatty():
password = getpass.getpass(stream=sys.stderr)
else:
password = sys.stdin.readline().rstrip()
basic_auth = (user, password)
try:
jira = GreenHopper({'server': endpoint}, basic_auth=basic_auth)
except JIRAError:
sys.stderr.write("warn: Autentication to JIRA failed," +
" continuing unauthenticated\n")
jira = GreenHopper({'server': endpoint})
# pylint: disable=protected-access
if "JSESSIONID" in jira._session.cookies:
# drop basic auth if we have a cookie (for performance)
jira._session.auth = None
return jira
except JIRAError as exn:
sys.stderr.write("Connection to JIRA failed: %s: %s\n" %
(exn.response.status_code, exn.response.reason))
exit(4)
def jira_login(endpoint, user=None):
try:
basic_auth = None
if user:
if sys.stdin.isatty():
password = getpass.getpass(stream=sys.stderr)
else:
password = sys.stdin.readline().rstrip()
basic_auth = (user, password)
try:
jira = GreenHopper({'server': endpoint}, basic_auth=basic_auth)
except JIRAError:
sys.stderr.write("warn: Autentication to JIRA failed," +
" continuing unauthenticated\n")
jira = GreenHopper({'server': endpoint})
# pylint: disable=protected-access
if "JSESSIONID" in jira._session.cookies:
# drop basic auth if we have a cookie (for performance)
jira._session.auth = None
return jira
except JIRAError as exn:
sys.stderr.write("Connection to JIRA failed: %s: %s\n" %
(exn.response.status_code, exn.response.reason))
exit(4)
__all__ = ['JIRA', 'JIRAError']
class ObliviousCookieJar(RequestsCookieJar):
def set_cookie(self, *args, **kwargs):
"""Simply ignore any request to set a cookie."""
pass
def copy(self):
"""Make sure to return an instance of the correct class on copying."""
return ObliviousCookieJar()
class JIRA(GreenHopper):
def _create_http_basic_session(self, username, password):
super(JIRA, self)._create_http_basic_session(username, password)
# XXX: JIRA logs the web user out if we send the session cookies we get
# back from the first request in any subsequent requests. As we don't
# need cookies when accessing the API anyway, just ignore all of them.
self._session.cookies = ObliviousCookieJar()
def close(self):
self._session.close()
# This script shows how to use the client in anonymous mode
# against jira.atlassian.com.
from jira.client import GreenHopper
# By default, the client will connect to a JIRA instance started from the Atlassian Plugin SDK
# (see https://developer.atlassian.com/display/DOCS/Installing+the+Atlassian+Plugin+SDK for details).
# Override this with the options parameter.
# GreenHopper is a plugin in a JIRA instance
options = {"server": "https://jira.atlassian.com"}
gh = GreenHopper(options)
# Get all boards viewable by anonymous users.
boards = gh.boards()
# Get the sprints in a specific board
board_id = 441
print("GreenHopper board: %s (%s)" % (boards[0].name, board_id))
sprints = gh.sprints(board_id)