From 63a99e68fef5f90f0b251b2dfa3ba5211c34bd1d Mon Sep 17 00:00:00 2001 From: Simo Tumelius Date: Thu, 14 Jul 2022 11:08:48 +0300 Subject: [PATCH] Add `dbt-cloud account get` command (#59) * Add 'dbt-cloud account get' command * Add unit test * Update README * Add integration test Co-authored-by: Simo Tumelius --- .circleci/config.yml | 5 +++ README.md | 55 ++++++++++++++++++++++++++- dbt_cloud/cli.py | 8 ++++ dbt_cloud/command/__init__.py | 2 +- dbt_cloud/command/account/__init__.py | 1 + dbt_cloud/command/account/get.py | 10 +++++ tests/conftest.py | 8 ++++ tests/data/account_get_response.json | 41 ++++++++++++++++++++ 8 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 dbt_cloud/command/account/get.py create mode 100644 tests/data/account_get_response.json diff --git a/.circleci/config.yml b/.circleci/config.yml index 5bb9873..4c085da 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -147,6 +147,11 @@ jobs: environment_count=$(cat environments.json | jq '.data | length') [[ $environment_count > 0 ]] && exit 0 || exit 1 + - run: + name: Test 'dbt-cloud account get' + command: | + dbt-cloud account get + - run: name: Test 'dbt-cloud account list' command: | diff --git a/README.md b/README.md index fd9d6b9..43797ad 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,8 @@ The following environment variables are used as argument defaults: Group | API endpoint | Command | Description | | --- | --- | --- | --- | +| Accounts | [https://cloud.getdbt.com/api/v2/accounts/{accountId}/](https://docs.getdbt.com/dbt-cloud/api-v2#operation/getAccountById) | [dbt-cloud account get](#dbt-cloud-account-get) | Retrieves dbt Cloud account information | | Accounts | [https://cloud.getdbt.com/api/v2/accounts/](https://docs.getdbt.com/dbt-cloud/api-v2#operation/listAccounts) | [dbt-cloud account list](#dbt-cloud-account-list) | Retrieves all available accounts | -| Accounts | [https://cloud.getdbt.com/api/v2/accounts/{accountId}/](https://docs.getdbt.com/dbt-cloud/api-v2#operation/getAccountById) | `dbt-cloud account get` | Not implemented yet | | Audit Logs | https://cloud.getdbt.com/api/v3/accounts/{accountId}/audit-logs/ | [dbt-cloud audit-log get](#dbt-cloud-audit-log-get) | Retrieves audit logs for the dbt Cloud account | | Projects | https://cloud.getdbt.com/api/v2/accounts/{accountId}/projects/ | [dbt-cloud project list](#dbt-cloud-project-list) | Returns a list of projects in the account | | Projects | [https://cloud.getdbt.com/api/v2/accounts/{accountId}/projects/{projectId}](https://docs.getdbt.com/dbt-cloud/api-v2#operation/getProjectById) | `dbt-cloud project get` | Not implemented yet | @@ -65,6 +65,7 @@ Group | API endpoint | Command | Description | # Commands +* [dbt-cloud account get](#dbt-cloud-account-get) * [dbt-cloud account list](#dbt-cloud-account-list) * [dbt-cloud audit-log get](#dbt-cloud-audit-log-get) * [dbt-cloud project list](#dbt-cloud-project-list) @@ -85,6 +86,58 @@ Group | API endpoint | Command | Description | * [dbt-cloud run get-artifact](#dbt-cloud-run-get-artifact) * [dbt-cloud metadata query](#dbt-cloud-metadata-query) +## dbt-cloud account get +This command retrieves dbt Cloud account information. For more information on the API endpoint arguments and response, run `dbt-cloud account get --help` and check out the [dbt Cloud API docs](https://docs.getdbt.com/dbt-cloud/api-v2#tag/Accounts/operation/getAccountById). + +
+ Usage + +```bash +>> dbt-cloud account get +{ + "status": { + "code": 200, + "is_success": true, + "user_message": "Success!", + "developer_message": "" + }, + "data": { + "docs_job_id": null, + "freshness_job_id": null, + "lock_reason": null, + "unlock_if_subscription_renewed": false, + "read_only_seats": 10, + "id": 1, + "name": "REDACTED", + "state": 1, + "plan": "enterprise", + "pending_cancel": false, + "run_slots": 15, + "developer_seats": 10, + "queue_limit": 50, + "pod_memory_request_mebibytes": 600, + "run_duration_limit_seconds": 86400, + "enterprise_authentication_method": null, + "enterprise_login_slug": null, + "enterprise_unique_identifier": null, + "billing_email_address": null, + "locked": false, + "develop_file_system": true, + "unlocked_at": null, + "created_at": "2021-04-14T20:23:00.305964+00:00", + "updated_at": "2022-05-17T16:45:23.288391+00:00", + "starter_repo_url": null, + "sso_reauth": false, + "git_auth_level": "personal", + "identifier": "REDACTED", + "docs_job": null, + "freshness_job": null, + "enterprise_login_url": "https://cloud.getdbt.com/enterprise-login/None/" + } +} +``` +
+ ## dbt-cloud account list This command retrieves all available dbt Cloud accounts. For more information on the API endpoint arguments and response, run `dbt-cloud account list --help` and check out the [dbt Cloud API docs](https://docs.getdbt.com/dbt-cloud/api-v2#operation/listAccounts). diff --git a/dbt_cloud/cli.py b/dbt_cloud/cli.py index b2d000c..963310c 100644 --- a/dbt_cloud/cli.py +++ b/dbt_cloud/cli.py @@ -19,6 +19,7 @@ DbtCloudProjectListCommand, DbtCloudEnvironmentListCommand, DbtCloudAccountListCommand, + DbtCloudAccountGetCommand, DbtCloudAuditLogGetCommand, ) from dbt_cloud.demo import data_catalog @@ -338,6 +339,13 @@ def list(**kwargs): response = execute_and_print(command) +@account.command(help=DbtCloudAccountGetCommand.get_description()) +@DbtCloudAccountGetCommand.click_options +def get(**kwargs): + command = DbtCloudAccountGetCommand.from_click_options(**kwargs) + response = execute_and_print(command) + + @audit_log.command(help=DbtCloudAuditLogGetCommand.get_description()) @DbtCloudAuditLogGetCommand.click_options def get(**kwargs): diff --git a/dbt_cloud/command/__init__.py b/dbt_cloud/command/__init__.py index 2326898..b67de4b 100644 --- a/dbt_cloud/command/__init__.py +++ b/dbt_cloud/command/__init__.py @@ -15,7 +15,7 @@ ) from .project import DbtCloudProjectListCommand from .environment import DbtCloudEnvironmentListCommand -from .account import DbtCloudAccountListCommand +from .account import DbtCloudAccountListCommand, DbtCloudAccountGetCommand from .audit_log import DbtCloudAuditLogGetCommand from .metadata import DbtCloudMetadataQueryCommand from .command import DbtCloudAccountCommand diff --git a/dbt_cloud/command/account/__init__.py b/dbt_cloud/command/account/__init__.py index 55a92bc..e0a0785 100644 --- a/dbt_cloud/command/account/__init__.py +++ b/dbt_cloud/command/account/__init__.py @@ -1 +1,2 @@ from .list import DbtCloudAccountListCommand +from .get import DbtCloudAccountGetCommand diff --git a/dbt_cloud/command/account/get.py b/dbt_cloud/command/account/get.py new file mode 100644 index 0000000..dd960ed --- /dev/null +++ b/dbt_cloud/command/account/get.py @@ -0,0 +1,10 @@ +import requests +from dbt_cloud.command.command import DbtCloudAccountCommand + + +class DbtCloudAccountGetCommand(DbtCloudAccountCommand): + """Retrieves dbt Cloud account information.""" + + def execute(self) -> requests.Response: + response = requests.get(url=self.api_url, headers=self.request_headers) + return response diff --git a/tests/conftest.py b/tests/conftest.py index de43f1a..9097f73 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,6 +15,7 @@ DbtCloudRunListCommand, DbtCloudEnvironmentListCommand, DbtCloudAccountListCommand, + DbtCloudAccountGetCommand, DbtCloudAuditLogGetCommand, ) @@ -155,6 +156,13 @@ def load_response(response_name): "get", marks=pytest.mark.account, ), + pytest.param( + "account_get", + DbtCloudAccountGetCommand(api_token=API_TOKEN), + load_response("account_get_response"), + "get", + marks=pytest.mark.account, + ), pytest.param( "audit_log_get", DbtCloudAuditLogGetCommand( diff --git a/tests/data/account_get_response.json b/tests/data/account_get_response.json new file mode 100644 index 0000000..64f429e --- /dev/null +++ b/tests/data/account_get_response.json @@ -0,0 +1,41 @@ +{ + "status": { + "code": 200, + "is_success": true, + "user_message": "Success!", + "developer_message": "" + }, + "data": { + "docs_job_id": null, + "freshness_job_id": null, + "lock_reason": null, + "unlock_if_subscription_renewed": false, + "read_only_seats": 10, + "id": 1, + "name": "REDACTED", + "state": 1, + "plan": "enterprise", + "pending_cancel": false, + "run_slots": 15, + "developer_seats": 10, + "queue_limit": 50, + "pod_memory_request_mebibytes": 600, + "run_duration_limit_seconds": 86400, + "enterprise_authentication_method": null, + "enterprise_login_slug": null, + "enterprise_unique_identifier": null, + "billing_email_address": null, + "locked": false, + "develop_file_system": true, + "unlocked_at": null, + "created_at": "2021-04-14T20:23:00.305964+00:00", + "updated_at": "2022-05-17T16:45:23.288391+00:00", + "starter_repo_url": null, + "sso_reauth": false, + "git_auth_level": "personal", + "identifier": "REDACTED", + "docs_job": null, + "freshness_job": null, + "enterprise_login_url": "https://cloud.getdbt.com/enterprise-login/None/" + } +} \ No newline at end of file