-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Use keyring for password storage #135
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:3-alpine | ||
FROM python:3 | ||
|
||
RUN pip install panoptescli | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM python:2.7-alpine | ||
FROM python:2.7 | ||
|
||
RUN pip install panoptescli | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import click | ||
import os | ||
|
||
import click | ||
import keyring | ||
import yaml | ||
|
||
from panoptes_cli.scripts.panoptes import cli | ||
|
@@ -25,19 +27,40 @@ def configure(ctx, edit_all): | |
if opt == 'endpoint' and not edit_all: | ||
continue | ||
|
||
is_password = opt == 'password' | ||
ctx.parent.config[opt] = click.prompt( | ||
opt, | ||
default=value, | ||
hide_input=is_password, | ||
show_default=not is_password, | ||
) | ||
|
||
if not ctx.parent.config['endpoint'].startswith('https://'): | ||
click.echo( | ||
'Error: Invalid endpoint supplied. Endpoint must be an HTTPS URL.' | ||
) | ||
return -1 | ||
|
||
new_password = click.prompt( | ||
'Password [leave blank for no change]', | ||
hide_input=True, | ||
show_default=False, | ||
default='', | ||
) | ||
if new_password: | ||
try: | ||
keyring.set_password( | ||
'panoptes', | ||
ctx.parent.config['username'], | ||
new_password, | ||
) | ||
except RuntimeError: | ||
click.echo( | ||
'Warning: Could not save your password to the keyring. ' | ||
'You will be asked for your password each time.', | ||
err=True, | ||
) | ||
|
||
save_config(ctx.parent.config_file, ctx.parent.config) | ||
|
||
|
||
with open(ctx.parent.config_file, 'w') as conf_f: | ||
yaml.dump(ctx.parent.config, conf_f, default_flow_style=False) | ||
def save_config(config_file, config): | ||
with open(config_file, 'w') as conf_f: | ||
yaml.dump(config, conf_f, default_flow_style=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. blank line at end of file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import click | ||
import os | ||
|
||
import click | ||
import keyring | ||
import yaml | ||
|
||
from panoptes_client import Panoptes | ||
|
||
|
||
|
@@ -28,7 +31,6 @@ def cli(ctx, endpoint, admin): | |
ctx.config = { | ||
'endpoint': 'https://www.zooniverse.org', | ||
'username': '', | ||
'password': '', | ||
} | ||
|
||
try: | ||
|
@@ -41,10 +43,44 @@ def cli(ctx, endpoint, admin): | |
ctx.config['endpoint'] = endpoint | ||
|
||
if ctx.invoked_subcommand != 'configure': | ||
try: | ||
password = keyring.get_password('panoptes', ctx.config['username']) | ||
except RuntimeError: | ||
password = None | ||
|
||
if 'password' in ctx.config: | ||
if not password: | ||
try: | ||
password = ctx.config['password'] | ||
keyring.set_password( | ||
'panoptes', | ||
ctx.config['username'], | ||
password, | ||
) | ||
retrieved_password = keyring.get_password( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. local variable 'retrieved_password' is assigned to but never used |
||
'panoptes', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||
ctx.config['username'], | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To do: Compare |
||
|
||
del ctx.config['password'] | ||
save_config(ctx.config_file, ctx.config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'save_config' may be undefined, or defined from star imports: panoptes_cli.commands.configure, panoptes_cli.commands.info, panoptes_cli.commands.project, panoptes_cli.commands.subject, panoptes_cli.commands.subject_set, panoptes_cli.commands.user, panoptes_cli.commands.workflow |
||
except RuntimeError: | ||
click.echo( | ||
'Warning: Your password is stored insecurely and ' | ||
'secure keyrings are not supported on your system.', | ||
err=True, | ||
) | ||
|
||
if not password: | ||
password = click.prompt( | ||
'Password for {}'.format(ctx.config['username']), | ||
hide_input=True, | ||
) | ||
|
||
Panoptes.connect( | ||
endpoint=ctx.config['endpoint'], | ||
username=ctx.config['username'], | ||
password=ctx.config['password'], | ||
password=password, | ||
admin=admin, | ||
) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line contains whitespace