Skip to content

Commit

Permalink
[AIRFLOW-725] Use keyring to store credentials for JIRA
Browse files Browse the repository at this point in the history
Now allows to store the credentials in the keyring
of the OS. Retains backwards compatibility.

Closes apache#1966 from bolkedebruin/DEV_KEYRING
  • Loading branch information
Bolke de Bruin authored and jlowin committed Feb 26, 2017
1 parent ef6dd1b commit 8c16956
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions dev/airflow-pr
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ except ImportError:
print("Could not find the click library. Run 'sudo pip install click' to install.")
sys.exit(-1)

try:
import keyring
except ImportError:
print("Could not find the keyring library. Run 'sudo pip install keyring' to install.")
sys.exit(-1)

# Location of your Airflow git development area
AIRFLOW_GIT_LOCATION = os.environ.get(
"AIRFLOW_GIT",
Expand All @@ -77,6 +83,7 @@ BRANCH_PREFIX = "PR_TOOL"

TMP_CREDENTIALS = {}


class PRToolError(Exception):
pass

Expand Down Expand Up @@ -460,6 +467,10 @@ def fix_version_from_branch(branch, versions):
return versions[-1]


def register(username, password):
""" Use this function to register a JIRA account in your OS' keyring """
keyring.set_password('airflow-pr', username, password)

def validate_jira_id(jira_id):
if not jira_id:
return
Expand Down Expand Up @@ -542,13 +553,19 @@ def resolve_jira_issue(comment=None, jira_id=None, merge_branches=None):
click.echo(
'Set a JIRA_USERNAME env var to avoid this prompt in the future.')
TMP_CREDENTIALS['JIRA_USERNAME'] = JIRA_USERNAME
if JIRA_USERNAME and not JIRA_PASSWORD:
JIRA_PASSWORD = keyring.get_password("airflow-pr", JIRA_USERNAME)
if JIRA_PASSWORD:
click.echo("Obtained password from keyring. To reset remove it there.")
if not JIRA_PASSWORD:
JIRA_PASSWORD = click.prompt(
click.style('Password for Airflow JIRA', fg='blue', bold=True),
type=str,
hide_input=True)
click.echo(
'Set a JIRA_PASSWORD env var to avoid this prompt in the future.')
if JIRA_USERNAME and JIRA_PASSWORD:
if click.confirm(click.style("Would you like to store your password "
"in your keyring?", fg='blue', bold=True)):
register(JIRA_USERNAME, JIRA_PASSWORD)
TMP_CREDENTIALS['JIRA_PASSWORD'] = JIRA_PASSWORD

try:
Expand Down
1 change: 1 addition & 0 deletions dev/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
click>=6.6,<7
jira>=1.0.7,<2
keyring==10.1

0 comments on commit 8c16956

Please sign in to comment.