-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
161 lines (129 loc) · 5.12 KB
/
utils.py
File metadata and controls
161 lines (129 loc) · 5.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import os
from pathlib import Path
from typing import Dict
from typing import Optional
import click
from requests import Response
from datapilot.clients.altimate.client import APIClient
def check_token_and_instance(
token: Optional[str],
instance_name: Optional[str],
):
if not token:
token = os.environ.get("ALTIMATE_API_KEY")
if not instance_name:
instance_name = os.environ.get("ALTIMATE_INSTANCE_NAME")
if not token or not instance_name:
click.echo(
"Error: API TOKEN and instance name is required. Please provide a valid API token."
" You can pass it as command line arguments or set it using environment variables like "
"ALTIMATE_API_KEY and ALTIMATE_INSTANCE_NAME."
)
return
def upload_content_to_signed_url(file_path, signed_url) -> Response:
api_client = APIClient()
with Path(file_path).open("rb") as file:
file_content = file.read()
return api_client.put(signed_url, data=file_content)
def validate_credentials(
token,
backend_url,
tenant,
) -> Response:
api_client = APIClient(api_token=token, base_url=backend_url, tenant=tenant)
return api_client.validate_credentials()
def validate_permissions(
token,
backend_url,
tenant,
) -> Response:
api_client = APIClient(api_token=token, base_url=backend_url, tenant=tenant)
return api_client.validate_upload_to_integration()
def onboard_file(api_token, tenant, dbt_core_integration_id, dbt_core_integration_environment, file_type, file_path, backend_url) -> Dict:
api_client = APIClient(api_token, base_url=backend_url, tenant=tenant)
params = {
"dbt_core_integration_id": dbt_core_integration_id,
"dbt_core_integration_environment_type": dbt_core_integration_environment,
"file_type": file_type,
}
signed_url_data = api_client.get_signed_url(params)
if signed_url_data:
signed_url = signed_url_data.get("url")
file_id = signed_url_data.get("dbt_core_integration_file_id")
api_client.log(f"Received signed URL: {signed_url}")
api_client.log(f"Received File ID: {file_id}")
upload_response = upload_content_to_signed_url(file_path, signed_url)
if upload_response:
verify_params = {"dbt_core_integration_file_id": file_id}
api_client.verify_upload(verify_params)
return {"ok": True}
else:
api_client.log(f"Error uploading file: {upload_response.status_code}, {upload_response.text}")
return {"ok": False, "message": f"Error uploading file: {upload_response.status_code}, {upload_response.text}"}
else:
api_client.log("Error getting signed URL.")
return {
"ok": False,
"message": "Error in uploading the manifest. ",
}
def start_dbt_ingestion(api_token, tenant, dbt_core_integration_id, dbt_core_integration_environment, backend_url):
api_client = APIClient(api_token, base_url=backend_url, tenant=tenant)
params = {
"dbt_core_integration_id": dbt_core_integration_id,
"dbt_core_integration_environment_type": dbt_core_integration_environment,
}
data = api_client.start_dbt_ingestion(params)
if data and data.get("ok"):
return {"ok": True}
else:
api_client.log("Error starting dbt ingestion worker")
return {
"ok": False,
"message": "Error starting dbt ingestion worker. ",
}
def get_project_governance_llm_checks(
api_token,
tenant,
backend_url,
):
api_client = APIClient(api_token=api_token, base_url=backend_url, tenant=tenant)
return api_client.get_project_governance_llm_checks()
def run_project_governance_llm_checks(
api_token,
tenant,
backend_url,
manifest,
catalog,
check_names,
):
api_client = APIClient(api_token=api_token, base_url=backend_url, tenant=tenant)
return api_client.run_project_governance_llm_checks(manifest, catalog, check_names)
def get_all_dbt_configs(
api_token,
tenant,
backend_url,
):
"""Get all DBT configs from the API."""
api_client = APIClient(api_token=api_token, base_url=backend_url, tenant=tenant)
return api_client.get_all_dbt_configs()
def get_all_integrations(
api_token,
tenant,
backend_url,
):
"""Get all integrations from the API."""
api_client = APIClient(api_token=api_token, base_url=backend_url, tenant=tenant)
return api_client.get_all_integrations()
def resolve_integration_name_to_id(
integration_name,
api_token,
tenant,
backend_url,
):
"""Resolve integration name to ID."""
integrations = get_all_integrations(api_token, tenant, backend_url)
if integrations:
matching_integrations = [i for i in integrations if i.get("name") == integration_name]
if matching_integrations:
return matching_integrations[0].get("id")
return None