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

Use ~/.ccm/.dse.ini as dse credentials file if it exists by default. #426

Merged
merged 2 commits into from
Dec 17, 2015
Merged

Use ~/.ccm/.dse.ini as dse credentials file if it exists by default. #426

merged 2 commits into from
Dec 17, 2015

Conversation

tolbertam
Copy link
Contributor

I really like the recent addition of the '--dse-credentials' config parameter for loading credentials from a config file. For convenience I think it would be nice if there were a default credentials file that, if exists, will be loaded to grab the dse credentials. This would remove the need to pass the path of the credentials file each time you create a cluster.

The existing behavior:

  • If user passes in --dse-credentials, grab dse_username and dse_password from the passed in config file.
  • Else grab from --dse-username and/or --dse-password

The new behavior:

  • If user doesn't pass in --dse-credentials and .dse.ini exists, set dse_username and dse_password based on it's contents.
  • Else If user passes in --dse-credentials, grab dse_username and dse_password from the passed in config file.
  • If --dse-username and/or --dse-password were passed in explicitly, override the dse_username and dse_password values.

self.dse_username = dse_username
if dse_password is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a need to define self.dse_username and password as None? Couldn't this just be

self.load_credentials_from_file(dse_credentials_file)
if dse_username is not None:
    self.dse_username, self.dse_password = dse_username, dse_password 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There would be a possible issue if there is no credentials file and --dse-username and --dse-password were not passed in, here is the failure behavior with explicitly setting them to None beforehand:

ccmlib.common.ArgumentError: Invalid url http://downloads.datastax.com/enterprise/dse-4.8.2-bin.tar.gz (underlying error is: HTTP Error 401: Unauthorized)

And without:

AttributeError: 'DseCluster' object has no attribute 'dse_username'

I think the first scenario is more obvious, but maybe we should assert that there was a resolved username / password beforehand. I'll add some additional logic for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've improved this by logging warnings if either dse_username or password are not set:

Warning: No dse username detected, specify one using --dse-username or passing in a credentials file using --dse-credentials.
Warning: No dse password detected, specify one using --dse-password or passing in a credentials file using --dse-credentials.

The download will still be attempted (and thus the Invalid url error will appear), I figured i'd leave it as is in the event the download ever doesn't require authentication.

@ptnapoleon
Copy link
Contributor

+1

ptnapoleon added a commit that referenced this pull request Dec 17, 2015
Use ~/.ccm/.dse.ini as dse credentials file if it exists by default.
@ptnapoleon ptnapoleon merged commit a67b5b4 into riptano:master Dec 17, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants