Skip to content

Commit

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

* Add unit test

* Add integration test

* Update README

Co-authored-by: Simo Tumelius <[email protected]>
  • Loading branch information
stumelius and datamie-simo authored Jul 14, 2022
1 parent 63a99e6 commit 3cf8bf0
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 4 deletions.
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ jobs:
run_id=$(cat run.json | jq .data.id -r)
dbt-cloud run get-artifact --run-id $run_id --path manifest.json
- run:
name: Test 'dbt-cloud project get'
command: |
dbt-cloud project get
- run:
name: Test 'dbt-cloud project list'
command: |
Expand All @@ -151,7 +156,7 @@ jobs:
name: Test 'dbt-cloud account get'
command: |
dbt-cloud account get
- run:
name: Test 'dbt-cloud account list'
command: |
Expand Down
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ 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 |
| 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/{projectId}](https://docs.getdbt.com/dbt-cloud/api-v2#operation/getProjectById) | [dbt-cloud project get](#dbt-cloud-project-get) | Retrieves dbt Cloud project information |
| 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 |
| Environments | https://cloud.getdbt.com/api/v3/accounts/{accountId}/projects/{projectId}/environments | [dbt-cloud environment list](#dbt-cloud-environment-list) | Retrieves environments for a given project |
| Jobs | [https://cloud.getdbt.com/api/v2/accounts/{accountId}/jobs/](https://docs.getdbt.com/dbt-cloud/api-v2#operation/listJobsForAccount) | [dbt-cloud job list](#dbt-cloud-job-list) | Returns a list of jobs in the account |
| Jobs | [https://cloud.getdbt.com/api/v2/accounts/{accountId}/jobs/{jobId}/](https://docs.getdbt.com/dbt-cloud/api-v2#operation/getJobById) | [dbt-cloud job get](#dbt-cloud-job-get) | Returns the details of a dbt Cloud job |
Expand All @@ -68,6 +68,7 @@ Group | API endpoint | Command | Description |
* [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 get](#dbt-cloud-project-get)
* [dbt-cloud project list](#dbt-cloud-project-list)
* [dbt-cloud environment list](#dbt-cloud-environment-list)
* [dbt-cloud job run](#dbt-cloud-job-run)
Expand Down Expand Up @@ -270,6 +271,19 @@ This command retrieves audit logs for the dbt Cloud account. For more informatio
```
</details>

## dbt-cloud project get
This command retrieves dbt Cloud project information. For more information on the API endpoint arguments and response, run `dbt-cloud project get --help` and check out the [dbt Cloud API docs](https://docs.getdbt.com/dbt-cloud/api-v2#tag/Projects/operation/getProjectById).

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

```bash
>> dbt-cloud project get
```

[Click to view sample response](tests/data/project_get_response.json)
</details>


## 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).
Expand Down
8 changes: 8 additions & 0 deletions dbt_cloud/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DbtCloudRunListCommand,
DbtCloudRunCancelCommand,
DbtCloudJobListCommand,
DbtCloudProjectGetCommand,
DbtCloudProjectListCommand,
DbtCloudEnvironmentListCommand,
DbtCloudAccountListCommand,
Expand Down Expand Up @@ -318,6 +319,13 @@ def get_artifact(file, **kwargs):
response.raise_for_status()


@project.command(help=DbtCloudProjectGetCommand.get_description())
@DbtCloudProjectGetCommand.click_options
def get(**kwargs):
command = DbtCloudProjectGetCommand.from_click_options(**kwargs)
response = execute_and_print(command)


@project.command(help=DbtCloudProjectListCommand.get_description())
@DbtCloudProjectListCommand.click_options
def list(**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 @@ -13,7 +13,7 @@
DbtCloudRunListCommand,
DbtCloudRunCancelCommand,
)
from .project import DbtCloudProjectListCommand
from .project import DbtCloudProjectListCommand, DbtCloudProjectGetCommand
from .environment import DbtCloudEnvironmentListCommand
from .account import DbtCloudAccountListCommand, DbtCloudAccountGetCommand
from .audit_log import DbtCloudAuditLogGetCommand
Expand Down
1 change: 1 addition & 0 deletions dbt_cloud/command/project/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .list import DbtCloudProjectListCommand
from .get import DbtCloudProjectGetCommand
17 changes: 17 additions & 0 deletions dbt_cloud/command/project/get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import requests
from dbt_cloud.command.command import DbtCloudAccountCommand
from dbt_cloud.field import PROJECT_ID_FIELD


class DbtCloudProjectGetCommand(DbtCloudAccountCommand):
"""Retrieves dbt Cloud project information."""

project_id: int = PROJECT_ID_FIELD

@property
def api_url(self) -> str:
return f"{super().api_url}/projects/{self.project_id}"

def execute(self) -> requests.Response:
response = requests.get(url=self.api_url, headers=self.request_headers)
return response
12 changes: 11 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
DbtCloudJobGetCommand,
DbtCloudJobListCommand,
DbtCloudJobRunCommand,
DbtCloudProjectGetCommand,
DbtCloudProjectListCommand,
DbtCloudRunCancelCommand,
DbtCloudRunGetArtifactCommand,
Expand Down Expand Up @@ -134,7 +135,16 @@ def load_response(response_name):
marks=pytest.mark.run,
),
pytest.param(
"project_list_artifact",
"project_get",
DbtCloudProjectGetCommand(
api_token=API_TOKEN, account_id=ACCOUNT_ID, project_id=PROJECT_ID
),
load_response("project_get_response"),
"get",
marks=pytest.mark.project,
),
pytest.param(
"project_list",
DbtCloudProjectListCommand(api_token=API_TOKEN, account_id=ACCOUNT_ID),
load_response("project_list_response"),
"get",
Expand Down
85 changes: 85 additions & 0 deletions tests/data/project_get_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"status": {
"code": 200,
"is_success": true,
"user_message": "Success!",
"developer_message": ""
},
"data": {
"name": "jaffle_shop",
"account_id": 123456,
"repository_id": 123459,
"connection_id": 123460,
"id": 123457,
"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": 123460,
"account_id": 123456,
"project_id": 123457,
"name": "Bigquery",
"type": "bigquery",
"created_by_id": 123461,
"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",
"priority": null,
"retries": 1,
"scopes": null,
"location": null,
"maximum_bytes_billed": 0,
"execution_project": null,
"impersonate_service_account": null,
"job_retry_deadline_seconds": 0,
"job_creation_timeout_seconds": 0,
"is_configured_for_oauth": false
},
"state": 1,
"created_at": "2021-11-16 16:26:01.571115+00:00",
"updated_at": "2022-05-18 06:27:34.729528+00:00"
},
"repository": {
"id": 123459,
"account_id": 123456,
"project_id": 123457,
"full_name": "REDACTED",
"remote_url": "REDACTED",
"remote_backend": "github",
"git_clone_strategy": "github_app",
"deploy_key_id": 123458,
"repository_credentials_id": null,
"github_installation_id": 123462,
"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": 123458,
"account_id": 123456,
"state": 1,
"public_key": "REDACTED"
},
"github_repo": "REDACTED",
"name": "jaffle_shop",
"git_provider_id": 123463,
"gitlab": null,
"git_provider": null
},
"group_permissions": [],
"docs_job_id": null,
"freshness_job_id": null,
"docs_job": null,
"freshness_job": null
}
}

0 comments on commit 3cf8bf0

Please sign in to comment.