Skip to content

Commit f120111

Browse files
gaurpulkitmdesmet
andauthored
feat: add config name support (#50)
* add config name support * changes * update doc * Fix access property --------- Co-authored-by: Michiel De Smet <[email protected]>
1 parent 78bd444 commit f120111

File tree

7 files changed

+71
-6
lines changed

7 files changed

+71
-6
lines changed

docs/features.rst

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@ You can also select specific list of models to run the health check on by provid
4242
4343
datapilot dbt project-health --manifest-path ./target/manifest.json --select "path:dir1 path:dir2 model1 model2"
4444
45-
This will run the health check on all the models in the 'dir1' and 'dir2' directory. It will also run the health check on the 'model1' and 'model2' models.
45+
This will run the health check on all the models in the 'dir1' and 'dir2' directory, as well as the 'model1' and 'model2' models.
4646
As of now, the '--select' flag only supports filtering based on model path and model name. We will add support for other filters and make it compatible
47-
with the dbt comands soon.
47+
with the dbt commands soon.
48+
49+
3. **Configuration**:
50+
You can provide configuration in two ways:
51+
52+
a. Using a local config file:
53+
.. code-block:: shell
54+
55+
datapilot dbt project-health --manifest-path ./target/manifest.json --config-path ./path/to/config.yml
56+
57+
b. Using a named config from the API:
58+
.. code-block:: shell
59+
60+
datapilot dbt project-health --manifest-path ./target/manifest.json --config-name "my-config" --token "YOUR_API_TOKEN" --instance-name "YOUR_INSTANCE"
61+
62+
The ``--config-name`` option allows you to use a configuration stored in the Altimate API. When using this option, you must also provide:
63+
- ``--token``: Your API token for authentication
64+
- ``--instance-name``: Your tenant ID
65+
66+
If both ``--config-path`` and ``--config-name`` are provided, the local config file (``--config-path``) takes precedence.

src/datapilot/clients/altimate/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,9 @@ def run_project_governance_llm_checks(self, manifest, catalog, check_names):
104104
"check_names": check_names,
105105
}
106106
return self.post(endpoint, data=data)
107+
108+
def get_all_dbt_configs(self):
109+
"""Get all DBT configs with a page size of 100."""
110+
endpoint = "/dbtconfig/"
111+
params = {"size": 100}
112+
return self.get(endpoint, params=params)

src/datapilot/clients/altimate/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,13 @@ def run_project_governance_llm_checks(
124124
):
125125
api_client = APIClient(api_token=api_token, base_url=backend_url, tenant=tenant)
126126
return api_client.run_project_governance_llm_checks(manifest, catalog, check_names)
127+
128+
129+
def get_all_dbt_configs(
130+
api_token,
131+
tenant,
132+
backend_url,
133+
):
134+
"""Get all DBT configs from the API."""
135+
api_client = APIClient(api_token=api_token, base_url=backend_url, tenant=tenant)
136+
return api_client.get_all_dbt_configs()

src/datapilot/core/platforms/dbt/cli/cli.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import click
44

55
from datapilot.clients.altimate.utils import check_token_and_instance
6+
from datapilot.clients.altimate.utils import get_all_dbt_configs
67
from datapilot.clients.altimate.utils import onboard_file
78
from datapilot.clients.altimate.utils import start_dbt_ingestion
89
from datapilot.clients.altimate.utils import validate_credentials
@@ -45,6 +46,11 @@ def dbt():
4546
required=False,
4647
help="Path to the DBT config file",
4748
)
49+
@click.option(
50+
"--config-name",
51+
required=False,
52+
help="Name of the DBT config to use from the API",
53+
)
4854
@click.option(
4955
"--select",
5056
required=False,
@@ -53,7 +59,14 @@ def dbt():
5359
)
5460
@click.option("--backend-url", required=False, help="Altimate's Backend URL", default="https://api.myaltimate.com")
5561
def project_health(
56-
token, instance_name, manifest_path, catalog_path, config_path=None, select=None, backend_url="https://api.myaltimate.com"
62+
token,
63+
instance_name,
64+
manifest_path,
65+
catalog_path,
66+
config_path=None,
67+
config_name=None,
68+
select=None,
69+
backend_url="https://api.myaltimate.com",
5770
):
5871
"""
5972
Validate the DBT project's configuration and structure.
@@ -62,6 +75,23 @@ def project_health(
6275
config = None
6376
if config_path:
6477
config = load_config(config_path)
78+
elif config_name and token and instance_name:
79+
# Get configs from API
80+
configs = get_all_dbt_configs(token, instance_name, backend_url)
81+
if configs and "items" in configs:
82+
# Find config by name
83+
matching_configs = [c for c in configs["items"] if c["name"] == config_name]
84+
if matching_configs:
85+
# Get the config directly from the API response
86+
click.echo(f"Using config: {config_name}")
87+
config = matching_configs[0].get("config", {})
88+
else:
89+
click.echo(f"No config found with name: {config_name}")
90+
return
91+
else:
92+
click.echo("Failed to fetch configs from API")
93+
return
94+
6595
selected_models = []
6696
if select:
6797
selected_models = select.split(" ")

src/datapilot/core/platforms/dbt/wrappers/manifest/v10/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _get_node(self, node: ManifestNode) -> AltimateManifestNode:
116116
contract=contract,
117117
meta=node.meta,
118118
patch_path=node.patch_path,
119-
access=node.access.value,
119+
access=getattr(node.access, "value", None) if hasattr(node, "access") and node.access is not None else None,
120120
)
121121

122122
def _get_source(self, source: SourceNode) -> AltimateManifestSourceNode:

src/datapilot/core/platforms/dbt/wrappers/manifest/v11/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _get_node(self, node: ManifestNode) -> AltimateManifestNode:
116116
contract=contract,
117117
meta=node.meta,
118118
patch_path=node.patch_path,
119-
access=node.access.value,
119+
access=getattr(node.access, "value", None) if hasattr(node, "access") and node.access is not None else None,
120120
)
121121

122122
def _get_source(self, source: SourceNode) -> AltimateManifestSourceNode:

src/datapilot/core/platforms/dbt/wrappers/manifest/v12/wrapper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _get_node(self, node: ManifestNode) -> AltimateManifestNode:
116116
contract=contract,
117117
meta=node.meta,
118118
patch_path=node.patch_path,
119-
access=node.access.value,
119+
access=getattr(node.access, "value", None) if hasattr(node, "access") and node.access is not None else None,
120120
)
121121

122122
def _get_source(self, source: SourceNode) -> AltimateManifestSourceNode:

0 commit comments

Comments
 (0)