Skip to content
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

allow passing username and password through environment variables #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ matrix:

include:
- python: "2.7"
- python: "3.4"
- python: "3.5"
- python: "3.6"
- python: pypy3.5-5.8.0
Expand Down
26 changes: 25 additions & 1 deletion cassandra_migrate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,20 @@ def main():
help='Connection port')
parser.add_argument('-u', '--user',
help='Connection username')
parser.add_argument('--user-environment-variable-name',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the advantage of having configurable environment variables for these two values instead of having a default one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zen of Python line two, my friend. :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were going to make it implicit, I'd probably do it by allowing any command line option to be overridden by setting $CASSANDRA_MIGRATE_{uppercased_option_name}. Do you think that would be preferable?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea, but I wouldn't block this PR because of that. I think just implementing the ones that you're gonna need right now would be enough, but it's always up to you :)

help="""
Name of an environment variable which contains the
username. Is overridden by --user if both are
passed.
""")
parser.add_argument('-P', '--password',
help='Connection password')
parser.add_argument('--password-environment-variable-name',
help="""
Name of an environment variable that contains the
password. Is overridden by --password if both are
passed.
""")
parser.add_argument('-c', '--config-file', default='cassandra-migrate.yml',
help='Path to configuration file')
parser.add_argument('-m', '--profile', default='dev',
Expand Down Expand Up @@ -134,9 +146,21 @@ def main():

print(os.path.basename(new_path))
else:
if opts.password:
password = opts.password
elif opts.password_environment_variable_name:
password = os.environ[opts.password_environment_variable_name]
else:
password = None
if opts.user:
user = opts.user
elif opts.user_environment_variable_name:
user = os.environ[opts.user_environment_variable_name]
else:
user = None
with Migrator(config=config, profile=opts.profile,
hosts=opts.hosts.split(','), port=opts.port,
user=opts.user, password=opts.password,
user=user, password=password,
host_cert_path=opts.ssl_cert,
client_key_path=opts.ssl_client_private_key,
client_cert_path=opts.ssl_client_cert) as migrator:
Expand Down
1 change: 0 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[tox]
envlist =
py27
py34
py35
py36
pypy3
Expand Down