Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Updates DbtCloudCredentials to implement CredentialsBlock interface #109

Merged
merged 5 commits into from
Dec 28, 2022

Conversation

desertaxle
Copy link
Member

@desertaxle desertaxle commented Dec 28, 2022

Updates DbtCloudCredentials to implement CredentialsBlock interface. In order to achieve this, I added an additional DbtCloudMetadataClient for querying the dbt Cloud metadata API. The DbtCloudCredentials block is now able to return two different clients with its .get_client method.

Example

Using the metadata client:

from prefect_dbt import DbtCloudCredentials

credentials_block = DbtCloudCredentials.load("test-account")
metadata_client = credentials_block.get_client("metadata")
query = """
{
  metrics(jobId: 123) {
    uniqueId
    name
    packageName
    tags
    label
    runId
    description
    type
    sql
    timestamp
    timeGrains
    dimensions
    meta
    resourceType
    filters {
       field
       operator
       value
     }
    model {
      name
    }
  }
}
"""
metadata_client.query(query)
# Result:
# {
#   "data": {
#     "metrics": [
#       {
#         "uniqueId": "metric.tpch.total_revenue",
#         "name": "total_revenue",
#         "packageName": "tpch",
#         "tags": [],
#         "label": "Total Revenue ($)",
#         "runId": 108952046,
#         "description": "",
#         "type": "sum",
#         "sql": "net_item_sales_amount",
#         "timestamp": "order_date",
#         "timeGrains": ["day", "week", "month"],
#         "dimensions": ["status_code", "priority_code"],
#         "meta": {},
#         "resourceType": "metric",
#         "filters": [],
#         "model": { "name": "fct_orders" }
#       }
#     ]
#   }
# }

Screenshots

Screenshot 2022-12-28 at 9 18 39 AM

Checklist

  • References any related issue by including "Closes #" or "Closes ".
    • If no issue exists and your change is not a small fix, please create an issue first.
  • Includes tests or only affects documentation.
  • Passes pre-commit checks.
    • Run pre-commit install && pre-commit run --all locally for formatting and linting.
  • Includes screenshots of documentation updates.
    • Run mkdocs serve view documentation locally.
  • Summarizes PR's changes in CHANGELOG.md

@desertaxle desertaxle marked this pull request as ready for review December 28, 2022 16:12
@desertaxle desertaxle requested a review from a team December 28, 2022 16:31
Copy link
Contributor

@ahuang11 ahuang11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!


credentials_block = DbtCloudCredentials.load("test-account")
metadata_client = credentials_block.get_metadata_client()
query = \"\"\"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the \ needed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, need to escape the quotes so that the docstring continues.

@desertaxle desertaxle merged commit 21d31e6 into main Dec 28, 2022
@desertaxle desertaxle deleted the implement-credentials-block branch December 28, 2022 19:56
ahuang11 pushed a commit that referenced this pull request Jan 4, 2023
…ce (#109)

* Adds metadata client

* Enhances docstrings

* Adds tests

* Adds changelog entry
ahuang11 added a commit that referenced this pull request Jan 31, 2023
* Restrict target configs keys

* Undo async

* Remove async

* Support secret dict (#107)

* Updates `DbtCloudCredentials` to implement `CredentialsBlock` interface (#109)

* Adds metadata client

* Enhances docstrings

* Adds tests

* Adds changelog entry

* prep v0.2.7 release (#110)

* Fix private_keys

* Add keys to restrict

* Add schema to rename

* Fix tests

* Update chagnelog

* Add tests

* Add examples

* FIx reqs

* Maybe fix reqs

* Update CHANGELOG.md

* Move breaking change in a separate PR

* Remove breaking change in this PR

* Update .pre-commit-config.yaml

---------

Co-authored-by: Alexander Streed <desertaxle@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants