From 738009444830dcd0db6aff73c8678397132d5fe4 Mon Sep 17 00:00:00 2001 From: Abhinav Garg Date: Tue, 31 Mar 2020 23:49:43 -0400 Subject: [PATCH 1/5] Adding support for MWS Accounts API, to enable automation for E2 workspaces --- .gitignore | 1 + databricks_cli/accounts/__init__.py | 0 databricks_cli/accounts/api.py | 91 ++++++++++ databricks_cli/accounts/cli.py | 247 ++++++++++++++++++++++++++++ databricks_cli/cli.py | 2 + databricks_cli/click_types.py | 25 +++ databricks_cli/sdk/api_client.py | 23 ++- databricks_cli/sdk/service.py | 53 ++++++ 8 files changed, 439 insertions(+), 3 deletions(-) create mode 100644 databricks_cli/accounts/__init__.py create mode 100644 databricks_cli/accounts/api.py create mode 100644 databricks_cli/accounts/cli.py diff --git a/.gitignore b/.gitignore index d5e32c90..aaa3c355 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ venv .DS_Store .coverage .tox/ +.vscode/ diff --git a/databricks_cli/accounts/__init__.py b/databricks_cli/accounts/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/databricks_cli/accounts/api.py b/databricks_cli/accounts/api.py new file mode 100644 index 00000000..5ae4c6ae --- /dev/null +++ b/databricks_cli/accounts/api.py @@ -0,0 +1,91 @@ +"""Implement Databricks Accounts API, interfacing with the AccountsService.""" +# Databricks CLI +# Copyright 2017 Databricks, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"), except +# that the use of services to which certain application programming +# interfaces (each, an "API") connect requires that the user first obtain +# a license for the use of the APIs from Databricks, Inc. ("Databricks"), +# by creating an account at www.databricks.com and agreeing to either (a) +# the Community Edition Terms of Service, (b) the Databricks Terms of +# Service, or (c) another written agreement between Licensee and Databricks +# for the use of the APIs. +# +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +from databricks_cli.sdk import AccountsService + + +class AccountsApi(object): + """Implement the databricks '2.0/accounts' API Interface.""" + + def __init__(self, api_client): + self.client = AccountsService(api_client) + + def create_credentials(self, account_id, json): + """Create a new credentials object with AWS IAM role reference.""" + 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) + + def get_credentials(self, account_id, credentials_id): + """Get the credentials object with the given credentials id.""" + return self.client.get_credentials(account_id, credentials_id) + + def delete_credentials(self, account_id, credentials_id): + """Delete the credentials object for the given credentials id.""" + return self.client.delete_credentials(account_id, credentials_id) + + def create_storage_config(self, account_id, json): + """Create a new storage config object with AWS bucket reference.""" + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/storage-configurations" % (account_id) + return self.client.client.perform_query('POST', endpoint, data=json) + + def get_storage_config(self, account_id, storage_config_id): + """Get the storage config object with the given storage config id.""" + return self.client.get_storage_config(account_id, storage_config_id) + + def delete_storage_config(self, account_id, storage_config_id): + """Delete the storage config object for the given storage config id.""" + return self.client.delete_storage_config(account_id, storage_config_id) + + def create_network(self, account_id, json): + """Create a new network object with AWS network infrastructure reference.""" + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/networks" % (account_id) + return self.client.client.perform_query('POST', endpoint, data=json) + + def get_network(self, account_id, network_id): + """Get the network object with the given network id.""" + return self.client.get_network(account_id, network_id) + + def delete_network(self, account_id, network_id): + """Delete the network object for the given network id.""" + return self.client.delete_network(account_id, network_id) + + def create_workspace(self, account_id, json): + """Create a new workspace with required references.""" + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/workspaces" % (account_id) + return self.client.client.perform_query('POST', endpoint, data=json) + + def get_workspace(self, account_id, workspace_id): + """Get the workspace details with the given workspace id.""" + return self.client.get_workspace(account_id, workspace_id) + + def delete_workspace(self, account_id, workspace_id): + """Delete the workspace for the given workspace id.""" + return self.client.delete_workspace(account_id, workspace_id) \ No newline at end of file diff --git a/databricks_cli/accounts/cli.py b/databricks_cli/accounts/cli.py new file mode 100644 index 00000000..a9bd934d --- /dev/null +++ b/databricks_cli/accounts/cli.py @@ -0,0 +1,247 @@ +"""Provide the API methods for Databricks Accounts REST endpoint.""" +# Databricks CLI +# Copyright 2017 Databricks, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"), except +# that the use of services to which certain application programming +# interfaces (each, an "API") connect requires that the user first obtain +# a license for the use of the APIs from Databricks, Inc. ("Databricks"), +# by creating an account at www.databricks.com and agreeing to either (a) +# the Community Edition Terms of Service, (b) the Databricks Terms of +# Service, or (c) another written agreement between Licensee and Databricks +# for the use of the APIs. +# +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import click + +from databricks_cli.click_types import AccountIdClickType, CredentialsIdClickType, NetworkIdClickType, \ + WorkspaceIdClickType, JsonClickType +from databricks_cli.accounts.api import AccountsApi +from databricks_cli.utils import eat_exceptions, CONTEXT_SETTINGS, pretty_format, json_cli_base +from databricks_cli.configure.config import provide_api_client, profile_option, debug_option +from databricks_cli.version import print_version_callback, version + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Create a new credentials object with AWS IAM role reference.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option('--json-file', default=None, type=click.Path(), + help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/credentials.') +@click.option('--json', default=None, type=JsonClickType(), + help=JsonClickType.help('/api/2.0/accounts/{account_id}/credentials')) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def create_credentials_cli(api_client, account_id, json_file, json): + """Create a new credentials object with AWS IAM role reference.""" + json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_credentials(account_id, json)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get the credentials object with the given credentials id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--credentials-id", required=True) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def get_credentials_cli(api_client, account_id, credentials_id): + """Get the credentials object with the given credentials id.""" + content = AccountsApi(api_client).get_credentials(account_id, credentials_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Delete the credentials object for the given credentials id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--credentials-id", required=True) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def delete_credentials_cli(api_client, account_id, credentials_id): + """Delete the credentials object for the given credentials id.""" + content = AccountsApi(api_client).delete_credentials(account_id, credentials_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Create a new storage config object with AWS bucket reference.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option('--json-file', default=None, type=click.Path(), + help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/storage-configurations.') +@click.option('--json', default=None, type=JsonClickType(), + help=JsonClickType.help('/api/2.0/accounts/{account_id}/storage-configurations')) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def create_storage_config_cli(api_client, account_id, json_file, json): + """Create a new storage config object with AWS bucket reference.""" + json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_storage_config(account_id, json)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get the storage config object with the given storage config id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--storage-config-id", required=True) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def get_storage_config_cli(api_client, account_id, storage_config_id): + """Get the storage config object with the given storage config id.""" + content = AccountsApi(api_client).get_storage_config(account_id, storage_config_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Delete the storage config object for the given storage config id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--storage-config-id", required=True) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def delete_storage_config_cli(api_client, account_id, storage_config_id): + """Delete the storage config object for the given storage config id.""" + content = AccountsApi(api_client).delete_storage_config(account_id, storage_config_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Create a new network object with AWS network infrastructure reference.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option('--json-file', default=None, type=click.Path(), + help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/networks.') +@click.option('--json', default=None, type=JsonClickType(), + help=JsonClickType.help('/api/2.0/accounts/{account_id}/networks')) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def create_network_cli(api_client, account_id, json_file, json): + """Create a new network object with AWS network infrastructure reference.""" + json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_network(account_id, json)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get the network object with the given network id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--network-id", required=True) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def get_network_cli(api_client, account_id, network_id): + """Get the network object with the given network id.""" + content = AccountsApi(api_client).get_network(account_id, network_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Delete the network object for the given network id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--network-id", required=True) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def delete_network_cli(api_client, account_id, network_id): + """Delete the network object for the given network id.""" + content = AccountsApi(api_client).delete_network(account_id, network_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Create a new workspace with required references.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option('--json-file', default=None, type=click.Path(), + help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/workspaces.') +@click.option('--json', default=None, type=JsonClickType(), + help=JsonClickType.help('/api/2.0/accounts/{account_id}/workspaces')) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def create_workspace_cli(api_client, account_id, json_file, json): + """Create a new workspace with required references.""" + json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_workspace(account_id, json)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get the workspace details with the given workspace id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--workspace-id", required=True) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def get_workspace_cli(api_client, account_id, workspace_id): + """Get the workspace details with the given workspace id.""" + content = AccountsApi(api_client).get_workspace(account_id, workspace_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Delete the workspace for the given workspace id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--workspace-id", required=True) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def delete_workspace_cli(api_client, account_id, workspace_id): + """Delete the workspace for the given workspace id.""" + content = AccountsApi(api_client).delete_workspace(account_id, workspace_id) + click.echo(pretty_format(content)) + + +@click.group(context_settings=CONTEXT_SETTINGS, + short_help='Utility to interact with Databricks accounts.') +@click.option('--version', '-v', is_flag=True, callback=print_version_callback, + expose_value=False, is_eager=True, help=version) +@debug_option +@profile_option +@eat_exceptions +def accounts_group(): + """ + Utility to interact with Databricks accounts. + """ + pass + +accounts_group.add_command(create_credentials_cli, name="create-credentials") +accounts_group.add_command(get_credentials_cli, name="get-credentials") +accounts_group.add_command(delete_credentials_cli, name="delete-credentials") +accounts_group.add_command(create_storage_config_cli, name="create-storage-config") +accounts_group.add_command(get_storage_config_cli, name="get-storage-config") +accounts_group.add_command(delete_storage_config_cli, name="delete-storage-config") +accounts_group.add_command(create_network_cli, name="create-network") +accounts_group.add_command(get_network_cli, name="get-network") +accounts_group.add_command(delete_network_cli, name="delete-network") +accounts_group.add_command(create_workspace_cli, name="create-workspace") +accounts_group.add_command(get_workspace_cli, name="get-workspace") +accounts_group.add_command(delete_workspace_cli, name="delete-workspace") diff --git a/databricks_cli/cli.py b/databricks_cli/cli.py index 47bd2824..a611d074 100644 --- a/databricks_cli/cli.py +++ b/databricks_cli/cli.py @@ -37,6 +37,7 @@ from databricks_cli.stack.cli import stack_group from databricks_cli.groups.cli import groups_group from databricks_cli.instance_pools.cli import instance_pools_group +from databricks_cli.accounts.cli import accounts_group @click.group(context_settings=CONTEXT_SETTINGS) @@ -59,6 +60,7 @@ def cli(): cli.add_command(stack_group, name='stack') cli.add_command(groups_group, name='groups') cli.add_command(instance_pools_group, name="instance-pools") +cli.add_command(accounts_group, name="accounts") if __name__ == "__main__": cli() diff --git a/databricks_cli/click_types.py b/databricks_cli/click_types.py index 5759a7ae..456b2801 100644 --- a/databricks_cli/click_types.py +++ b/databricks_cli/click_types.py @@ -90,6 +90,31 @@ class SecretPrincipalClickType(ParamType): help = 'The name of the principal.' +class AccountIdClickType(ParamType): + name = 'ACCOUNT_ID' + help = 'Databricks Account Id' + + +class CredentialsIdClickType(ParamType): + name = 'CREDENTIALS_ID' + help = 'Databricks Workspace Credentials Id' + + +class StorageConfigIdClickType(ParamType): + name = 'STORAGE_CONFIG_ID' + help = 'Databricks Workspace Storage Configuration Id' + + +class NetworkIdClickType(ParamType): + name = 'NETWORK_ID' + help = 'Databricks Workspace Network Id' + + +class WorkspaceIdClickType(ParamType): + name = 'WORKSPACE_ID' + help = 'Databricks Workspace Id' + + class OneOfOption(Option): def __init__(self, *args, **kwargs): self.one_of = kwargs.pop('one_of') diff --git a/databricks_cli/sdk/api_client.py b/databricks_cli/sdk/api_client.py index d5870a6a..f504b543 100644 --- a/databricks_cli/sdk/api_client.py +++ b/databricks_cli/sdk/api_client.py @@ -93,6 +93,10 @@ def __init__(self, user=None, password=None, host=None, token=None, self.default_headers.update(user_agent) self.verify = verify + """Adding for Accounts API support""" + self.restful_methods = ['REST-GET', 'DELETE'] + self.accounts_url = "%s://%s/api/%s" % ("https", "accounts.cloud.databricks.com", apiVersion) + def close(self): """Close the client""" pass @@ -100,6 +104,13 @@ def close(self): # 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"): + path_specific_url = self.accounts_url + else: + path_specific_url = self.url + """set up connection and perform query""" if headers is None: headers = self.default_headers @@ -110,12 +121,18 @@ def perform_query(self, method, path, data = {}, headers = None): with warnings.catch_warnings(): warnings.simplefilter("ignore", exceptions.InsecureRequestWarning) - if method == 'GET': + if method in self.restful_methods: + restful_method = method + if method == 'REST-GET': + restful_method = 'GET' + resp = self.session.request(restful_method, path_specific_url + path, verify = self.verify, + headers = headers) + elif method == 'GET': translated_data = {k: _translate_boolean_to_query_param(data[k]) for k in data} - resp = self.session.request(method, self.url + path, params = translated_data, + resp = self.session.request(method, path_specific_url + path, params = translated_data, verify = self.verify, headers = headers) else: - resp = self.session.request(method, self.url + path, data = json.dumps(data), + resp = self.session.request(method, path_specific_url + path, data = json.dumps(data), verify = self.verify, headers = headers) try: resp.raise_for_status() diff --git a/databricks_cli/sdk/service.py b/databricks_cli/sdk/service.py index de769a34..85120f36 100644 --- a/databricks_cli/sdk/service.py +++ b/databricks_cli/sdk/service.py @@ -794,3 +794,56 @@ 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): + def __init__(self, client): + self.client = client + + def get_credentials(self, account_id, credentials_id, headers=None): + if account_id is None or credentials_id is None: + raise TypeError('Expected account_id and credentials_id') + endpoint = "/accounts/%s/credentials/%s" % (account_id, credentials_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + + def delete_credentials(self, account_id, credentials_id, headers=None): + if account_id is None or credentials_id is None: + raise TypeError('Expected account_id and credentials_id') + endpoint = "/accounts/%s/credentials/%s" % (account_id, credentials_id) + return self.client.perform_query('DELETE', endpoint, data={}, headers=headers) + + def get_storage_config(self, account_id, storage_config_id, headers=None): + if account_id is None or storage_config_id is None: + raise TypeError('Expected account_id and storage_config_id') + endpoint = "/accounts/%s/storage-configurations/%s" % (account_id, storage_config_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + + def delete_storage_config(self, account_id, storage_config_id, headers=None): + if account_id is None or storage_config_id is None: + raise TypeError('Expected account_id and storage_config_id') + endpoint = "/accounts/%s/storage-configurations/%s" % (account_id, storage_config_id) + return self.client.perform_query('DELETE', endpoint, data={}, headers=headers) + + def get_network(self, account_id, network_id, headers=None): + if account_id is None or network_id is None: + raise TypeError('Expected account_id and network_id') + endpoint = "/accounts/%s/networks/%s" % (account_id, network_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + + def delete_network(self, account_id, network_id, headers=None): + if account_id is None or network_id is None: + raise TypeError('Expected account_id and network_id') + endpoint = "/accounts/%s/networks/%s" % (account_id, network_id) + return self.client.perform_query('DELETE', endpoint, data={}, headers=headers) + + def get_workspace(self, account_id, workspace_id, headers=None): + if account_id is None or workspace_id is None: + raise TypeError('Expected account_id and workspace_id') + endpoint = "/accounts/%s/workspaces/%s" % (account_id, workspace_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + + def delete_workspace(self, account_id, workspace_id, headers=None): + if account_id is None or workspace_id is None: + raise TypeError('Expected account_id and workspace_id') + endpoint = "/accounts/%s/workspaces/%s" % (account_id, workspace_id) + return self.client.perform_query('DELETE', endpoint, data={}, headers=headers) \ No newline at end of file From 0dbff445f6b64881a9d85d3beebc752917d90d85 Mon Sep 17 00:00:00 2001 From: Abhinav Garg Date: Wed, 1 Apr 2020 15:31:11 -0400 Subject: [PATCH 2/5] Allowing AccountsApi to be used from non-CLI clients --- databricks_cli/accounts/__init__.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/databricks_cli/accounts/__init__.py b/databricks_cli/accounts/__init__.py index e69de29b..4f71e580 100644 --- a/databricks_cli/accounts/__init__.py +++ b/databricks_cli/accounts/__init__.py @@ -0,0 +1,24 @@ +# Databricks CLI +# Copyright 2017 Databricks, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"), except +# that the use of services to which certain application programming +# interfaces (each, an "API") connect requires that the user first obtain +# a license for the use of the APIs from Databricks, Inc. ("Databricks"), +# by creating an account at www.databricks.com and agreeing to either (a) +# the Community Edition Terms of Service, (b) the Databricks Terms of +# Service, or (c) another written agreement between Licensee and Databricks +# for the use of the APIs. +# +# You may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from .api import * From ae9838a58fb7d3406e386ea77ef46b5b638e1b0a Mon Sep 17 00:00:00 2001 From: Abhinav Garg Date: Sun, 12 Apr 2020 19:33:27 -0400 Subject: [PATCH 3/5] Adding support for customer managed key API and all other list all APIs --- databricks_cli/accounts/api.py | 57 ++++++++-- databricks_cli/accounts/cli.py | 202 ++++++++++++++++++++++++++++----- databricks_cli/click_types.py | 5 + databricks_cli/sdk/service.py | 50 +++++++- 4 files changed, 278 insertions(+), 36 deletions(-) diff --git a/databricks_cli/accounts/api.py b/databricks_cli/accounts/api.py index 5ae4c6ae..b4233f4f 100644 --- a/databricks_cli/accounts/api.py +++ b/databricks_cli/accounts/api.py @@ -31,61 +31,100 @@ def __init__(self, api_client): self.client = AccountsService(api_client) def create_credentials(self, account_id, json): - """Create a new credentials object with AWS IAM role reference.""" + """Create a new credentials object for the AWS IAM role reference.""" 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) def get_credentials(self, account_id, credentials_id): - """Get the credentials object with the given credentials id.""" + """Get the credentials object for the given credentials id.""" return self.client.get_credentials(account_id, credentials_id) + def list_credentials(self, account_id): + """Get all credentials objects for the given account.""" + return self.client.list_credentials(account_id) + def delete_credentials(self, account_id, credentials_id): """Delete the credentials object for the given credentials id.""" return self.client.delete_credentials(account_id, credentials_id) def create_storage_config(self, account_id, json): - """Create a new storage config object with AWS bucket reference.""" + """Create a new storage config object for the AWS bucket reference.""" if account_id is None: raise TypeError('Expected account_id') endpoint = "/accounts/%s/storage-configurations" % (account_id) return self.client.client.perform_query('POST', endpoint, data=json) def get_storage_config(self, account_id, storage_config_id): - """Get the storage config object with the given storage config id.""" + """Get the storage config object for the given storage config id.""" return self.client.get_storage_config(account_id, storage_config_id) + def list_storage_configs(self, account_id): + """Get all storage config objects for the given account.""" + return self.client.list_storage_configs(account_id) + def delete_storage_config(self, account_id, storage_config_id): """Delete the storage config object for the given storage config id.""" return self.client.delete_storage_config(account_id, storage_config_id) def create_network(self, account_id, json): - """Create a new network object with AWS network infrastructure reference.""" + """Create a new network object for the AWS network infrastructure reference.""" if account_id is None: raise TypeError('Expected account_id') endpoint = "/accounts/%s/networks" % (account_id) return self.client.client.perform_query('POST', endpoint, data=json) def get_network(self, account_id, network_id): - """Get the network object with the given network id.""" + """Get the network object for the given network id.""" return self.client.get_network(account_id, network_id) + def list_networks(self, account_id): + """Get all network objects for the given account.""" + return self.client.list_networks(account_id) + def delete_network(self, account_id, network_id): """Delete the network object for the given network id.""" return self.client.delete_network(account_id, network_id) + def create_customer_managed_key(self, account_id, json): + """Create a new customer managed key object for the AWS KMS key reference.""" + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/customer-managed-keys" % (account_id) + return self.client.client.perform_query('POST', endpoint, data=json) + + def get_customer_managed_key(self, account_id, customer_managed_key_id): + """Get the customer managed key object for the given customer managed key id.""" + return self.client.get_customer_managed_key(account_id, customer_managed_key_id) + + def list_customer_managed_keys(self, account_id): + """Get all customer managed key objects for the given account.""" + return self.client.list_customer_managed_keys(account_id) + def create_workspace(self, account_id, json): - """Create a new workspace with required references.""" + """Create a new workspace with the required references.""" if account_id is None: raise TypeError('Expected account_id') endpoint = "/accounts/%s/workspaces" % (account_id) return self.client.client.perform_query('POST', endpoint, data=json) def get_workspace(self, account_id, workspace_id): - """Get the workspace details with the given workspace id.""" + """Get the workspace details for the given workspace id.""" return self.client.get_workspace(account_id, workspace_id) + def list_workspaces(self, account_id): + """Get all workspaces for the given account.""" + return self.client.list_workspaces(account_id) + def delete_workspace(self, account_id, workspace_id): """Delete the workspace for the given workspace id.""" - return self.client.delete_workspace(account_id, workspace_id) \ No newline at end of file + return self.client.delete_workspace(account_id, workspace_id) + + def list_customer_managed_key_hist_by_workspace(self, account_id, workspace_id): + """Get the history of customer managed key objects for the given workspace id.""" + return self.client.list_customer_managed_key_hist_by_workspace(account_id, workspace_id) + + def list_customer_managed_key_hist_by_account(self, account_id): + """Get the history of customer managed key objects for the given account.""" + return self.client.list_customer_managed_key_hist_by_account(account_id) \ No newline at end of file diff --git a/databricks_cli/accounts/cli.py b/databricks_cli/accounts/cli.py index a9bd934d..5f542dde 100644 --- a/databricks_cli/accounts/cli.py +++ b/databricks_cli/accounts/cli.py @@ -24,8 +24,8 @@ import click -from databricks_cli.click_types import AccountIdClickType, CredentialsIdClickType, NetworkIdClickType, \ - WorkspaceIdClickType, JsonClickType +from databricks_cli.click_types import AccountIdClickType, CredentialsIdClickType, StorageConfigIdClickType, \ + NetworkIdClickType, CustomerManagedKeyIdClickType, WorkspaceIdClickType, JsonClickType from databricks_cli.accounts.api import AccountsApi from databricks_cli.utils import eat_exceptions, CONTEXT_SETTINGS, pretty_format, json_cli_base from databricks_cli.configure.config import provide_api_client, profile_option, debug_option @@ -33,7 +33,7 @@ @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new credentials object with AWS IAM role reference.") + short_help="Create a new credentials object for the AWS IAM role reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), @@ -45,30 +45,46 @@ @eat_exceptions @provide_api_client def create_credentials_cli(api_client, account_id, json_file, json): - """Create a new credentials object with AWS IAM role reference.""" + """Create a new credentials object for the AWS IAM role reference.""" json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_credentials(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the credentials object with the given credentials id.") + short_help="Get the credentials object for the given credentials id.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) -@click.option("--credentials-id", required=True) +@click.option("--credentials-id", required=True, type=CredentialsIdClickType(), + help=CredentialsIdClickType.help) @debug_option @profile_option @eat_exceptions @provide_api_client def get_credentials_cli(api_client, account_id, credentials_id): - """Get the credentials object with the given credentials id.""" + """Get the credentials object for the given credentials id.""" content = AccountsApi(api_client).get_credentials(account_id, credentials_id) click.echo(pretty_format(content)) +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get all credentials objects for the given account.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def list_credentials_cli(api_client, account_id): + """Get all credentials objects for the given account.""" + content = AccountsApi(api_client).list_credentials(account_id) + click.echo(pretty_format(content)) + + @click.command(context_settings=CONTEXT_SETTINGS, short_help="Delete the credentials object for the given credentials id.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) -@click.option("--credentials-id", required=True) +@click.option("--credentials-id", required=True, type=CredentialsIdClickType(), + help=CredentialsIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -80,7 +96,7 @@ def delete_credentials_cli(api_client, account_id, credentials_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new storage config object with AWS bucket reference.") + short_help="Create a new storage config object for the AWS bucket reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), @@ -92,30 +108,46 @@ def delete_credentials_cli(api_client, account_id, credentials_id): @eat_exceptions @provide_api_client def create_storage_config_cli(api_client, account_id, json_file, json): - """Create a new storage config object with AWS bucket reference.""" + """Create a new storage config object for the AWS bucket reference.""" json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_storage_config(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the storage config object with the given storage config id.") + short_help="Get the storage config object for the given storage config id.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) -@click.option("--storage-config-id", required=True) +@click.option("--storage-config-id", required=True, type=StorageConfigIdClickType(), + help=StorageConfigIdClickType.help) @debug_option @profile_option @eat_exceptions @provide_api_client def get_storage_config_cli(api_client, account_id, storage_config_id): - """Get the storage config object with the given storage config id.""" + """Get the storage config object for the given storage config id.""" content = AccountsApi(api_client).get_storage_config(account_id, storage_config_id) click.echo(pretty_format(content)) +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get all storage config objects for the given account.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def list_storage_configs_cli(api_client, account_id): + """Get all storage config objects for the given account.""" + content = AccountsApi(api_client).list_storage_configs(account_id) + click.echo(pretty_format(content)) + + @click.command(context_settings=CONTEXT_SETTINGS, short_help="Delete the storage config object for the given storage config id.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) -@click.option("--storage-config-id", required=True) +@click.option("--storage-config-id", required=True, type=StorageConfigIdClickType(), + help=StorageConfigIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -127,7 +159,7 @@ def delete_storage_config_cli(api_client, account_id, storage_config_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new network object with AWS network infrastructure reference.") + short_help="Create a new network object for the AWS network infrastructure reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), @@ -139,30 +171,46 @@ def delete_storage_config_cli(api_client, account_id, storage_config_id): @eat_exceptions @provide_api_client def create_network_cli(api_client, account_id, json_file, json): - """Create a new network object with AWS network infrastructure reference.""" + """Create a new network object for the AWS network infrastructure reference.""" json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_network(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the network object with the given network id.") + short_help="Get the network object for the given network id.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) -@click.option("--network-id", required=True) +@click.option("--network-id", required=True, type=NetworkIdClickType(), + help=NetworkIdClickType.help) @debug_option @profile_option @eat_exceptions @provide_api_client def get_network_cli(api_client, account_id, network_id): - """Get the network object with the given network id.""" + """Get the network object for the given network id.""" content = AccountsApi(api_client).get_network(account_id, network_id) click.echo(pretty_format(content)) +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get all network objects for the given account.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def list_networks_cli(api_client, account_id): + """Get all network objects for the given account.""" + content = AccountsApi(api_client).list_networks(account_id) + click.echo(pretty_format(content)) + + @click.command(context_settings=CONTEXT_SETTINGS, short_help="Delete the network object for the given network id.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) -@click.option("--network-id", required=True) +@click.option("--network-id", required=True, type=NetworkIdClickType(), + help=NetworkIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -174,7 +222,54 @@ def delete_network_cli(api_client, account_id, network_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new workspace with required references.") + short_help="Create a new customer managed key object for the AWS KMS key reference.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option('--json-file', default=None, type=click.Path(), + help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/customer-managed-keys.') +@click.option('--json', default=None, type=JsonClickType(), + help=JsonClickType.help('/api/2.0/accounts/{account_id}/customer-managed-keys')) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def create_customer_managed_key_cli(api_client, account_id, json_file, json): + """Create a new customer managed key object for the AWS KMS key reference.""" + json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_customer_managed_key(account_id, json)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get the customer managed key object for the given customer managed key id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--customer-managed-key-id", required=True, type=CustomerManagedKeyIdClickType(), + help=CustomerManagedKeyIdClickType.help) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def get_customer_managed_key_cli(api_client, account_id, customer_managed_key_id): + """Get the customer managed key object for the given customer managed key id.""" + content = AccountsApi(api_client).get_customer_managed_key(account_id, customer_managed_key_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get all customer managed key objects for the given account.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def list_customer_managed_keys_cli(api_client, account_id): + """Get all customer managed key objects for the given account.""" + content = AccountsApi(api_client).list_customer_managed_keys(account_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Create a new workspace with the required references.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), @@ -186,30 +281,46 @@ def delete_network_cli(api_client, account_id, network_id): @eat_exceptions @provide_api_client def create_workspace_cli(api_client, account_id, json_file, json): - """Create a new workspace with required references.""" + """Create a new workspace with the required references.""" json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_workspace(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the workspace details with the given workspace id.") + short_help="Get the workspace details for the given workspace id.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) -@click.option("--workspace-id", required=True) +@click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), + help=WorkspaceIdClickType.help) @debug_option @profile_option @eat_exceptions @provide_api_client def get_workspace_cli(api_client, account_id, workspace_id): - """Get the workspace details with the given workspace id.""" + """Get the workspace details for the given workspace id.""" content = AccountsApi(api_client).get_workspace(account_id, workspace_id) click.echo(pretty_format(content)) +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get all workspaces for the given account.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def list_workspaces_cli(api_client, account_id): + """Get all workspaces for the given account.""" + content = AccountsApi(api_client).list_workspaces(account_id) + click.echo(pretty_format(content)) + + @click.command(context_settings=CONTEXT_SETTINGS, short_help="Delete the workspace for the given workspace id.") @click.option('--account-id', required=True, type=AccountIdClickType(), help=AccountIdClickType.help) -@click.option("--workspace-id", required=True) +@click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), + help=WorkspaceIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -220,6 +331,36 @@ def delete_workspace_cli(api_client, account_id, workspace_id): click.echo(pretty_format(content)) +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get the history of customer managed key objects for the given workspace id.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), + help=WorkspaceIdClickType.help) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def list_customer_managed_key_hist_by_workspace_cli(api_client, account_id, workspace_id): + """Get the history of customer managed key objects for the given workspace id.""" + content = AccountsApi(api_client).list_customer_managed_key_hist_by_workspace(account_id, workspace_id) + click.echo(pretty_format(content)) + + +@click.command(context_settings=CONTEXT_SETTINGS, + short_help="Get the history of customer managed key objects for the given account.") +@click.option('--account-id', required=True, type=AccountIdClickType(), + help=AccountIdClickType.help) +@debug_option +@profile_option +@eat_exceptions +@provide_api_client +def list_customer_managed_key_hist_by_account_cli(api_client, account_id): + """Get the history of customer managed key objects for the given account.""" + content = AccountsApi(api_client).list_customer_managed_key_hist_by_account(account_id) + click.echo(pretty_format(content)) + + @click.group(context_settings=CONTEXT_SETTINGS, short_help='Utility to interact with Databricks accounts.') @click.option('--version', '-v', is_flag=True, callback=print_version_callback, @@ -235,13 +376,22 @@ def accounts_group(): accounts_group.add_command(create_credentials_cli, name="create-credentials") accounts_group.add_command(get_credentials_cli, name="get-credentials") +accounts_group.add_command(list_credentials_cli, name="list-credentials") accounts_group.add_command(delete_credentials_cli, name="delete-credentials") accounts_group.add_command(create_storage_config_cli, name="create-storage-config") accounts_group.add_command(get_storage_config_cli, name="get-storage-config") +accounts_group.add_command(list_storage_configs_cli, name="list-storage-config") accounts_group.add_command(delete_storage_config_cli, name="delete-storage-config") accounts_group.add_command(create_network_cli, name="create-network") accounts_group.add_command(get_network_cli, name="get-network") +accounts_group.add_command(list_networks_cli, name="list-network") accounts_group.add_command(delete_network_cli, name="delete-network") +accounts_group.add_command(create_customer_managed_key_cli, name="create-cust-managed-key") +accounts_group.add_command(get_customer_managed_key_cli, name="get-cust-managed-key") +accounts_group.add_command(list_customer_managed_keys_cli, name="list-cust-managed-key") accounts_group.add_command(create_workspace_cli, name="create-workspace") accounts_group.add_command(get_workspace_cli, name="get-workspace") +accounts_group.add_command(list_workspaces_cli, name="list-workspace") accounts_group.add_command(delete_workspace_cli, name="delete-workspace") +accounts_group.add_command(list_customer_managed_key_hist_by_workspace_cli, name="list-cust-managed-key-hist-by-ws") +accounts_group.add_command(list_customer_managed_key_hist_by_account_cli, name="list-cust-managed-key-hist-by-acc") diff --git a/databricks_cli/click_types.py b/databricks_cli/click_types.py index 456b2801..93ba3858 100644 --- a/databricks_cli/click_types.py +++ b/databricks_cli/click_types.py @@ -110,6 +110,11 @@ class NetworkIdClickType(ParamType): help = 'Databricks Workspace Network Id' +class CustomerManagedKeyIdClickType(ParamType): + name = 'CUSTOMER_MANAGED_KEY_ID' + help = 'Databricks Workspace Customer Managed Key Id' + + class WorkspaceIdClickType(ParamType): name = 'WORKSPACE_ID' help = 'Databricks Workspace Id' diff --git a/databricks_cli/sdk/service.py b/databricks_cli/sdk/service.py index 85120f36..99271c13 100644 --- a/databricks_cli/sdk/service.py +++ b/databricks_cli/sdk/service.py @@ -806,6 +806,12 @@ def get_credentials(self, account_id, credentials_id, headers=None): endpoint = "/accounts/%s/credentials/%s" % (account_id, credentials_id) return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + def list_credentials(self, account_id, headers=None): + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/credentials" % (account_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + def delete_credentials(self, account_id, credentials_id, headers=None): if account_id is None or credentials_id is None: raise TypeError('Expected account_id and credentials_id') @@ -818,6 +824,12 @@ def get_storage_config(self, account_id, storage_config_id, headers=None): endpoint = "/accounts/%s/storage-configurations/%s" % (account_id, storage_config_id) return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + def list_storage_configs(self, account_id, headers=None): + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/storage-configurations" % (account_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + def delete_storage_config(self, account_id, storage_config_id, headers=None): if account_id is None or storage_config_id is None: raise TypeError('Expected account_id and storage_config_id') @@ -829,6 +841,12 @@ def get_network(self, account_id, network_id, headers=None): raise TypeError('Expected account_id and network_id') endpoint = "/accounts/%s/networks/%s" % (account_id, network_id) return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + + def list_networks(self, account_id, headers=None): + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/networks" % (account_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) def delete_network(self, account_id, network_id, headers=None): if account_id is None or network_id is None: @@ -836,14 +854,44 @@ def delete_network(self, account_id, network_id, headers=None): endpoint = "/accounts/%s/networks/%s" % (account_id, network_id) return self.client.perform_query('DELETE', endpoint, data={}, headers=headers) + def get_customer_managed_key(self, account_id, customer_managed_key_id, headers=None): + if account_id is None or customer_managed_key_id is None: + raise TypeError('Expected account_id and customer_managed_key_id') + endpoint = "/accounts/%s/customer-managed-keys/%s" % (account_id, customer_managed_key_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + + def list_customer_managed_keys(self, account_id, headers=None): + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/customer-managed-keys" % (account_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + def get_workspace(self, account_id, workspace_id, headers=None): if account_id is None or workspace_id is None: raise TypeError('Expected account_id and workspace_id') endpoint = "/accounts/%s/workspaces/%s" % (account_id, workspace_id) return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + def list_workspaces(self, account_id, headers=None): + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/workspaces" % (account_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + def delete_workspace(self, account_id, workspace_id, headers=None): if account_id is None or workspace_id is None: raise TypeError('Expected account_id and workspace_id') endpoint = "/accounts/%s/workspaces/%s" % (account_id, workspace_id) - return self.client.perform_query('DELETE', endpoint, data={}, headers=headers) \ No newline at end of file + return self.client.perform_query('DELETE', endpoint, data={}, headers=headers) + + def list_customer_managed_key_hist_by_workspace(self, account_id, workspace_id, headers=None): + if account_id is None or workspace_id is None: + raise TypeError('Expected account_id and workspace_id') + endpoint = "/accounts/%s/workspaces/%s/customer-managed-key-history" % (account_id, workspace_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) + + def list_customer_managed_key_hist_by_account(self, account_id, headers=None): + if account_id is None: + raise TypeError('Expected account_id') + endpoint = "/accounts/%s/customer-managed-key-history" % (account_id) + return self.client.perform_query('REST-GET', endpoint, data={}, headers=headers) \ No newline at end of file From f11c7e5efa2e881ec8ebf43d5a980cc67d753c57 Mon Sep 17 00:00:00 2001 From: Abhinav Garg Date: Mon, 11 May 2020 20:47:02 -0400 Subject: [PATCH 4/5] Making formatting changes to fix the pylint related errors from the Travis CI build --- databricks_cli/accounts/__init__.py | 2 - databricks_cli/accounts/api.py | 2 +- databricks_cli/accounts/cli.py | 159 +++++++++++++++------------- 3 files changed, 86 insertions(+), 77 deletions(-) diff --git a/databricks_cli/accounts/__init__.py b/databricks_cli/accounts/__init__.py index 4f71e580..b0c9feac 100644 --- a/databricks_cli/accounts/__init__.py +++ b/databricks_cli/accounts/__init__.py @@ -20,5 +20,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -from .api import * diff --git a/databricks_cli/accounts/api.py b/databricks_cli/accounts/api.py index b4233f4f..e6273487 100644 --- a/databricks_cli/accounts/api.py +++ b/databricks_cli/accounts/api.py @@ -127,4 +127,4 @@ def list_customer_managed_key_hist_by_workspace(self, account_id, workspace_id): def list_customer_managed_key_hist_by_account(self, account_id): """Get the history of customer managed key objects for the given account.""" - return self.client.list_customer_managed_key_hist_by_account(account_id) \ No newline at end of file + return self.client.list_customer_managed_key_hist_by_account(account_id) diff --git a/databricks_cli/accounts/cli.py b/databricks_cli/accounts/cli.py index 5f542dde..8314445c 100644 --- a/databricks_cli/accounts/cli.py +++ b/databricks_cli/accounts/cli.py @@ -24,8 +24,9 @@ import click -from databricks_cli.click_types import AccountIdClickType, CredentialsIdClickType, StorageConfigIdClickType, \ - NetworkIdClickType, CustomerManagedKeyIdClickType, WorkspaceIdClickType, JsonClickType +from databricks_cli.click_types import AccountIdClickType, CredentialsIdClickType, \ + StorageConfigIdClickType, NetworkIdClickType, CustomerManagedKeyIdClickType, \ + WorkspaceIdClickType, JsonClickType from databricks_cli.accounts.api import AccountsApi from databricks_cli.utils import eat_exceptions, CONTEXT_SETTINGS, pretty_format, json_cli_base from databricks_cli.configure.config import provide_api_client, profile_option, debug_option @@ -33,28 +34,29 @@ @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new credentials object for the AWS IAM role reference.") + short_help="Create a new credentials object for the AWS IAM role reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/credentials.') + help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/credentials.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/credentials')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/credentials')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_credentials_cli(api_client, account_id, json_file, json): """Create a new credentials object for the AWS IAM role reference.""" - json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_credentials(account_id, json)) + json_cli_base(json_file, json, + lambda json: AccountsApi(api_client).create_credentials(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the credentials object for the given credentials id.") + short_help="Get the credentials object for the given credentials id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--credentials-id", required=True, type=CredentialsIdClickType(), - help=CredentialsIdClickType.help) + help=CredentialsIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -66,9 +68,9 @@ def get_credentials_cli(api_client, account_id, credentials_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all credentials objects for the given account.") + short_help="Get all credentials objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -80,11 +82,11 @@ def list_credentials_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Delete the credentials object for the given credentials id.") + short_help="Delete the credentials object for the given credentials id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--credentials-id", required=True, type=CredentialsIdClickType(), - help=CredentialsIdClickType.help) + help=CredentialsIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -96,28 +98,30 @@ def delete_credentials_cli(api_client, account_id, credentials_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new storage config object for the AWS bucket reference.") + short_help="Create a new storage config object for the AWS bucket reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/storage-configurations.') + help='File containing JSON request to POST to \ + /api/2.0/accounts/{account_id}/storage-configurations.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/storage-configurations')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/storage-configurations')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_storage_config_cli(api_client, account_id, json_file, json): """Create a new storage config object for the AWS bucket reference.""" - json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_storage_config(account_id, json)) + json_cli_base(json_file, json, + lambda json: AccountsApi(api_client).create_storage_config(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the storage config object for the given storage config id.") + short_help="Get the storage config object for the given storage config id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--storage-config-id", required=True, type=StorageConfigIdClickType(), - help=StorageConfigIdClickType.help) + help=StorageConfigIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -129,9 +133,9 @@ def get_storage_config_cli(api_client, account_id, storage_config_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all storage config objects for the given account.") + short_help="Get all storage config objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -143,11 +147,11 @@ def list_storage_configs_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Delete the storage config object for the given storage config id.") + short_help="Delete the storage config object for the given storage config id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--storage-config-id", required=True, type=StorageConfigIdClickType(), - help=StorageConfigIdClickType.help) + help=StorageConfigIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -159,28 +163,29 @@ def delete_storage_config_cli(api_client, account_id, storage_config_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new network object for the AWS network infrastructure reference.") + short_help="Create a new network object for the AWS network infrastructure reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/networks.') + help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/networks.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/networks')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/networks')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_network_cli(api_client, account_id, json_file, json): """Create a new network object for the AWS network infrastructure reference.""" - json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_network(account_id, json)) + json_cli_base(json_file, json, + lambda json: AccountsApi(api_client).create_network(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the network object for the given network id.") + short_help="Get the network object for the given network id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--network-id", required=True, type=NetworkIdClickType(), - help=NetworkIdClickType.help) + help=NetworkIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -192,9 +197,9 @@ def get_network_cli(api_client, account_id, network_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all network objects for the given account.") + short_help="Get all network objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -206,11 +211,11 @@ def list_networks_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Delete the network object for the given network id.") + short_help="Delete the network object for the given network id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--network-id", required=True, type=NetworkIdClickType(), - help=NetworkIdClickType.help) + help=NetworkIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -222,28 +227,30 @@ def delete_network_cli(api_client, account_id, network_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new customer managed key object for the AWS KMS key reference.") + short_help="Create a new customer managed key object for the AWS KMS key reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/customer-managed-keys.') + help='File containing JSON request to POST to \ + /api/2.0/accounts/{account_id}/customer-managed-keys.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/customer-managed-keys')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/customer-managed-keys')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_customer_managed_key_cli(api_client, account_id, json_file, json): """Create a new customer managed key object for the AWS KMS key reference.""" - json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_customer_managed_key(account_id, json)) + json_cli_base(json_file, json, + lambda json: AccountsApi(api_client).create_customer_managed_key(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the customer managed key object for the given customer managed key id.") + short_help="Get the customer managed key object for the given customer managed key id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--customer-managed-key-id", required=True, type=CustomerManagedKeyIdClickType(), - help=CustomerManagedKeyIdClickType.help) + help=CustomerManagedKeyIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -255,9 +262,9 @@ def get_customer_managed_key_cli(api_client, account_id, customer_managed_key_id @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all customer managed key objects for the given account.") + short_help="Get all customer managed key objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -269,28 +276,29 @@ def list_customer_managed_keys_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new workspace with the required references.") + short_help="Create a new workspace with the required references.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/workspaces.') + help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/workspaces.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/workspaces')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/workspaces')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_workspace_cli(api_client, account_id, json_file, json): """Create a new workspace with the required references.""" - json_cli_base(json_file, json, lambda json: AccountsApi(api_client).create_workspace(account_id, json)) + json_cli_base(json_file, json, + lambda json: AccountsApi(api_client).create_workspace(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the workspace details for the given workspace id.") + short_help="Get the workspace details for the given workspace id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), - help=WorkspaceIdClickType.help) + help=WorkspaceIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -302,9 +310,9 @@ def get_workspace_cli(api_client, account_id, workspace_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all workspaces for the given account.") + short_help="Get all workspaces for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -316,11 +324,11 @@ def list_workspaces_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Delete the workspace for the given workspace id.") + short_help="Delete the workspace for the given workspace id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), - help=WorkspaceIdClickType.help) + help=WorkspaceIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -332,25 +340,26 @@ def delete_workspace_cli(api_client, account_id, workspace_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the history of customer managed key objects for the given workspace id.") + short_help="Get the history of customer managed key objects for the given workspace id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), - help=WorkspaceIdClickType.help) + help=WorkspaceIdClickType.help) @debug_option @profile_option @eat_exceptions @provide_api_client def list_customer_managed_key_hist_by_workspace_cli(api_client, account_id, workspace_id): """Get the history of customer managed key objects for the given workspace id.""" - content = AccountsApi(api_client).list_customer_managed_key_hist_by_workspace(account_id, workspace_id) + content = AccountsApi(api_client). \ + list_customer_managed_key_hist_by_workspace(account_id, workspace_id) click.echo(pretty_format(content)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the history of customer managed key objects for the given account.") + short_help="Get the history of customer managed key objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -362,9 +371,9 @@ def list_customer_managed_key_hist_by_account_cli(api_client, account_id): @click.group(context_settings=CONTEXT_SETTINGS, - short_help='Utility to interact with Databricks accounts.') + short_help='Utility to interact with Databricks accounts.') @click.option('--version', '-v', is_flag=True, callback=print_version_callback, - expose_value=False, is_eager=True, help=version) + expose_value=False, is_eager=True, help=version) @debug_option @profile_option @eat_exceptions @@ -393,5 +402,7 @@ def accounts_group(): accounts_group.add_command(get_workspace_cli, name="get-workspace") accounts_group.add_command(list_workspaces_cli, name="list-workspace") accounts_group.add_command(delete_workspace_cli, name="delete-workspace") -accounts_group.add_command(list_customer_managed_key_hist_by_workspace_cli, name="list-cust-managed-key-hist-by-ws") -accounts_group.add_command(list_customer_managed_key_hist_by_account_cli, name="list-cust-managed-key-hist-by-acc") +accounts_group.add_command(list_customer_managed_key_hist_by_workspace_cli, + name="list-cust-managed-key-hist-by-ws") +accounts_group.add_command(list_customer_managed_key_hist_by_account_cli, + name="list-cust-managed-key-hist-by-acc") From 3ebe8d864a3e81f12b39e942e1f054340acfb713 Mon Sep 17 00:00:00 2001 From: Abhinav Garg Date: Mon, 11 May 2020 21:34:10 -0400 Subject: [PATCH 5/5] Making further formatting changes to accounts/cli.py to fix the pylint related errors from the Travis CI build. Tested this locally now. --- databricks_cli/accounts/cli.py | 164 +++++++++++++++++---------------- 1 file changed, 84 insertions(+), 80 deletions(-) diff --git a/databricks_cli/accounts/cli.py b/databricks_cli/accounts/cli.py index 8314445c..a9832227 100644 --- a/databricks_cli/accounts/cli.py +++ b/databricks_cli/accounts/cli.py @@ -34,29 +34,30 @@ @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new credentials object for the AWS IAM role reference.") + short_help="Create a credentials object for the AWS IAM role reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/credentials.') + help='File containing JSON request to POST to \ + /api/2.0/accounts/{account_id}/credentials.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/credentials')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/credentials')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_credentials_cli(api_client, account_id, json_file, json): - """Create a new credentials object for the AWS IAM role reference.""" + """Create a credentials object for the AWS IAM role reference.""" json_cli_base(json_file, json, - lambda json: AccountsApi(api_client).create_credentials(account_id, json)) + lambda json: AccountsApi(api_client).create_credentials(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the credentials object for the given credentials id.") + short_help="Get the credentials object for the given credentials id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--credentials-id", required=True, type=CredentialsIdClickType(), - help=CredentialsIdClickType.help) + help=CredentialsIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -68,9 +69,9 @@ def get_credentials_cli(api_client, account_id, credentials_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all credentials objects for the given account.") + short_help="Get all credentials objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -82,11 +83,11 @@ def list_credentials_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Delete the credentials object for the given credentials id.") + short_help="Delete the credentials object for the given credentials id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--credentials-id", required=True, type=CredentialsIdClickType(), - help=CredentialsIdClickType.help) + help=CredentialsIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -98,30 +99,30 @@ def delete_credentials_cli(api_client, account_id, credentials_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new storage config object for the AWS bucket reference.") + short_help="Create a storage config object for the AWS bucket reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to \ - /api/2.0/accounts/{account_id}/storage-configurations.') + help='File containing JSON request to POST to \ + /api/2.0/accounts/{account_id}/storage-configurations.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/storage-configurations')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/storage-configurations')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_storage_config_cli(api_client, account_id, json_file, json): - """Create a new storage config object for the AWS bucket reference.""" + """Create a storage config object for the AWS bucket reference.""" json_cli_base(json_file, json, - lambda json: AccountsApi(api_client).create_storage_config(account_id, json)) + lambda json: AccountsApi(api_client).create_storage_config(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the storage config object for the given storage config id.") + short_help="Get the storage config object for the given storage config id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--storage-config-id", required=True, type=StorageConfigIdClickType(), - help=StorageConfigIdClickType.help) + help=StorageConfigIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -133,9 +134,9 @@ def get_storage_config_cli(api_client, account_id, storage_config_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all storage config objects for the given account.") + short_help="Get all storage config objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -147,11 +148,11 @@ def list_storage_configs_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Delete the storage config object for the given storage config id.") + short_help="Delete the storage config object for the given storage config id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--storage-config-id", required=True, type=StorageConfigIdClickType(), - help=StorageConfigIdClickType.help) + help=StorageConfigIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -163,29 +164,30 @@ def delete_storage_config_cli(api_client, account_id, storage_config_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new network object for the AWS network infrastructure reference.") + short_help="Create a network object for the AWS network infrastructure reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/networks.') + help='File containing JSON request to POST to \ + /api/2.0/accounts/{account_id}/networks.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/networks')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/networks')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_network_cli(api_client, account_id, json_file, json): - """Create a new network object for the AWS network infrastructure reference.""" + """Create a network object for the AWS network infrastructure reference.""" json_cli_base(json_file, json, - lambda json: AccountsApi(api_client).create_network(account_id, json)) + lambda json: AccountsApi(api_client).create_network(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the network object for the given network id.") + short_help="Get the network object for the given network id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--network-id", required=True, type=NetworkIdClickType(), - help=NetworkIdClickType.help) + help=NetworkIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -197,9 +199,9 @@ def get_network_cli(api_client, account_id, network_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all network objects for the given account.") + short_help="Get all network objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -211,11 +213,11 @@ def list_networks_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Delete the network object for the given network id.") + short_help="Delete the network object for the given network id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--network-id", required=True, type=NetworkIdClickType(), - help=NetworkIdClickType.help) + help=NetworkIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -227,30 +229,31 @@ def delete_network_cli(api_client, account_id, network_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new customer managed key object for the AWS KMS key reference.") + short_help="Create a customer managed key object for the AWS KMS key reference.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to \ - /api/2.0/accounts/{account_id}/customer-managed-keys.') + help='File containing JSON request to POST to \ + /api/2.0/accounts/{account_id}/customer-managed-keys.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/customer-managed-keys')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/customer-managed-keys')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_customer_managed_key_cli(api_client, account_id, json_file, json): - """Create a new customer managed key object for the AWS KMS key reference.""" + """Create a customer managed key object for the AWS KMS key reference.""" json_cli_base(json_file, json, - lambda json: AccountsApi(api_client).create_customer_managed_key(account_id, json)) + lambda json: AccountsApi(api_client). + create_customer_managed_key(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the customer managed key object for the given customer managed key id.") + short_help="Get customer managed key object for the given customer managed key id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--customer-managed-key-id", required=True, type=CustomerManagedKeyIdClickType(), - help=CustomerManagedKeyIdClickType.help) + help=CustomerManagedKeyIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -262,9 +265,9 @@ def get_customer_managed_key_cli(api_client, account_id, customer_managed_key_id @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all customer managed key objects for the given account.") + short_help="Get all customer managed key objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -276,29 +279,30 @@ def list_customer_managed_keys_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Create a new workspace with the required references.") + short_help="Create a workspace with the required references.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option('--json-file', default=None, type=click.Path(), - help='File containing JSON request to POST to /api/2.0/accounts/{account_id}/workspaces.') + help='File containing JSON request to POST to \ + /api/2.0/accounts/{account_id}/workspaces.') @click.option('--json', default=None, type=JsonClickType(), - help=JsonClickType.help('/api/2.0/accounts/{account_id}/workspaces')) + help=JsonClickType.help('/api/2.0/accounts/{account_id}/workspaces')) @debug_option @profile_option @eat_exceptions @provide_api_client def create_workspace_cli(api_client, account_id, json_file, json): - """Create a new workspace with the required references.""" + """Create a workspace with the required references.""" json_cli_base(json_file, json, - lambda json: AccountsApi(api_client).create_workspace(account_id, json)) + lambda json: AccountsApi(api_client).create_workspace(account_id, json)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the workspace details for the given workspace id.") + short_help="Get the workspace details for the given workspace id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), - help=WorkspaceIdClickType.help) + help=WorkspaceIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -310,9 +314,9 @@ def get_workspace_cli(api_client, account_id, workspace_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get all workspaces for the given account.") + short_help="Get all workspaces for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -324,11 +328,11 @@ def list_workspaces_cli(api_client, account_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Delete the workspace for the given workspace id.") + short_help="Delete the workspace for the given workspace id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), - help=WorkspaceIdClickType.help) + help=WorkspaceIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -340,11 +344,11 @@ def delete_workspace_cli(api_client, account_id, workspace_id): @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the history of customer managed key objects for the given workspace id.") + short_help="Get history of customer managed key objects for the given workspace id.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @click.option("--workspace-id", required=True, type=WorkspaceIdClickType(), - help=WorkspaceIdClickType.help) + help=WorkspaceIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -352,14 +356,14 @@ def delete_workspace_cli(api_client, account_id, workspace_id): def list_customer_managed_key_hist_by_workspace_cli(api_client, account_id, workspace_id): """Get the history of customer managed key objects for the given workspace id.""" content = AccountsApi(api_client). \ - list_customer_managed_key_hist_by_workspace(account_id, workspace_id) + list_customer_managed_key_hist_by_workspace(account_id, workspace_id) click.echo(pretty_format(content)) @click.command(context_settings=CONTEXT_SETTINGS, - short_help="Get the history of customer managed key objects for the given account.") + short_help="Get the history of customer managed key objects for the given account.") @click.option('--account-id', required=True, type=AccountIdClickType(), - help=AccountIdClickType.help) + help=AccountIdClickType.help) @debug_option @profile_option @eat_exceptions @@ -371,9 +375,9 @@ def list_customer_managed_key_hist_by_account_cli(api_client, account_id): @click.group(context_settings=CONTEXT_SETTINGS, - short_help='Utility to interact with Databricks accounts.') + short_help='Utility to interact with Databricks accounts.') @click.option('--version', '-v', is_flag=True, callback=print_version_callback, - expose_value=False, is_eager=True, help=version) + expose_value=False, is_eager=True, help=version) @debug_option @profile_option @eat_exceptions @@ -381,7 +385,7 @@ def accounts_group(): """ Utility to interact with Databricks accounts. """ - pass + accounts_group.add_command(create_credentials_cli, name="create-credentials") accounts_group.add_command(get_credentials_cli, name="get-credentials") @@ -403,6 +407,6 @@ def accounts_group(): accounts_group.add_command(list_workspaces_cli, name="list-workspace") accounts_group.add_command(delete_workspace_cli, name="delete-workspace") accounts_group.add_command(list_customer_managed_key_hist_by_workspace_cli, - name="list-cust-managed-key-hist-by-ws") + name="list-cust-managed-key-hist-by-ws") accounts_group.add_command(list_customer_managed_key_hist_by_account_cli, - name="list-cust-managed-key-hist-by-acc") + name="list-cust-managed-key-hist-by-acc")