Skip to content

Commit afa667b

Browse files
committed
feat: add functionality to resolve integration names to IDs and enhance onboarding options in CLI
1 parent 399448e commit afa667b

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

src/datapilot/clients/altimate/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ def get_all_dbt_configs(self):
110110
endpoint = "/dbtconfig/"
111111
params = {"size": 100}
112112
return self.get(endpoint, params=params)
113+
114+
def get_all_integrations(self):
115+
"""Get all integrations"""
116+
endpoint = "/dbt/v1/project_integrations/"
117+
return self.get(endpoint)

src/datapilot/clients/altimate/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,28 @@ def get_all_dbt_configs(
134134
"""Get all DBT configs from the API."""
135135
api_client = APIClient(api_token=api_token, base_url=backend_url, tenant=tenant)
136136
return api_client.get_all_dbt_configs()
137+
138+
139+
def get_all_integrations(
140+
api_token,
141+
tenant,
142+
backend_url,
143+
):
144+
"""Get all integrations from the API."""
145+
api_client = APIClient(api_token=api_token, base_url=backend_url, tenant=tenant)
146+
return api_client.get_all_integrations()
147+
148+
149+
def resolve_integration_name_to_id(
150+
integration_name,
151+
api_token,
152+
tenant,
153+
backend_url,
154+
):
155+
"""Resolve integration name to ID."""
156+
integrations = get_all_integrations(api_token, tenant, backend_url)
157+
if integrations:
158+
matching_integrations = [i for i in integrations if i.get("name") == integration_name]
159+
if matching_integrations:
160+
return matching_integrations[0].get("id")
161+
return None

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from datapilot.clients.altimate.utils import check_token_and_instance
77
from datapilot.clients.altimate.utils import get_all_dbt_configs
88
from datapilot.clients.altimate.utils import onboard_file
9+
from datapilot.clients.altimate.utils import resolve_integration_name_to_id
910
from datapilot.clients.altimate.utils import start_dbt_ingestion
1011
from datapilot.clients.altimate.utils import validate_credentials
1112
from datapilot.clients.altimate.utils import validate_permissions
@@ -136,9 +137,14 @@ def project_health(
136137
"--dbt_core_integration_id",
137138
"--dbt_integration_id",
138139
"dbt_integration_id", # This is the parameter name that will be passed to the function
139-
prompt="DBT Integration ID",
140140
help="DBT Core Integration ID or DBT Integration ID",
141141
)
142+
@click.option(
143+
"--dbt_core_integration_name",
144+
"--dbt_integration_name",
145+
"dbt_integration_name", # This is the parameter name that will be passed to the function
146+
help="DBT Core Integration Name or DBT Integration Name (alternative to ID)",
147+
)
142148
@click.option(
143149
"--dbt_core_integration_environment",
144150
"--dbt_integration_environment",
@@ -154,11 +160,12 @@ def onboard(
154160
instance_name,
155161
backend_url,
156162
dbt_integration_id,
163+
dbt_integration_name,
157164
dbt_integration_environment,
158165
manifest_path,
159166
catalog_path,
160167
):
161-
"""Onboard a manifest file to DBT."""
168+
"""Onboard a manifest file to DBT. You can specify either --dbt_integration_id or --dbt_integration_name."""
162169

163170
# For onboard command, token and instance_name are required
164171
if not token:
@@ -176,6 +183,21 @@ def onboard(
176183
click.echo("Error: You don't have permission to perform this action.")
177184
return
178185

186+
# Resolve integration name to ID if name is provided instead of ID
187+
if not dbt_integration_id and not dbt_integration_name:
188+
dbt_integration_id = click.prompt("DBT Integration ID")
189+
elif dbt_integration_name and not dbt_integration_id:
190+
click.echo(f"Resolving integration name '{dbt_integration_name}' to ID...")
191+
resolved_id = resolve_integration_name_to_id(dbt_integration_name, token, instance_name, backend_url)
192+
if resolved_id:
193+
dbt_integration_id = resolved_id
194+
click.echo(f"Found integration ID: {dbt_integration_id}")
195+
else:
196+
click.echo(f"Error: Integration with name '{dbt_integration_name}' not found.")
197+
return
198+
elif dbt_integration_name and dbt_integration_id:
199+
click.echo("Warning: Both integration ID and name provided. Using ID and ignoring name.")
200+
179201
try:
180202
load_manifest(manifest_path)
181203
except Exception as e:

0 commit comments

Comments
 (0)