diff --git a/.circleci/config.yml b/.circleci/config.yml index 4c085da..6c32a41 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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: | @@ -151,7 +156,7 @@ jobs: 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 43797ad..cde6f91 100644 --- a/README.md +++ b/README.md @@ -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 | @@ -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) @@ -270,6 +271,19 @@ This command retrieves audit logs for the dbt Cloud account. For more informatio ``` +## 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). + +
+ Usage + +```bash +>> dbt-cloud project get +``` + +[Click to view sample response](tests/data/project_get_response.json) +
+ ## 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). diff --git a/dbt_cloud/cli.py b/dbt_cloud/cli.py index 963310c..5431360 100644 --- a/dbt_cloud/cli.py +++ b/dbt_cloud/cli.py @@ -16,6 +16,7 @@ DbtCloudRunListCommand, DbtCloudRunCancelCommand, DbtCloudJobListCommand, + DbtCloudProjectGetCommand, DbtCloudProjectListCommand, DbtCloudEnvironmentListCommand, DbtCloudAccountListCommand, @@ -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): diff --git a/dbt_cloud/command/__init__.py b/dbt_cloud/command/__init__.py index b67de4b..ddf1d69 100644 --- a/dbt_cloud/command/__init__.py +++ b/dbt_cloud/command/__init__.py @@ -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 diff --git a/dbt_cloud/command/project/__init__.py b/dbt_cloud/command/project/__init__.py index b530112..4aa6568 100644 --- a/dbt_cloud/command/project/__init__.py +++ b/dbt_cloud/command/project/__init__.py @@ -1 +1,2 @@ from .list import DbtCloudProjectListCommand +from .get import DbtCloudProjectGetCommand diff --git a/dbt_cloud/command/project/get.py b/dbt_cloud/command/project/get.py new file mode 100644 index 0000000..13bbabd --- /dev/null +++ b/dbt_cloud/command/project/get.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 9097f73..72f4b19 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,6 +7,7 @@ DbtCloudJobGetCommand, DbtCloudJobListCommand, DbtCloudJobRunCommand, + DbtCloudProjectGetCommand, DbtCloudProjectListCommand, DbtCloudRunCancelCommand, DbtCloudRunGetArtifactCommand, @@ -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", diff --git a/tests/data/project_get_response.json b/tests/data/project_get_response.json new file mode 100644 index 0000000..f09afd8 --- /dev/null +++ b/tests/data/project_get_response.json @@ -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 + } +} \ No newline at end of file