Skip to content

Commit

Permalink
ZOOKEEPER-4784: Token based ASF JIRA authentication
Browse files Browse the repository at this point in the history
Reviewers: anmolnar, anmolnar
Author: szucsvillo
Closes apache#2106 from szucsvillo/ZOOKEEPER-4784
  • Loading branch information
szucsvillo authored and AlphaCanisMajoris committed Mar 28, 2024
1 parent 598dc24 commit 2ab8efd
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions zk-merge-pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
JIRA_USERNAME = os.environ.get("JIRA_USERNAME", "")
# ASF JIRA password
JIRA_PASSWORD = os.environ.get("JIRA_PASSWORD", "")
# ASF JIRA access token
# If it is configured, username and password are dismissed
# Go to https://issues.apache.org/jira/secure/ViewProfile.jspa -> Personal Access Tokens for
# your own token management.
JIRA_ACCESS_TOKEN = os.environ.get("JIRA_ACCESS_TOKEN")
# OAuth key used for issuing requests against the GitHub API. If this is not defined, then requests
# will be unauthenticated. You should only need to configure this if you find yourself regularly
# exceeding your IP's unauthenticated request rate limit. You can create an OAuth key at
Expand Down Expand Up @@ -249,8 +254,12 @@ def fix_version_from_branch(branch, versions):


def resolve_jira_issue(merge_branches, comment, default_jira_id=""):
asf_jira = jira.client.JIRA({'server': JIRA_API_BASE},
basic_auth=(JIRA_USERNAME, JIRA_PASSWORD))
jira_server = {"server": JIRA_API_BASE}

if JIRA_ACCESS_TOKEN is not None:
asf_jira = jira.client.JIRA(jira_server, token_auth=JIRA_ACCESS_TOKEN)
else:
asf_jira = jira.client.JIRA(jira_server, basic_auth=(JIRA_USERNAME, JIRA_PASSWORD))

jira_id = input("Enter a JIRA id [%s]: " % default_jira_id)
if jira_id == "":
Expand Down Expand Up @@ -400,15 +409,15 @@ def check_jira_env():
global JIRA_PASSWORD

if JIRA_IMPORTED:

if JIRA_USERNAME.strip() != "" and JIRA_PASSWORD.strip() == "":
inform_pwd = input("JIRA_USERNAME set but JIRA_PASSWORD is not. Want to inform it? ")
if inform_pwd.strip() == "y":
JIRA_PASSWORD = getpass.getpass('JIRA PASSWORD: ')

if JIRA_USERNAME.strip() == "" or JIRA_PASSWORD.strip() == "":
msg ="JIRA_USERNAME and/or JIRA_PASSWORD are not set. Want to continue? "
continue_maybe(msg)
if JIRA_ACCESS_TOKEN is None:
if JIRA_USERNAME.strip() != "" and JIRA_PASSWORD.strip() == "":
inform_pwd = input("JIRA_USERNAME set but JIRA_PASSWORD is not. Want to inform it? ")
if inform_pwd.strip() == "y":
JIRA_PASSWORD = getpass.getpass('JIRA PASSWORD: ')

if JIRA_USERNAME.strip() == "" or JIRA_PASSWORD.strip() == "":
msg ="Neither JIRA_ACCESS_TOKEN nor JIRA_USERNAME and/or JIRA_PASSWORD are set. Want to continue? "
continue_maybe(msg)
else:
msg = "JIRA lib not installed. Want to continue? "
continue_maybe(msg)
Expand Down Expand Up @@ -499,12 +508,12 @@ def main():
merged_refs = merged_refs + [cherry_pick(pr_num, merge_hash, latest_branch)]

if JIRA_IMPORTED:
if JIRA_USERNAME and JIRA_PASSWORD:
if (JIRA_ACCESS_TOKEN is not None) or (JIRA_USERNAME and JIRA_PASSWORD):
continue_maybe("Would you like to update an associated JIRA?")
jira_comment = "Issue resolved by pull request %s\n[%s/%s]" % (pr_num, GITHUB_BASE, pr_num)
resolve_jira_issues(commit_title, merged_refs, jira_comment)
else:
print("JIRA_USERNAME and JIRA_PASSWORD not set")
print("Neither JIRA_ACCESS_TOKEN nor JIRA_USERNAME and/or JIRA_PASSWORD are set.")
print("Exiting without trying to close the associated JIRA.")
else:
print("Could not find jira-python library. Run 'sudo pip install jira' to install.")
Expand Down

0 comments on commit 2ab8efd

Please sign in to comment.