Skip to content

Commit

Permalink
Add dbt-cloud account get command (#59)
Browse files Browse the repository at this point in the history
* Add 'dbt-cloud account get' command

* Add unit test

* Update README

* Add integration test

Co-authored-by: Simo Tumelius <[email protected]>
  • Loading branch information
stumelius and datamie-simo authored Jul 14, 2022
1 parent b85f63a commit 63a99e6
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
55 changes: 54 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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)
Expand All @@ -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).

<details>
<summary><b>Usage</b></summary>

```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/"
}
}
```
</details>

## 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).

Expand Down
8 changes: 8 additions & 0 deletions dbt_cloud/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
DbtCloudProjectListCommand,
DbtCloudEnvironmentListCommand,
DbtCloudAccountListCommand,
DbtCloudAccountGetCommand,
DbtCloudAuditLogGetCommand,
)
from dbt_cloud.demo import data_catalog
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion dbt_cloud/command/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions dbt_cloud/command/account/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .list import DbtCloudAccountListCommand
from .get import DbtCloudAccountGetCommand
10 changes: 10 additions & 0 deletions dbt_cloud/command/account/get.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DbtCloudRunListCommand,
DbtCloudEnvironmentListCommand,
DbtCloudAccountListCommand,
DbtCloudAccountGetCommand,
DbtCloudAuditLogGetCommand,
)

Expand Down Expand Up @@ -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(
Expand Down
41 changes: 41 additions & 0 deletions tests/data/account_get_response.json
Original file line number Diff line number Diff line change
@@ -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/"
}
}

0 comments on commit 63a99e6

Please sign in to comment.