-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
dbt-cloud environment create
command (#91)
* Add DbtCloudEnvironmentCreateCommand class * Fix environment commands now inherit DbtCloudProjectCommand * Add unit test * Add test_cli_environment_create_and_delete integration test * Update README * Fix docstrings --------- Co-authored-by: Simo Tumelius <simo@datamie.fi>
- Loading branch information
1 parent
26df2cc
commit 8481929
Showing
13 changed files
with
291 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .list import DbtCloudEnvironmentListCommand | ||
from .get import DbtCloudEnvironmentGetCommand | ||
from .create import DbtCloudEnvironmentCreateCommand | ||
from .delete import DbtCloudEnvironmentDeleteCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import requests | ||
from typing import Optional | ||
from pydantic import Field | ||
from dbt_cloud.command.command import DbtCloudProjectCommand | ||
from dbt_cloud.field import DBT_VERSION_FIELD | ||
|
||
|
||
class DbtCloudEnvironmentCreateCommand(DbtCloudProjectCommand): | ||
"""Creates a new dbt Cloud environment in a given project.""" | ||
|
||
name: str = Field( | ||
description="Name of the environment.", | ||
) | ||
id: Optional[int] | ||
connection_id: Optional[int] = Field( | ||
description="Connection ID to use for this environment.", | ||
) | ||
credentials_id: Optional[int] = Field( | ||
description="Credentials ID to use for this environment.", | ||
) | ||
created_by_id: Optional[int] = Field( | ||
description="User ID of the user who created this environment.", | ||
) | ||
dbt_project_subdirectory: Optional[str] = Field( | ||
description="Subdirectory of the dbt project to use for this environment.", | ||
) | ||
use_custom_branch: bool = Field( | ||
False, | ||
description="Whether to use a custom branch for this environment.", | ||
) | ||
custom_branch: Optional[str] = Field( | ||
description="Custom branch to use for this environment.", | ||
) | ||
dbt_version: Optional[str] = DBT_VERSION_FIELD | ||
raw_dbt_version: Optional[str] = Field( | ||
description="Raw dbt version to use for this environment.", | ||
) | ||
supports_docs: bool = Field( | ||
False, | ||
description="Whether this environment supports docs.", | ||
) | ||
repository_id: Optional[int] = Field( | ||
description="Repository ID to use for this environment.", | ||
) | ||
state: int = Field( | ||
1, | ||
description="State of the environment. 1 = Active.", | ||
) | ||
custom_environment_variables: Optional[dict] = Field( | ||
description="Custom environment variables to use for this environment.", | ||
) | ||
|
||
@property | ||
def api_url(self) -> str: | ||
return f"{super().api_url}/environments" | ||
|
||
def execute(self) -> requests.Response: | ||
response = requests.post( | ||
url=self.api_url, | ||
headers=self.request_headers, | ||
json=self.get_payload(exclude_empty=True), | ||
) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
{ | ||
"status": { | ||
"code": 201, | ||
"is_success": true, | ||
"user_message": "Success!", | ||
"developer_message": "" | ||
}, | ||
"data": { | ||
"id": 222601, | ||
"account_id": 123456, | ||
"project_id": 123457, | ||
"credentials_id": null, | ||
"name": "pytest environment", | ||
"dbt_version": "1.6.0-latest", | ||
"raw_dbt_version": "1.6.0-latest", | ||
"type": "deployment", | ||
"use_custom_branch": false, | ||
"custom_branch": null, | ||
"supports_docs": false, | ||
"state": 1, | ||
"created_at": null, | ||
"updated_at": "2023-08-03 11:53:02.868229+00:00", | ||
"project": { | ||
"name": "jaffle_shop", | ||
"account_id": 123456, | ||
"connection_id": 32544, | ||
"repository_id": 40480, | ||
"semantic_layer_config_id": null, | ||
"id": 26597, | ||
"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": 32544, | ||
"account_id": 123456, | ||
"project_id": 123457, | ||
"name": "Bigquery", | ||
"type": "bigquery", | ||
"created_by_id": 1321515, | ||
"created_by_service_token_id": null, | ||
"details": { | ||
"project_id": "ANONYMIZED", | ||
"timeout_seconds": 300, | ||
"private_key_id": "ANONYMIZED", | ||
"client_email": "ANONYMIZED", | ||
"client_id": "ANONYMIZED", | ||
"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": "https://www.googleapis.com/robot/v1/metadata/x509/dbt-user%40ANONYMIZED", | ||
"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, | ||
"gcs_bucket": null, | ||
"dataproc_region": null, | ||
"dataproc_cluster_name": null | ||
}, | ||
"state": 1, | ||
"created_at": "2021-11-16 16:26:01.571115+00:00", | ||
"updated_at": "2022-05-18 06:27:34.729528+00:00", | ||
"private_link_endpoint_id": null | ||
}, | ||
"repository": { | ||
"id": 40480, | ||
"account_id": 123456, | ||
"project_id": 123457, | ||
"full_name": "ANONYMIZED", | ||
"remote_url": "ANONYMIZED", | ||
"remote_backend": "github", | ||
"git_clone_strategy": "github_app", | ||
"deploy_key_id": 39445, | ||
"repository_credentials_id": null, | ||
"github_installation_id": 19320059, | ||
"github_webhook_id": null, | ||
"pull_request_url_template": "ANONYMIZED", | ||
"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": 39445, | ||
"account_id": 123456, | ||
"state": 1, | ||
"public_key": "ssh-rsa ANONYMIZED" | ||
}, | ||
"github_repo": "ANONYMIZED", | ||
"name": "dbt-cloud-cli", | ||
"git_provider_id": 9437, | ||
"gitlab": null, | ||
"git_provider": null | ||
}, | ||
"group_permissions": null, | ||
"docs_job_id": null, | ||
"freshness_job_id": null, | ||
"docs_job": null, | ||
"freshness_job": null | ||
}, | ||
"jobs": null, | ||
"credentials": null, | ||
"custom_environment_variables": null, | ||
"deployment_type": null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.