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

Adding E2/MWS Accounts API support to the CLI #294

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

abhinavg6
Copy link

This is a PR to add E2/WMS Accounts API support to the Databricks CLI. Support for these high-level constructs has been added as part of this:

  • Credentials
  • Storage Config
  • Network
  • Customer Managed Key
  • Workspace

Idea is that the objects could also be used via the SDK Client in customer projects. This is one example: https://github.com/abhinavg6/awsdb-workspace-provisioner.

# See the License for the specific language governing permissions and
# limitations under the License.

from .api import *
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, why do we need this?

Copy link
Author

Choose a reason for hiding this comment

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

Good question. So we need to expose the create_* methods in AccountsApi to be used via the SDK. Rather than doing a import in a client as import databricks_cli.accounts.api in a client, we're doing a import here directly.

@@ -794,3 +794,104 @@ def get_instance_pool(self, instance_pool_id=None, headers=None):
def list_instance_pools(self, headers=None):
_data = {}
return self.client.perform_query('GET', '/instance-pools/list', data=_data, headers=headers)


class AccountsService(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this change autogenerated?

Copy link
Author

Choose a reason for hiding this comment

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

No @andrewmchen, I implemented it. Sorry, should it have been auto-generated somehow?

Copy link
Author

Choose a reason for hiding this comment

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

As per @andrewmchen - this needs to be inlined in the proto as this is auto-generated.

Abhinav Garg added 2 commits May 11, 2020 20:47
if account_id is None:
raise TypeError('Expected account_id')
endpoint = "/accounts/%s/credentials" % (account_id)
return self.client.client.perform_query('POST', endpoint, data=json)

Choose a reason for hiding this comment

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

Why not write these into the client SDK as well?

Copy link
Author

Choose a reason for hiding this comment

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

I did not see any other POST perform_query methods accepting a JSON for other objects in the client SDK, so I skipped these too.

help=JsonClickType.help('/api/2.0/accounts/{account_id}/credentials'))
@debug_option
@profile_option
@eat_exceptions

Choose a reason for hiding this comment

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

This looks foreboding. Does this mean exceptions won't be surfaced?

Copy link
Author

Choose a reason for hiding this comment

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

Just repeating the pattern from other objects in the CLI.

@click.option('--json', default=None, type=JsonClickType(),
help=JsonClickType.help('/api/2.0/accounts/{account_id}/credentials'))
@debug_option
@profile_option

Choose a reason for hiding this comment

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

What do these do?

Copy link
Author

Choose a reason for hiding this comment

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

Just repeating the pattern from other objects in the CLI. I think @profile_option makes the command open to --profile parameter which would correspond to a particular workspace environment.

if method in self.restful_methods:
restful_method = method
if method == 'REST-GET':
restful_method = 'GET'
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary? I see you don't typically pass in data anyways. If you don't won't method = GET do the same thing?

Copy link
Author

Choose a reason for hiding this comment

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

I just tried to keep the restful API separate from the existing API where we try and create the query parameters for GET today. Didn't want to cause an unintended change due to how APIs are being designed now vs earlier.

Copy link
Contributor

Choose a reason for hiding this comment

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

@abhinavg6 but data is always empty in AccountsService, therefore REST-GET might be unnecessary

Copy link
Author

Choose a reason for hiding this comment

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

Guys - Please feel free to fix this after it has been merged. I've no time to look at it and test it now. At this point I don't care if it gets approved or not, because I was trying to do this coz Eng didn't have capacity and CLI is often overlooked for new APIs.

if method in self.restful_methods:
restful_method = method
if method == 'REST-GET':
restful_method = 'GET'
Copy link
Contributor

Choose a reason for hiding this comment

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

@abhinavg6 but data is always empty in AccountsService, therefore REST-GET might be unnecessary

def close(self):
"""Close the client"""
pass

# helper functions starting here

def perform_query(self, method, path, data = {}, headers = None):
"""Adding for Accounts API support"""
path_specific_url = ""
if path.startswith("/accounts"):
Copy link
Contributor

Choose a reason for hiding this comment

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

@abhinavg6 we might not need this change, because ApiClient shouldn't be aware of different URLs. There's also "Execution Context API", which can be used by this very same ApiClient class without the need of modifying it.

It already has host, username and password, which are part of profile configuration. And most likely we'll have to have one profile for "usual" workspace work like clusters/jobs and another profile for "multiworkspace" setup.

Also, this client could have different "provider function", that is different from databricks_cli.configure.config#provide_api_client - something like provide_multiworkspace_client.

it might also be helpful to add few lines to README.md to describe how to use both modes and how to configure multiworkspace functionality.

Copy link
Author

Choose a reason for hiding this comment

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

Please feel free to change if this is merged. I'm not doing anything right now.

@pietern
Copy link
Contributor

pietern commented Jul 1, 2022

@abhinavg6 It's been a while since the last update. Do you want to reboot or abort this PR?

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.

5 participants