From 5f10b884e76210c7e2ce8588df836e05d4c0bb2e Mon Sep 17 00:00:00 2001 From: Simo Tumelius Date: Mon, 4 Apr 2022 17:25:13 +0300 Subject: [PATCH 1/5] Change DbtCloudCommand no longer requires the account_id (for commands that require account_id use DbtCloudAccountCommand as parent instead) --- dbt_cloud/command/__init__.py | 3 ++- dbt_cloud/command/command.py | 11 +++++++++-- dbt_cloud/command/environment/list.py | 4 ++-- dbt_cloud/command/job/create.py | 4 ++-- dbt_cloud/command/job/delete.py | 4 ++-- dbt_cloud/command/job/get.py | 4 ++-- dbt_cloud/command/job/list.py | 4 ++-- dbt_cloud/command/job/run.py | 4 ++-- dbt_cloud/command/metadata/query.py | 4 ++-- dbt_cloud/command/project/list.py | 4 ++-- dbt_cloud/command/run/cancel.py | 4 ++-- dbt_cloud/command/run/get.py | 4 ++-- dbt_cloud/command/run/get_artifact.py | 4 ++-- dbt_cloud/command/run/list.py | 4 ++-- dbt_cloud/command/run/list_artifacts.py | 4 ++-- 15 files changed, 37 insertions(+), 29 deletions(-) diff --git a/dbt_cloud/command/__init__.py b/dbt_cloud/command/__init__.py index 6dfd502..ed34e4b 100644 --- a/dbt_cloud/command/__init__.py +++ b/dbt_cloud/command/__init__.py @@ -15,5 +15,6 @@ ) from .project import DbtCloudProjectListCommand from .environment import DbtCloudEnvironmentListCommand +from .account import DbtCloudAccountListCommand from .metadata import DbtCloudMetadataQueryCommand -from .command import DbtCloudCommand +from .command import DbtCloudAccountCommand diff --git a/dbt_cloud/command/command.py b/dbt_cloud/command/command.py index b79fbe7..b800bf4 100644 --- a/dbt_cloud/command/command.py +++ b/dbt_cloud/command/command.py @@ -92,7 +92,6 @@ def get_description(cls) -> str: class DbtCloudCommand(ClickBaseModel): api_token: str = API_TOKEN_FIELD - account_id: int = ACCOUNT_ID_FIELD dbt_cloud_host: str = DBT_CLOUD_HOST_FIELD _api_version: str = PrivateAttr("v2") @@ -102,8 +101,16 @@ def request_headers(self) -> dict: @property def api_url(self) -> str: - return f"https://{self.dbt_cloud_host}/api/{self._api_version}/accounts/{self.account_id}" + return f"https://{self.dbt_cloud_host}/api/{self._api_version}" def get_payload(self, exclude=["api_token", "dbt_cloud_host"]) -> dict: payload = self.json(exclude=set(exclude)) return json_to_dict(payload) + + +class DbtCloudAccountCommand(DbtCloudCommand): + account_id: int = ACCOUNT_ID_FIELD + + @property + def api_url(self) -> str: + return f"{super().api_url}/accounts/{self.account_id}" diff --git a/dbt_cloud/command/environment/list.py b/dbt_cloud/command/environment/list.py index 97627bc..d153682 100644 --- a/dbt_cloud/command/environment/list.py +++ b/dbt_cloud/command/environment/list.py @@ -1,10 +1,10 @@ import requests from pydantic import Field, PrivateAttr -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand from dbt_cloud.field import PROJECT_ID_FIELD -class DbtCloudEnvironmentListCommand(DbtCloudCommand): +class DbtCloudEnvironmentListCommand(DbtCloudAccountCommand): """Retrieves environments for a given project.""" project_id: int = PROJECT_ID_FIELD diff --git a/dbt_cloud/command/job/create.py b/dbt_cloud/command/job/create.py index 61ecdd8..5f8c81e 100644 --- a/dbt_cloud/command/job/create.py +++ b/dbt_cloud/command/job/create.py @@ -2,7 +2,7 @@ from enum import Enum from typing import Optional, List from pydantic import Field -from dbt_cloud.command.command import DbtCloudCommand, ClickBaseModel +from dbt_cloud.command.command import DbtCloudAccountCommand, ClickBaseModel from dbt_cloud.field import PythonLiteralOption, PROJECT_ID_FIELD, ENVIRONMENT_ID_FIELD @@ -51,7 +51,7 @@ class DbtCloudJobSchedule(ClickBaseModel): time: DbtCloudJobScheduleTime = Field(default_factory=DbtCloudJobScheduleTime) -class DbtCloudJobCreateCommand(DbtCloudCommand): +class DbtCloudJobCreateCommand(DbtCloudAccountCommand): """Creates a job in a dbt Cloud project.""" id: Optional[int] = Field( diff --git a/dbt_cloud/command/job/delete.py b/dbt_cloud/command/job/delete.py index 92fa3c3..061a7c6 100644 --- a/dbt_cloud/command/job/delete.py +++ b/dbt_cloud/command/job/delete.py @@ -1,11 +1,11 @@ import os import requests from pydantic import Field -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand from dbt_cloud.field import JOB_ID_FIELD -class DbtCloudJobDeleteCommand(DbtCloudCommand): +class DbtCloudJobDeleteCommand(DbtCloudAccountCommand): """Deletes a job from a dbt Cloud project.""" job_id: int = JOB_ID_FIELD diff --git a/dbt_cloud/command/job/get.py b/dbt_cloud/command/job/get.py index 37c7757..f5f7af0 100644 --- a/dbt_cloud/command/job/get.py +++ b/dbt_cloud/command/job/get.py @@ -2,11 +2,11 @@ import requests from typing import Optional from pydantic import Field -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand from dbt_cloud.field import JOB_ID_FIELD -class DbtCloudJobGetCommand(DbtCloudCommand): +class DbtCloudJobGetCommand(DbtCloudAccountCommand): """Returns the details of a dbt Cloud job.""" job_id: int = JOB_ID_FIELD diff --git a/dbt_cloud/command/job/list.py b/dbt_cloud/command/job/list.py index 782ec8f..f770c9c 100644 --- a/dbt_cloud/command/job/list.py +++ b/dbt_cloud/command/job/list.py @@ -1,10 +1,10 @@ import requests from typing import Optional from pydantic import Field -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand -class DbtCloudJobListCommand(DbtCloudCommand): +class DbtCloudJobListCommand(DbtCloudAccountCommand): """Returns a list of jobs in the account.""" order_by: Optional[str] = Field( diff --git a/dbt_cloud/command/job/run.py b/dbt_cloud/command/job/run.py index 9285cff..1a241fc 100644 --- a/dbt_cloud/command/job/run.py +++ b/dbt_cloud/command/job/run.py @@ -2,11 +2,11 @@ import requests from typing import Optional, List from pydantic import Field, validator -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand from dbt_cloud.field import JOB_ID_FIELD -class DbtCloudJobRunCommand(DbtCloudCommand): +class DbtCloudJobRunCommand(DbtCloudAccountCommand): """Triggers a dbt Cloud job run and returns a status JSON response.""" job_id: int = JOB_ID_FIELD diff --git a/dbt_cloud/command/metadata/query.py b/dbt_cloud/command/metadata/query.py index 04cf9fa..45ff60b 100644 --- a/dbt_cloud/command/metadata/query.py +++ b/dbt_cloud/command/metadata/query.py @@ -1,9 +1,9 @@ import requests from pydantic import Field -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand -class DbtCloudMetadataQueryCommand(DbtCloudCommand): +class DbtCloudMetadataQueryCommand(DbtCloudAccountCommand): """Queries the dbt Cloud Metadata API using GraphQL.""" query: str = Field(exclude_from_click_options=True) diff --git a/dbt_cloud/command/project/list.py b/dbt_cloud/command/project/list.py index 0474220..7589dfc 100644 --- a/dbt_cloud/command/project/list.py +++ b/dbt_cloud/command/project/list.py @@ -1,8 +1,8 @@ import requests -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand -class DbtCloudProjectListCommand(DbtCloudCommand): +class DbtCloudProjectListCommand(DbtCloudAccountCommand): """Returns a list of projects in the account.""" @property diff --git a/dbt_cloud/command/run/cancel.py b/dbt_cloud/command/run/cancel.py index 1475906..747bcf9 100644 --- a/dbt_cloud/command/run/cancel.py +++ b/dbt_cloud/command/run/cancel.py @@ -1,6 +1,6 @@ import requests from enum import IntEnum -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand from dbt_cloud.field import RUN_ID_FIELD @@ -13,7 +13,7 @@ class DbtCloudRunStatus(IntEnum): CANCELLED = 30 -class DbtCloudRunCancelCommand(DbtCloudCommand): +class DbtCloudRunCancelCommand(DbtCloudAccountCommand): """Cancels a dbt Cloud run.""" run_id: int = RUN_ID_FIELD diff --git a/dbt_cloud/command/run/get.py b/dbt_cloud/command/run/get.py index 6988a6f..d7d031a 100644 --- a/dbt_cloud/command/run/get.py +++ b/dbt_cloud/command/run/get.py @@ -2,7 +2,7 @@ from enum import IntEnum from typing import Optional, List from pydantic import Field -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand from dbt_cloud.field import RUN_ID_FIELD @@ -15,7 +15,7 @@ class DbtCloudRunStatus(IntEnum): CANCELLED = 30 -class DbtCloudRunGetCommand(DbtCloudCommand): +class DbtCloudRunGetCommand(DbtCloudAccountCommand): """Returns the details of a dbt Cloud run.""" run_id: int = RUN_ID_FIELD diff --git a/dbt_cloud/command/run/get_artifact.py b/dbt_cloud/command/run/get_artifact.py index 001607d..bb07440 100644 --- a/dbt_cloud/command/run/get_artifact.py +++ b/dbt_cloud/command/run/get_artifact.py @@ -1,10 +1,10 @@ import requests from pydantic import Field -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand from dbt_cloud.field import RUN_ID_FIELD -class DbtCloudRunGetArtifactCommand(DbtCloudCommand): +class DbtCloudRunGetArtifactCommand(DbtCloudAccountCommand): """Fetches an artifact file from a completed run.""" run_id: int = RUN_ID_FIELD diff --git a/dbt_cloud/command/run/list.py b/dbt_cloud/command/run/list.py index 78b85ca..73f3310 100644 --- a/dbt_cloud/command/run/list.py +++ b/dbt_cloud/command/run/list.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Optional from pydantic import Field, PrivateAttr -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand class DbtCloudRunStatus(Enum): @@ -15,7 +15,7 @@ class DbtCloudRunStatus(Enum): CANCELED = "Canceled" -class DbtCloudRunListCommand(DbtCloudCommand): +class DbtCloudRunListCommand(DbtCloudAccountCommand): """Returns a list of runs in the account. The runs are returned sorted by creation date, with the most recent run appearing first.""" limit: Optional[int] = Field( diff --git a/dbt_cloud/command/run/list_artifacts.py b/dbt_cloud/command/run/list_artifacts.py index df8426d..26a9a9d 100644 --- a/dbt_cloud/command/run/list_artifacts.py +++ b/dbt_cloud/command/run/list_artifacts.py @@ -1,10 +1,10 @@ import requests from pydantic import Field -from dbt_cloud.command.command import DbtCloudCommand +from dbt_cloud.command.command import DbtCloudAccountCommand from dbt_cloud.field import RUN_ID_FIELD -class DbtCloudRunListArtifactsCommand(DbtCloudCommand): +class DbtCloudRunListArtifactsCommand(DbtCloudAccountCommand): """Fetches a list of artifact files generated for a completed run.""" run_id: int = RUN_ID_FIELD From 6a6929b86068ab77b086b31c9c15bbfbc893b001 Mon Sep 17 00:00:00 2001 From: Simo Tumelius Date: Mon, 4 Apr 2022 17:25:35 +0300 Subject: [PATCH 2/5] Add 'dbt-cloud account list' command --- .github/workflows/ci.yml | 7 ++++++ dbt_cloud/cli.py | 31 +++++++++++++++++++-------- dbt_cloud/command/account/__init__.py | 1 + dbt_cloud/command/account/list.py | 14 ++++++++++++ tests/conftest.py | 8 +++++++ 5 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 dbt_cloud/command/account/__init__.py create mode 100644 dbt_cloud/command/account/list.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5d46f1c..47619a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -127,6 +127,13 @@ jobs: environment_count=$(cat environments.json | jq '.data | length') [[ $environment_count > 0 ]] && exit 0 || exit 1 + - name: Test 'dbt-cloud account list' + run: | + dbt-cloud account list > accounts.json + cat accounts.json | jq '.data[] | {id: .id}' + account_count=$(cat accounts.json | jq '.data | length') + [[ $account_count > 0 ]] && exit 0 || exit 1 + - name: Test 'dbt-cloud metadata query' run: dbt-cloud metadata query -f tests/data/metadata_query.graphql diff --git a/dbt_cloud/cli.py b/dbt_cloud/cli.py index 670d16a..6fe2f71 100644 --- a/dbt_cloud/cli.py +++ b/dbt_cloud/cli.py @@ -8,7 +8,7 @@ DbtCloudJobCreateCommand, DbtCloudJobDeleteCommand, DbtCloudJobRunCommand, - DbtCloudCommand, + DbtCloudAccountCommand, DbtCloudRunGetCommand, DbtCloudRunListArtifactsCommand, DbtCloudRunGetArtifactCommand, @@ -18,6 +18,7 @@ DbtCloudJobListCommand, DbtCloudProjectListCommand, DbtCloudEnvironmentListCommand, + DbtCloudAccountListCommand, ) from dbt_cloud.demo import data_catalog from dbt_cloud.serde import json_to_dict, dict_to_json @@ -32,7 +33,7 @@ def execute_and_print(command, **kwargs): return response -@click.group() +@click.group(help="The dbt Cloud command line interface.") def dbt_cloud(): import http.client as http_client @@ -45,27 +46,32 @@ def dbt_cloud(): http_client.HTTPConnection.debuglevel = 1 -@dbt_cloud.group(help="dbt Cloud job commands") +@dbt_cloud.group(help="Interact with dbt Cloud jobs.") def job(): pass -@dbt_cloud.group(name="run", help="dbt Cloud run commands") +@dbt_cloud.group(name="run", help="Interact with dbt Cloud job runs.") def job_run(): pass -@dbt_cloud.group(help="dbt Cloud project commands") +@dbt_cloud.group(help="Interact with dbt Cloud projects.") def project(): pass -@dbt_cloud.group(help="dbt Cloud environment commands") +@dbt_cloud.group(help="Interact with dbt Cloud environments.") def environment(): pass -@dbt_cloud.group(help="dbt Cloud Metadata API commands") +@dbt_cloud.group(help="Interact with dbt Cloud accounts.") +def account(): + pass + + +@dbt_cloud.group(help="Interact with the dbt Cloud Metadata API.") def metadata(): pass @@ -204,7 +210,7 @@ def export(file, **kwargs): @job.command(help="Imports a dbt Cloud job from exported JSON.", name="import") -@DbtCloudCommand.click_options +@DbtCloudAccountCommand.click_options @click.option( "-f", "--file", @@ -213,7 +219,7 @@ def export(file, **kwargs): help="Import file path.", ) def import_job(file, **kwargs): - base_command = DbtCloudCommand.from_click_options(**kwargs) + base_command = DbtCloudAccountCommand.from_click_options(**kwargs) job_create_kwargs = {**json_to_dict(file.read()), **base_command.dict()} command = DbtCloudJobCreateCommand(**job_create_kwargs) response = command.execute() @@ -284,6 +290,13 @@ def list(**kwargs): response = execute_and_print(command) +@account.command(help=DbtCloudAccountListCommand.get_description()) +@DbtCloudAccountListCommand.click_options +def list(**kwargs): + command = DbtCloudAccountListCommand.from_click_options(**kwargs) + response = execute_and_print(command) + + @metadata.command(help=DbtCloudMetadataQueryCommand.get_description()) @click.option( "-f", diff --git a/dbt_cloud/command/account/__init__.py b/dbt_cloud/command/account/__init__.py new file mode 100644 index 0000000..55a92bc --- /dev/null +++ b/dbt_cloud/command/account/__init__.py @@ -0,0 +1 @@ +from .list import DbtCloudAccountListCommand diff --git a/dbt_cloud/command/account/list.py b/dbt_cloud/command/account/list.py new file mode 100644 index 0000000..277d82c --- /dev/null +++ b/dbt_cloud/command/account/list.py @@ -0,0 +1,14 @@ +import requests +from dbt_cloud.command.command import DbtCloudCommand + + +class DbtCloudAccountListCommand(DbtCloudCommand): + """Retrieves accounts.""" + + @property + def api_url(self) -> str: + return f"{super().api_url}/accounts/" + + 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 a085d96..6e9b813 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,6 +14,7 @@ DbtCloudRunListArtifactsCommand, DbtCloudRunListCommand, DbtCloudEnvironmentListCommand, + DbtCloudAccountListCommand, ) @@ -146,6 +147,13 @@ def load_response(response_name): "get", marks=pytest.mark.environment, ), + pytest.param( + "account_list", + DbtCloudAccountListCommand(api_token=API_TOKEN), + load_response("account_list_response"), + "get", + marks=pytest.mark.account, + ), ] From d78639ba709957bde076606fe2bdf3c4f1397a2c Mon Sep 17 00:00:00 2001 From: Simo Tumelius Date: Mon, 4 Apr 2022 17:32:07 +0300 Subject: [PATCH 3/5] Add account_list_response.json --- tests/data/account_list_response.json | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/data/account_list_response.json diff --git a/tests/data/account_list_response.json b/tests/data/account_list_response.json new file mode 100644 index 0000000..9944e9c --- /dev/null +++ b/tests/data/account_list_response.json @@ -0,0 +1,55 @@ +{ + "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": 50, + "id": 1, + "name": "Jaffle Shop", + "state": 1, + "plan": "team", + "pending_cancel": false, + "run_slots": 5, + "developer_seats": 4, + "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": "ap@jaffleshop.com", + "locked": false, + "develop_file_system": true, + "unlocked_at": null, + "created_at": "2021-09-06T07:41:12.146234+00:00", + "updated_at": "2022-03-07T06:05:33.350381+00:00", + "starter_repo_url": null, + "sso_reauth": false, + "git_auth_level": "team", + "identifier": "jaffle-123", + "docs_job": null, + "freshness_job": null, + "enterprise_login_url": "https://cloud.getdbt.com/enterprise-login/None/" + } + ], + "extra": { + "filters": { + "pk__in": [ + 27299 + ] + }, + "order_by": null, + "pagination": { + "count": 1, + "total_count": 1 + } + } +} From cb1c913ee8a1700ff34811450d9cdac7a59949e4 Mon Sep 17 00:00:00 2001 From: Simo Tumelius Date: Mon, 4 Apr 2022 17:32:18 +0300 Subject: [PATCH 4/5] Update README --- README.md | 227 ++++++++++++++++++++++++++++++++++------------------- pytest.ini | 3 +- 2 files changed, 147 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index c24682e..1a87991 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The following environment variables are used as argument defaults: Group | API endpoint | Command | Description | | --- | --- | --- | --- | -| Accounts | [https://cloud.getdbt.com/api/v2/accounts/](https://docs.getdbt.com/dbt-cloud/api-v2#operation/listAccounts) | `dbt-cloud account list` | Not implemented yet | +| 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 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 | | 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 | @@ -53,6 +53,7 @@ Group | API endpoint | Command | Description | # Commands +* [dbt-cloud account list](#dbt-cloud-account-list) * [dbt-cloud project list](#dbt-cloud-project-list) * [dbt-cloud environment list](#dbt-cloud-environment-list) * [dbt-cloud job run](#dbt-cloud-job-run) @@ -70,6 +71,68 @@ 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 list +This command retrieves 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). + +### Usage +```bash +>> dbt-cloud account list +{ + "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": 50, + "id": REDACTED, + "name": "Jaffle Shop", + "state": 1, + "plan": "team", + "pending_cancel": false, + "run_slots": 5, + "developer_seats": 4, + "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": "REDACTED", + "locked": false, + "develop_file_system": true, + "unlocked_at": null, + "created_at": "2021-09-06T07:41:12.146234+00:00", + "updated_at": "2022-03-07T06:05:33.350381+00:00", + "starter_repo_url": null, + "sso_reauth": false, + "git_auth_level": "team", + "identifier": "REDACTED", + "docs_job": null, + "freshness_job": null, + "enterprise_login_url": "https://cloud.getdbt.com/enterprise-login/None/" + } + ], + "extra": { + "filters": { + "pk__in": [ + REDACTED + ] + }, + "order_by": null, + "pagination": { + "count": 1, + "total_count": 1 + } + } +} +``` ## dbt-cloud project list This command returns a list of projects in the account. For more information on the API endpoint arguments and response, run `dbt-cloud project list --help` and check out the [dbt Cloud API docs](https://docs.getdbt.com/dbt-cloud/api-v2#operation/listProjects). @@ -78,97 +141,97 @@ This command returns a list of projects in the account. For more information on ```bash >> dbt-cloud project list { - "status": { - "code": 200, - "is_success": true, - "user_message": "Success!", - "developer_message": "" - }, - "data": [ - { - "name": "jaffle_shop", + "status": { + "code": 200, + "is_success": true, + "user_message": "Success!", + "developer_message": "" + }, + "data": [ + { + "name": "jaffle_shop", + "account_id": REDACTED, + "repository_id": REDACTED, + "connection_id": REDACTED, + "id": REDACTED, + "created_at": "2021-04-14 20:23:00.395285+00:00", + "updated_at": "2021-11-16 16:32:43.960836+00:00", + "skipped_setup": false, + "state": 1, + "dbt_project_subdirectory": null, + "connection": { + "id": REDACTED, "account_id": REDACTED, - "repository_id": REDACTED, - "connection_id": REDACTED, + "project_id": REDACTED, + "name": "Bigquery", + "type": "bigquery", + "created_by_id": REDACTED, + "created_by_service_token_id": null, + "details": { + "project_id": "REDACTED", + "timeout_seconds": 300, + "private_key_id": "REDACTED", + "client_email": "REDACTED", + "client_id": "REDACTED", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "REDACTED", + "retries": 1, + "location": null, + "is_configured_for_oauth": false + }, + "state": 1, + "created_at": "2021-11-16 16:26:01.571115+00:00", + "updated_at": "2021-11-16 16:37:42.500015+00:00" + }, + "repository": { "id": REDACTED, - "created_at": "2021-04-14 20:23:00.395285+00:00", - "updated_at": "2021-11-16 16:32:43.960836+00:00", - "skipped_setup": false, + "account_id": REDACTED, + "project_id": REDACTED, + "full_name": "REDACTED", + "remote_url": "REDACTED", + "remote_backend": "github", + "git_clone_strategy": "github_app", + "deploy_key_id": REDACTED, + "repository_credentials_id": null, + "github_installation_id": REDACTED, + "pull_request_url_template": "REDACTED", "state": 1, - "dbt_project_subdirectory": null, - "connection": { - "id": REDACTED, - "account_id": REDACTED, - "project_id": REDACTED, - "name": "Bigquery", - "type": "bigquery", - "created_by_id": REDACTED, - "created_by_service_token_id": null, - "details": { - "project_id": "REDACTED", - "timeout_seconds": 300, - "private_key_id": "REDACTED", - "client_email": "REDACTED", - "client_id": "REDACTED", - "auth_uri": "https://accounts.google.com/o/oauth2/auth", - "token_uri": "https://oauth2.googleapis.com/token", - "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", - "client_x509_cert_url": "REDACTED", - "retries": 1, - "location": null, - "is_configured_for_oauth": false - }, - "state": 1, - "created_at": "2021-11-16 16:26:01.571115+00:00", - "updated_at": "2021-11-16 16:37:42.500015+00:00" - }, - "repository": { + "created_at": "2021-11-16 16:26:24.412439+00:00", + "updated_at": "2021-11-16 16:26:24.412455+00:00", + "deploy_key": { "id": REDACTED, "account_id": REDACTED, - "project_id": REDACTED, - "full_name": "REDACTED", - "remote_url": "REDACTED", - "remote_backend": "github", - "git_clone_strategy": "github_app", - "deploy_key_id": REDACTED, - "repository_credentials_id": null, - "github_installation_id": REDACTED, - "pull_request_url_template": "REDACTED", "state": 1, - "created_at": "2021-11-16 16:26:24.412439+00:00", - "updated_at": "2021-11-16 16:26:24.412455+00:00", - "deploy_key": { - "id": REDACTED, - "account_id": REDACTED, - "state": 1, - "public_key": "REDACTED" - }, - "github_repo": "REDACTED", - "name": "jaffle_shop", - "git_provider_id": REDACTED, - "gitlab": null, - "git_provider": null + "public_key": "REDACTED" }, - "group_permissions": [], - "docs_job_id": null, - "freshness_job_id": null, - "docs_job": null, - "freshness_job": null - } - ], - "extra": { - "filters": { - "account_id": REDACTED, - "limit": 100, - "offset": 0 + "github_repo": "REDACTED", + "name": "jaffle_shop", + "git_provider_id": REDACTED, + "gitlab": null, + "git_provider": null }, - "order_by": "id", - "pagination": { - "count": 1, - "total_count": 1 - } + "group_permissions": [], + "docs_job_id": null, + "freshness_job_id": null, + "docs_job": null, + "freshness_job": null + } + ], + "extra": { + "filters": { + "account_id": REDACTED, + "limit": 100, + "offset": 0 + }, + "order_by": "id", + "pagination": { + "count": 1, + "total_count": 1 } } +} ``` ## dbt-cloud environment list diff --git a/pytest.ini b/pytest.ini index 9128928..8bdf6cb 100644 --- a/pytest.ini +++ b/pytest.ini @@ -5,4 +5,5 @@ markers = job: tests related to dbt Cloud jobs run: tests related to dbt Cloud runs project: tests related to dbt Cloud projects - environment: tests related to dbt Cloud environments \ No newline at end of file + environment: tests related to dbt Cloud environments + account: tests related to dbt Cloud accounts \ No newline at end of file From c02b0825e160f67cfb891f820083651f880f62d1 Mon Sep 17 00:00:00 2001 From: Simo Tumelius Date: Mon, 4 Apr 2022 17:34:19 +0300 Subject: [PATCH 5/5] Minor change --- README.md | 4 ++-- dbt_cloud/command/account/list.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1a87991..8228f62 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The following environment variables are used as argument defaults: Group | API endpoint | Command | Description | | --- | --- | --- | --- | -| 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 accounts | +| 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 | | 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 | @@ -72,7 +72,7 @@ Group | API endpoint | Command | Description | * [dbt-cloud metadata query](#dbt-cloud-metadata-query) ## dbt-cloud account list -This command retrieves 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). +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). ### Usage ```bash diff --git a/dbt_cloud/command/account/list.py b/dbt_cloud/command/account/list.py index 277d82c..99dc7cd 100644 --- a/dbt_cloud/command/account/list.py +++ b/dbt_cloud/command/account/list.py @@ -3,7 +3,7 @@ class DbtCloudAccountListCommand(DbtCloudCommand): - """Retrieves accounts.""" + """Retrieves all available accounts.""" @property def api_url(self) -> str: