Skip to content

Commit

Permalink
Merge pull request #104 from dpguthrie/fix/list-environments
Browse files Browse the repository at this point in the history
Fix/list environments
  • Loading branch information
dpguthrie authored Apr 6, 2024
2 parents 3fc1f6b + 16d9c0a commit ad52d4c
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 122 deletions.
63 changes: 46 additions & 17 deletions dbtc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,14 +858,20 @@ def delete_environment(
def list_environments_old(
ctx: typer.Context,
account_id: int = ACCOUNT_ID,
project_id: str = typer.Option(
None, "--project-id", "-p", help="The project ID or IDs"
project_id: str = PROJECT_ID,
credentials_id: int = typer.Option(
None, "--credentials-id", help="Numeric ID of the credentials."
),
dbt_version: str = typer.Option(
None,
"--dbt-version",
help="The dbt version(s) used in the environment",
),
deployment_type: str = typer.Option(
None,
"--deployment-type",
help="The deployment type of the environment",
),
name: str = typer.Option(
None,
"--name",
Expand All @@ -886,28 +892,36 @@ def list_environments_old(
ctx,
account_id,
project_id,
dbt_version,
name,
type,
state,
offset,
limit,
order_by,
credentials_id=credentials_id,
dbt_version=dbt_version,
deployment_type=deployment_type,
name=name,
type=type,
state=state,
offset=offset,
limit=limit,
order_by=order_by,
)


@environments_app.command("list")
def list_environments(
ctx: typer.Context,
account_id: int = ACCOUNT_ID,
project_id: str = typer.Option(
None, "--project-id", "-p", help="The project ID or IDs"
),
project_id: str = PROJECT_ID,
dbt_version: str = typer.Option(
None,
"--dbt-version",
help="The dbt version(s) used in the environment",
),
deployment_type: str = typer.Option(
None,
"--deployment-type",
help="The deployment type of the environment",
),
credentials_id: int = typer.Option(
None, "--credentials-id", help="Numeric ID of the credentials."
),
name: str = typer.Option(
None,
"--name",
Expand All @@ -929,12 +943,19 @@ def list_environments(
except (ValueError, TypeError):
pass

try:
deployment_type = json.loads(deployment_type)
except (ValueError, TypeError):
pass

_dbt_cloud_request(
ctx,
"list_environments",
account_id,
project_id=json.loads(project_id) if project_id else project_id,
project_id,
dbt_version=dbt_version,
deployment_type=deployment_type,
credentials_id=credentials_id,
name=name,
type=type,
state=state,
Expand Down Expand Up @@ -987,7 +1008,9 @@ def assign_group_permissions_old(
group_id: int = GROUP_ID,
payload: str = PAYLOAD,
):
"""This will soon be deprecated! Use `dbtc user-groups assign-permissions` instead."""
"""This will soon be deprecated! Use `dbtc user-groups assign-permissions`
instead.
"""
return assign_group_permissions(ctx, account_id, group_id, payload)


Expand Down Expand Up @@ -1771,7 +1794,9 @@ def get_most_recent_run_artifact_old(
None, "--step", "-s", help="Index of the step in the run to retrieve"
),
):
"""This will soon be deprecated! Use `dbtc runs get-most-recent-artifact` instead."""
"""
This will soon be deprecated! Use `dbtc runs get-most-recent-artifact` instead.
"""
return get_most_recent_run_artifact(
ctx,
account_id,
Expand Down Expand Up @@ -2055,7 +2080,9 @@ def assign_service_token_permissions_old(
service_token_id: int = SERVICE_TOKEN_ID,
payload: str = PAYLOAD,
):
"""This will soon be deprecated! Use `dbtc service-tokens assign-permissions` instead."""
"""
This will soon be deprecated! Use `dbtc service-tokens assign-permissions` instead.
"""
return assign_service_token_permissions(ctx, account_id, service_token_id, payload)


Expand Down Expand Up @@ -2098,7 +2125,9 @@ def list_service_token_permissions_old(
account_id: int = ACCOUNT_ID,
service_token_id: int = SERVICE_TOKEN_ID,
):
"""This will soon be deprecated! Use `dbtc service-tokens list-permissions` instead."""
"""
This will soon be deprecated! Use `dbtc service-tokens list-permissions` instead.
"""
return list_service_token_permissions(ctx, account_id, service_token_id)


Expand Down
44 changes: 28 additions & 16 deletions dbtc/client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def delete_credentials(
credentials_id (int): Numeric ID of the credentials to delete
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/credentials/{credentials_id}/",
f"accounts/{account_id}/projects/{project_id}/credentials/{credentials_id}/", # noqa: E501
method="delete",
)

Expand All @@ -351,7 +351,7 @@ def get_credentials(
credentials_id (int): Numeric ID of the credentials to retrieve
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/credentials/{credentials_id}/",
f"accounts/{account_id}/projects/{project_id}/credentials/{credentials_id}/", # noqa: E501
)

@v3
Expand Down Expand Up @@ -379,7 +379,7 @@ def partial_update_credentials(
payload (dict): Dictionary representing the credentials to update
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/credentials/{credentials_id}/",
f"accounts/{account_id}/projects/{project_id}/credentials/{credentials_id}/", # noqa: E501
method="patch",
json=payload,
)
Expand Down Expand Up @@ -446,7 +446,7 @@ def delete_env_vars(
env_var_id (int): Numeric ID of the environment variable to delete
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/environment-variables/{env_var_id}/",
f"accounts/{account_id}/projects/{project_id}/environment-variables/{env_var_id}/", # noqa: E501
method="delete",
)

Expand Down Expand Up @@ -535,7 +535,7 @@ def update_env_vars(
payload (dict): Dictionary representing the environment variables to update
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/environment-variables/{env_var_id}/",
f"accounts/{account_id}/projects/{project_id}/environment-variables/{env_var_id}/", # noqa: E501
method="post",
json=payload,
)
Expand Down Expand Up @@ -609,23 +609,28 @@ def get_environment(
def list_environments(
self,
account_id: int,
project_id: int,
*,
project_id: Union[int, List[int]] = None,
dbt_version: Union[str, List[str]] = None,
deployment_type: Union[str, List[str]] = None,
credentials_id: int = None,
name: str = None,
type: str = None,
state: int = None,
offset: int = None,
limit: int = None,
order_by: str = None,
) -> Dict:
"""List environments for a specific account
"""List environments for a specific account and project
Args:
account_id (int): Numeric ID of the account to retrieve
project_id (int or list, optional): The project ID or IDs
dbt_version (str or list, optional): The version of dbt the environment
is using
deployment_type (str or list, optional): The deployment type of the
environment. Valid values are "staging" and "production"
credentials_id (int, optional): Numeric ID of the credentials to retrieve
name (str, optional): Name of the environment to retrieve
type (str, optional): Type of the environment (deployment or development)
state (int, optional): 1 = active, 2 = deleted
Expand All @@ -636,10 +641,11 @@ def list_environments(
order_by (str, optional): Field to order the result by.
"""
return self._simple_request(
f"accounts/{account_id}/environments/",
f"accounts/{account_id}/projects/{project_id}/environments/",
params={
"project_id__in": json_listify(project_id),
"dbt_version__in": json_listify(dbt_version),
"deployment_type__in": json_listify(deployment_type),
"credentials_id": credentials_id,
"name": name,
"type": type,
"state": state,
Expand Down Expand Up @@ -1143,10 +1149,11 @@ def create_sl_config(self, account_id: int, project_id: int, payload: Dict) -> D
Args:
account_id (int): Numeric ID of the account
project_id (int): Numeric ID of the project
payload (dict): Dictionary representing the semantic layer configuration to create
payload (dict): Dictionary representing the semantic layer configuration to
create
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/semantic-layer-configurations",
f"accounts/{account_id}/projects/{project_id}/semantic-layer-configurations", # noqa: E501
method="post",
json=payload,
)
Expand Down Expand Up @@ -1176,7 +1183,8 @@ def get_sl_config(
Args:
account_id (int): Numeric ID of the account to retrieve
project_id (int): Numeric ID of the project to retrieve
sl_config_id (int): Numeric ID of the semantic layer configuration to retrieve
sl_config_id (int): Numeric ID of the semantic layer configuration to
retrieve
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/semantic-layer-configurations/{sl_config_id}" # noqa: E501
Expand All @@ -1192,7 +1200,8 @@ def update_sl_config(
account_id (int): Numeric ID of the account
project_id (int): Numeric ID of the project
sl_config_id (int): Numeric ID of the semantic layer configuration to update
payload (dict): Dictionary representing the semantic layer configuration to update
payload (dict): Dictionary representing the semantic layer configuration to
update
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/semantic-layer-configurations/{sl_config_id}", # noqa: E501
Expand All @@ -1209,7 +1218,8 @@ def create_sl_creds(self, account_id: int, project_id: int, payload: Dict) -> Di
Args:
account_id (int): Numeric ID of the account
project_id (int): Numeric ID of the project
payload (dict): Dictionary representing the semantic layer credential to create
payload (dict): Dictionary representing the semantic layer credential to
create
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/semantic-layer-credentials",
Expand Down Expand Up @@ -1256,7 +1266,8 @@ def partially_update_sl_creds(
account_id (int): Numeric ID of the account
project_id (int): Numeric ID of the project
sl_creds_id (int): Numeric ID of the semantic layer credential to update
payload (dict): Dictionary representing the semantic layer credential to update
payload (dict): Dictionary representing the semantic layer credential to
update
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/semantic-layer-credentials/{sl_creds_id}", # noqa: E501
Expand All @@ -1274,7 +1285,8 @@ def update_sl_creds(
account_id (int): Numeric ID of the account
project_id (int): Numeric ID of the project
sl_creds_id (int): Numeric ID of the semantic layer credential to update
payload (dict): Dictionary representing the semantic layer credential to update
payload (dict): Dictionary representing the semantic layer credential to
update
"""
return self._simple_request(
f"accounts/{account_id}/projects/{project_id}/semantic-layer-credentials/{sl_creds_id}", # noqa: E501
Expand Down
27 changes: 27 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,33 @@ def test_get_project():
)


@pytest.mark.dependency(depends=["test_list_projects"])
def test_list_environments_old():
_test_cloud_cli(
[
"list-environments",
"--account-id",
ACCOUNT_ID,
"--project-id",
PROJECT_ID,
],
)


@pytest.mark.dependency(depends=["test_list_projects"])
def test_list_environments():
_test_cloud_cli(
[
"environments",
"list",
"--account-id",
ACCOUNT_ID,
"--project-id",
PROJECT_ID,
],
)


@pytest.mark.dependency(depends=["test_list_projects"])
def test_list_jobs_old():
_test_cloud_cli(
Expand Down
Loading

0 comments on commit ad52d4c

Please sign in to comment.