Skip to content

Commit

Permalink
Merge pull request #92 from dpguthrie/feat/environment-variables
Browse files Browse the repository at this point in the history
Add methods for update, list env vars
  • Loading branch information
dpguthrie authored Jul 30, 2023
2 parents d6349d7 + f168bb4 commit db786a4
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.5.1] - 2023-07-30

### Added
- Methods to update and list environment variables

## [0.5.0] - 2023-07-28

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion dbtc/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.5.0'
__version__ = '0.5.1'
69 changes: 69 additions & 0 deletions dbtc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,58 @@ def list_credentials(
_dbt_cloud_request(ctx, 'list_credentials', account_id, project_id)


@app.command()
def list_environment_variables(
ctx: typer.Context,
account_id: int = ACCOUNT_ID,
project_id: int = PROJECT_ID,
resource_type: str = typer.Option(
'environment',
'--resource-type',
help='The name of the resource to retrieve',
),
environment_id: int = typer.Option(
None,
'--environment-id',
help='Numeric ID of the environment to retrieve',
),
job_id: int = typer.Option(
None,
'--job-id',
help='Numeric ID of the job to retrieve',
),
user_id: int = typer.Option(None, '--user-id', '-u', help='Numeric ID of the user'),
name: str = typer.Option(
None,
'--name',
help='The name of the environment',
),
type: str = typer.Option(
None,
'--type',
help='The type of environment (deployment or development)',
),
state: str = STATE,
offset: int = OFFSET,
limit: int = LIMIT,
):
_dbt_cloud_request(
ctx,
'list_environment_variables',
account_id,
project_id,
resource_type=resource_type,
environment_id=environment_id,
job_id=job_id,
user_id=user_id,
name=name,
type=type,
state=state,
offset=offset,
limit=limit,
)


@app.command()
def list_environments(
ctx: typer.Context,
Expand Down Expand Up @@ -1361,6 +1413,23 @@ def update_environment(
)


@app.command()
def update_environment_variables(
ctx: typer.Context,
account_id: int = ACCOUNT_ID,
project_id: int = PROJECT_ID,
payload: str = PAYLOAD,
):
"""Update environment variables."""
_dbt_cloud_request(
ctx,
'update_environment_variables',
account_id,
project_id,
json.loads(payload),
)


@app.command()
def update_job(
ctx: typer.Context,
Expand Down
89 changes: 87 additions & 2 deletions dbtc/client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,15 +886,29 @@ def list_audit_logs(
)

@v3
def list_connections(self, account_id: int, project_id: int) -> Dict:
def list_connections(
self,
account_id: int,
project_id: int,
*,
state: int = None,
offset: int = None,
limit: int = None,
) -> Dict:
"""List connections for a specific account and project
Args:
account_id (int): Numeric ID of the account to retrieve
project_id (int): Numeric ID of the project to retrieve
state (int, optional): 1 = active, 2 = deleted
offset (int, optional): The offset to apply when listing runs.
Use with limit to paginate results.
limit (int, optional): The limit to apply when listing runs.
Use with offset to paginate results.
"""
return self._simple_request(
f'accounts/{account_id}/projects/{project_id}/connections'
f'accounts/{account_id}/projects/{project_id}/connections',
params={'state': state, 'limit': limit, 'offset': offset},
)

@v3
Expand Down Expand Up @@ -962,6 +976,60 @@ def list_environments(
},
)

@v3
def list_environment_variables(
self,
account_id: int,
project_id: int,
*,
resource_type: str = 'environment',
environment_id: int = None,
job_id: int = None,
limit: int = None,
offset: int = None,
name: str = None,
state: int = None,
type: str = None,
user_id: int = None,
):
"""List environment variables for a specific account and project
Args:
account_id (int): Numeric ID of the account to retrieve
project_id (int): Numeric ID of he project to retrieve
resource_type (str, optional): The name of the resource to retrieve. Valid
resources include environment, job, and user
environment_id (int, optional): Numeric ID of the environment to retrieve
job_id (int, optional): Numeric ID of the job to retrieve
name (str, optional): Name of the environment to retrieve
type (str, optional): Type of the environment variable
state (int, optional): 1 = active, 2 = deleted
offset (int, optional): The offset to apply when listing runs.
Use with limit to paginate results.
limit (int, optional): The limit to apply when listing runs.
Use with offset to paginate results.
"""
valid_resource_types = ['environment', 'job', 'user']
if resource_type not in valid_resource_types:
raise ValueError(
f'{resource_type} is not a valid argument for resource_type. Valid '
f'resource types include {", ".join(valid_resource_types)}.'
)

return self._simple_request(
f'accounts/{account_id}/projects/{project_id}/environment-variables/{resource_type}', # noqa: E501
params={
'environment_id': environment_id,
'job_definition_id': job_id,
'name': name,
'type': type,
'state': state,
'offset': offset,
'limit': limit,
'user_id': user_id,
},
)

@v3
def list_feature_flags(self, account_id: int) -> Dict:
"""List feature flags for a specific account
Expand Down Expand Up @@ -1699,6 +1767,23 @@ def update_environment(
json=payload,
)

@v3
def update_environment_variables(
self, account_id: int, project_id: int, payload: Dict
):
"""Update an environment variable
Args:
account_id (int): Numeric ID of the account
project_id (int): Numeric ID of the project
payload (dict): Dictionary representing the environment to update
"""
return self._simple_request(
f'accounts/{account_id}/projects/{project_id}/environment-variables/bulk', # noqa: E501
method='post',
json=payload,
)

@v2
def update_job(self, account_id: int, job_id: int, payload: Dict) -> Dict:
"""Update a job by its ID.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dbtc"
version = "0.5.0"
version = "0.5.1"
description = "An unaffiliated python wrapper for dbt Cloud APIs"
authors = ["Doug Guthrie <douglas.p.guthrie@gmail.com>"]
documentation = "https://dbtc.dpguthrie.com"
Expand Down

0 comments on commit db786a4

Please sign in to comment.