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

Add support for write only configuration profiles. #64

Merged
merged 5 commits into from
Feb 23, 2018

Conversation

andrewmchen
Copy link
Contributor

This is part one of two for the configuration profile feature.

In this part, we add support for writing configurations with different profiles. In the next PR, we will add support for using this profile to authenticate to a Databricks workspace other than the one specified by the DEFAULT profile.

@@ -35,41 +35,42 @@
PROMPT_TOKEN = 'Token' # NOQA


def _configure_cli_token():
def _configure_cli_token(profile):

Choose a reason for hiding this comment

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

does it support consolidated shard? I think we need to set workspaceId for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it should. The profile here is just to distinguish between different types of configurations. Since the DEFAULT profile already works with consolidated I don't see why other profiles wouldn't.

@@ -51,30 +52,35 @@ def decorator(*args, **kwargs):
return decorator


def _get_api_client():
def profile_option(f):

Choose a reason for hiding this comment

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

Why don't we just document how to create config file? I don't think the command option is that useful for this. As a user I would be fine to copy paste and modify the token.

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 think that would be useful as well. Regarding the command option, aws configure supports the --profile option so this PR follows this convention.

TEST_USER + '\n' +
TEST_PASSWORD + '\n' +
TEST_PASSWORD + '\n'))
assert DatabricksConfig.fetch_from_fs().host(DEFAULT_SECTION) == TEST_HOST

Choose a reason for hiding this comment

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

can we have some test that doesn't use DEFAULT_SECTION

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test_configure_two_sections should test that behavior.


def test_is_valid_true(self):
assert self.databricks_config_from_password.is_valid
assert self.databricks_config_from_token.is_valid

def test_is_valid_false(self):
databricks_config = config.DatabricksConfig()
assert not databricks_config.is_valid
assert not databricks_config.is_valid(config.DEFAULT_SECTION)

Choose a reason for hiding this comment

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

Do we need DEFAULT_SECTION everywhere? Can we simply call assert not databricks_config.is_valid()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, the explicit parameter adds some clarity here.

Copy link
Collaborator

@mengxr mengxr left a comment

Choose a reason for hiding this comment

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

'DEFAULT' is the default profile name. But we should think about whether it should be case sensitive or not. Currently, if I ran databricks configure --profile default, I got

  File "/Users/meng/anaconda2/lib/python2.7/site-packages/databricks_cli-0.4.2-py2.7.egg/databricks_cli/configure/config.py", line 131, in _create_section_if_absent
    self._config.add_section(profile)
  File "/Users/meng/anaconda2/lib/python2.7/ConfigParser.py", line 261, in add_section
    raise ValueError, 'Invalid section name: %s' % section
ValueError: Invalid section name: defaul

@property
def host(self):
return self._config.get(DEFAULT_SECTION, HOST) if self.is_valid else None
def host(self, profile):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems more extensible if we implement a DatabricksConfigProvider class (or Factory) that has def from_profile(profile): method. Then the code changes to

conf = DatabricksConfProvider.from_profile(profile)
api_client = ApiClient(conf)

@andrewmchen andrewmchen merged commit bb544b1 into databricks:master Feb 23, 2018
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.

3 participants