recce-nightly 1.15.0.20250806__py3-none-any.whl → 1.26.0.20251124__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of recce-nightly might be problematic. Click here for more details.
- recce/VERSION +1 -1
- recce/__init__.py +5 -0
- recce/adapter/dbt_adapter/__init__.py +12 -3
- recce/artifact.py +74 -1
- recce/cli.py +642 -101
- recce/config.py +2 -2
- recce/connect_to_cloud.py +1 -1
- recce/core.py +2 -2
- recce/data/404.html +1 -1
- recce/data/__next.__PAGE__.txt +10 -0
- recce/data/__next._full.txt +23 -0
- recce/data/__next._head.txt +8 -0
- recce/data/__next._index.txt +8 -0
- recce/data/__next._tree.txt +5 -0
- recce/data/_next/static/52aV_JrNUZU6dMFgvTQEO/_buildManifest.js +11 -0
- recce/data/_next/static/52aV_JrNUZU6dMFgvTQEO/_clientMiddlewareManifest.json +1 -0
- recce/data/_next/static/chunks/02b996c7f6a29a06.js +4 -0
- recce/data/_next/static/chunks/19c10d219a6a21ff.js +1 -0
- recce/data/_next/static/chunks/2df9ec28a061971d.js +11 -0
- recce/data/_next/static/chunks/3098c987393bda15.js +1 -0
- recce/data/_next/static/chunks/393dc43e483f717a.css +2 -0
- recce/data/_next/static/chunks/399e8d91a7e45073.js +2 -0
- recce/data/_next/static/chunks/4d0186f631230245.js +1 -0
- recce/data/_next/static/chunks/5794ba9e10a9c060.js +11 -0
- recce/data/_next/static/chunks/715761c929a3f28b.js +110 -0
- recce/data/_next/static/chunks/71f88fcc615bf282.js +1 -0
- recce/data/_next/static/chunks/80d2a95eaf1201ea.js +1 -0
- recce/data/_next/static/chunks/9979c6109bbbee35.js +1 -0
- recce/data/_next/static/chunks/99d638224186c118.js +1 -0
- recce/data/_next/static/chunks/d003eb36240e92f3.js +1 -0
- recce/data/_next/static/chunks/d3167cdfec4fc351.js +1 -0
- recce/data/_next/static/chunks/e124bccf574a3361.css +1 -0
- recce/data/_next/static/chunks/f40141db1bdb46f0.css +6 -0
- recce/data/_next/static/chunks/fcc53a88741a52f9.js +1 -0
- recce/data/_next/static/chunks/turbopack-b1920d28cfb1f28d.js +3 -0
- recce/data/_next/static/media/favicon.a8d38d84.ico +0 -0
- recce/data/_next/static/media/montserrat-cyrillic-800-normal.d80d830d.woff2 +0 -0
- recce/data/_next/static/media/{montserrat-cyrillic-800-normal.bd5c9f50.woff → montserrat-cyrillic-800-normal.f9d58125.woff} +0 -0
- recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.076c2a93.woff2 +0 -0
- recce/data/_next/static/media/montserrat-latin-800-normal.cde454cc.woff2 +0 -0
- recce/data/_next/static/media/{montserrat-latin-800-normal.fc315020.woff → montserrat-latin-800-normal.d5761935.woff} +0 -0
- recce/data/_next/static/media/montserrat-latin-ext-800-normal.40ec0659.woff2 +0 -0
- recce/data/_next/static/media/{montserrat-latin-ext-800-normal.2e5381b2.woff → montserrat-latin-ext-800-normal.b671449b.woff} +0 -0
- recce/data/_next/static/media/{montserrat-vietnamese-800-normal.20c545e6.woff → montserrat-vietnamese-800-normal.9f7b8541.woff} +0 -0
- recce/data/_next/static/media/montserrat-vietnamese-800-normal.f9eb854e.woff2 +0 -0
- recce/data/_not-found/__next._full.txt +17 -0
- recce/data/_not-found/__next._head.txt +8 -0
- recce/data/_not-found/__next._index.txt +8 -0
- recce/data/_not-found/__next._not-found.__PAGE__.txt +5 -0
- recce/data/_not-found/__next._not-found.txt +4 -0
- recce/data/_not-found/__next._tree.txt +3 -0
- recce/data/_not-found.html +1 -0
- recce/data/_not-found.txt +17 -0
- recce/data/index.html +1 -1
- recce/data/index.txt +21 -23
- recce/event/__init__.py +9 -8
- recce/event/collector.py +3 -1
- recce/event/track.py +10 -0
- recce/github.py +1 -1
- recce/mcp_server.py +716 -0
- recce/models/types.py +35 -2
- recce/pull_request.py +1 -1
- recce/run.py +2 -2
- recce/server.py +105 -3
- recce/state/__init__.py +31 -0
- recce/state/cloud.py +632 -0
- recce/state/const.py +26 -0
- recce/state/local.py +56 -0
- recce/state/state.py +119 -0
- recce/state/state_loader.py +174 -0
- recce/summary.py +21 -1
- recce/tasks/dataframe.py +63 -1
- recce/tasks/rowcount.py +4 -1
- recce/tasks/schema.py +4 -1
- recce/util/api_token.py +9 -2
- recce/util/breaking.py +1 -1
- recce/util/io.py +2 -2
- recce/util/lineage.py +14 -18
- recce/util/recce_cloud.py +187 -7
- recce/yaml/__init__.py +2 -2
- recce_cloud/__init__.py +24 -0
- recce_cloud/api/__init__.py +17 -0
- recce_cloud/api/base.py +111 -0
- recce_cloud/api/client.py +150 -0
- recce_cloud/api/exceptions.py +26 -0
- recce_cloud/api/factory.py +63 -0
- recce_cloud/api/github.py +76 -0
- recce_cloud/api/gitlab.py +82 -0
- recce_cloud/artifact.py +57 -0
- recce_cloud/ci_providers/__init__.py +9 -0
- recce_cloud/ci_providers/base.py +82 -0
- recce_cloud/ci_providers/detector.py +147 -0
- recce_cloud/ci_providers/github_actions.py +136 -0
- recce_cloud/ci_providers/gitlab_ci.py +130 -0
- recce_cloud/cli.py +245 -0
- recce_cloud/upload.py +214 -0
- {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/METADATA +54 -28
- recce_nightly-1.26.0.20251124.dist-info/RECORD +180 -0
- {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/top_level.txt +1 -0
- tests/adapter/dbt_adapter/test_dbt_cll.py +4 -2
- tests/recce_cloud/__init__.py +0 -0
- tests/recce_cloud/test_ci_providers.py +351 -0
- tests/recce_cloud/test_cli.py +372 -0
- tests/recce_cloud/test_client.py +273 -0
- tests/recce_cloud/test_platform_clients.py +333 -0
- tests/test_cli.py +106 -3
- tests/test_cli_mcp_optional.py +45 -0
- tests/test_cloud_listing_cli.py +324 -0
- tests/test_core.py +147 -0
- tests/test_mcp_server.py +332 -0
- tests/test_server.py +6 -6
- tests/test_summary.py +14 -6
- recce/data/_next/static/Q_5ThPsmamd4VAGXuqwgi/_buildManifest.js +0 -1
- recce/data/_next/static/chunks/0376eeba-3db2196398d62270.js +0 -1
- recce/data/_next/static/chunks/068b80ea-833a129468ee1622.js +0 -1
- recce/data/_next/static/chunks/0ddaf06c-c7961285f66460f6.js +0 -1
- recce/data/_next/static/chunks/1268aea1-6dc1251c01bd724b.js +0 -54
- recce/data/_next/static/chunks/12f8fac4-16838e42d28d45c3.js +0 -1
- recce/data/_next/static/chunks/235b8375-8c84c51d7bd4f6aa.js +0 -1
- recce/data/_next/static/chunks/2541941f-2cd3a7c2d629bd33.js +0 -1
- recce/data/_next/static/chunks/273-f3fa401bd2b6fc91.js +0 -10
- recce/data/_next/static/chunks/2fc37c1e-910deebeb3d77c90.js +0 -1
- recce/data/_next/static/chunks/338-2e7eed5135c64550.js +0 -30
- recce/data/_next/static/chunks/367-ab8b16dd5f8586ca.js +0 -1
- recce/data/_next/static/chunks/3a92ee20-0400ffe460c7c803.js +0 -1
- recce/data/_next/static/chunks/62446465-423c03bb8c1f59b6.js +0 -1
- recce/data/_next/static/chunks/6af7f9e9-60aa8706f49dae45.js +0 -1
- recce/data/_next/static/chunks/6cf54382-49d52ae6e564e2ac.js +0 -1
- recce/data/_next/static/chunks/6dc81886-78e2efe4538794ae.js +0 -1
- recce/data/_next/static/chunks/715e4acc-9e2e6df4eb3809d1.js +0 -1
- recce/data/_next/static/chunks/72-181b430654230f0e.js +0 -1
- recce/data/_next/static/chunks/786-774e3e3ed70a41b3.js +0 -1
- recce/data/_next/static/chunks/8d700b6a.7fe2c8c3f4e333a6.js +0 -1
- recce/data/_next/static/chunks/a69d64b4-d6890125a87b0aba.js +0 -1
- recce/data/_next/static/chunks/ae307f12-01100009689ace61.js +0 -1
- recce/data/_next/static/chunks/app/_not-found/page-c7ef8ed6dc07aaeb.js +0 -1
- recce/data/_next/static/chunks/app/layout-744f0a78e9e50e60.js +0 -1
- recce/data/_next/static/chunks/app/page-e8f798c2ae3f59c2.js +0 -1
- recce/data/_next/static/chunks/c0015c5c-82c219792582c104.js +0 -1
- recce/data/_next/static/chunks/d90cfbaa-e7d779b3912afeec.js +0 -1
- recce/data/_next/static/chunks/e07c302e-cd170429646873e1.js +0 -1
- recce/data/_next/static/chunks/fa5fb511-15fb438349ad5b97.js +0 -1
- recce/data/_next/static/chunks/framework-7950757d31580329.js +0 -1
- recce/data/_next/static/chunks/main-app-4df79eb11c34d43c.js +0 -1
- recce/data/_next/static/chunks/main-cd6c104af638214a.js +0 -1
- recce/data/_next/static/chunks/pages/_app-73008661edbd5e05.js +0 -1
- recce/data/_next/static/chunks/pages/_error-cf8bbdc3cf76c83f.js +0 -1
- recce/data/_next/static/chunks/webpack-84df6dd5ae3cf908.js +0 -1
- recce/data/_next/static/css/188a3a1687e2a064.css +0 -1
- recce/data/_next/static/css/8edca58d4abcf908.css +0 -14
- recce/data/_next/static/css/abdb9814a3dd18bb.css +0 -1
- recce/data/_next/static/css/c21263c1520b615b.css +0 -1
- recce/data/_next/static/media/montserrat-cyrillic-800-normal.22628180.woff2 +0 -0
- recce/data/_next/static/media/montserrat-cyrillic-ext-800-normal.94a63aea.woff2 +0 -0
- recce/data/_next/static/media/montserrat-latin-800-normal.6f8fa298.woff2 +0 -0
- recce/data/_next/static/media/montserrat-latin-ext-800-normal.013b84f9.woff2 +0 -0
- recce/data/_next/static/media/montserrat-vietnamese-800-normal.c0035377.woff2 +0 -0
- recce/state.py +0 -865
- recce_nightly-1.15.0.20250806.dist-info/RECORD +0 -156
- tests/test_state.py +0 -134
- /recce/data/_next/static/{Q_5ThPsmamd4VAGXuqwgi → 52aV_JrNUZU6dMFgvTQEO}/_ssgManifest.js +0 -0
- /recce/data/_next/static/chunks/{polyfills-42372ed130431b0a.js → a6dad97d9634a72d.js} +0 -0
- /recce/data/_next/static/media/{montserrat-cyrillic-ext-800-normal.e6e0d8d0.woff → montserrat-cyrillic-ext-800-normal.a4fa76b5.woff} +0 -0
- /recce/data/_next/static/media/{reload-image.79aabb7d.svg → reload-image.7aa931c7.svg} +0 -0
- {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/WHEEL +0 -0
- {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/entry_points.txt +0 -0
- {recce_nightly-1.15.0.20250806.dist-info → recce_nightly-1.26.0.20251124.dist-info}/licenses/LICENSE +0 -0
recce/util/recce_cloud.py
CHANGED
|
@@ -42,6 +42,7 @@ class RecceCloud:
|
|
|
42
42
|
self.token = token
|
|
43
43
|
self.token_type = "github_token" if token.startswith(("ghp_", "gho_", "ghu_", "ghs_", "ghr_")) else "api_token"
|
|
44
44
|
self.base_url = f"{RECCE_CLOUD_API_HOST}/api/v1"
|
|
45
|
+
self.base_url_v2 = f"{RECCE_CLOUD_API_HOST}/api/v2"
|
|
45
46
|
|
|
46
47
|
def _request(self, method, url, headers: Dict = None, **kwargs):
|
|
47
48
|
headers = {
|
|
@@ -81,6 +82,19 @@ class RecceCloud:
|
|
|
81
82
|
response = self._fetch_presigned_url(method, repository, artifact_name, metadata, pr_id, branch)
|
|
82
83
|
return response.get("presigned_url")
|
|
83
84
|
|
|
85
|
+
def _replace_localhost_with_docker_internal(self, url: str) -> str:
|
|
86
|
+
if url is None:
|
|
87
|
+
return None
|
|
88
|
+
if (
|
|
89
|
+
os.environ.get("RECCE_SHARE_INSTANCE_ENV") == "docker"
|
|
90
|
+
or os.environ.get("RECCE_TASK_INSTANCE_ENV") == "docker"
|
|
91
|
+
or os.environ.get("RECCE_INSTANCE_ENV") == "docker"
|
|
92
|
+
):
|
|
93
|
+
# For local development, convert the presigned URL from localhost to host.docker.internal
|
|
94
|
+
if url.startswith(LOCALHOST_URL_PREFIX):
|
|
95
|
+
return url.replace(LOCALHOST_URL_PREFIX, DOCKER_INTERNAL_URL_PREFIX)
|
|
96
|
+
return url
|
|
97
|
+
|
|
84
98
|
def get_presigned_url_by_share_id(
|
|
85
99
|
self,
|
|
86
100
|
method: PresignedUrlMethod,
|
|
@@ -89,10 +103,13 @@ class RecceCloud:
|
|
|
89
103
|
) -> str:
|
|
90
104
|
response = self._fetch_presigned_url_by_share_id(method, share_id, metadata=metadata)
|
|
91
105
|
presigned_url = response.get("presigned_url")
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
if not presigned_url:
|
|
107
|
+
raise RecceCloudException(
|
|
108
|
+
message="Failed to get presigned URL from Recce Cloud.",
|
|
109
|
+
reason="No presigned URL returned from the server.",
|
|
110
|
+
status_code=404,
|
|
111
|
+
)
|
|
112
|
+
presigned_url = self._replace_localhost_with_docker_internal(presigned_url)
|
|
96
113
|
return presigned_url
|
|
97
114
|
|
|
98
115
|
def get_download_presigned_url_by_github_repo_with_tags(
|
|
@@ -167,12 +184,22 @@ class RecceCloud:
|
|
|
167
184
|
)
|
|
168
185
|
return response.json()
|
|
169
186
|
|
|
170
|
-
def purge_artifacts(self,
|
|
171
|
-
|
|
187
|
+
def purge_artifacts(self, repository: str, pr_id: int = None, branch: str = None):
|
|
188
|
+
if pr_id is not None:
|
|
189
|
+
api_url = f"{self.base_url}/{repository}/pulls/{pr_id}/artifacts"
|
|
190
|
+
error_message = "Failed to purge artifacts from Recce Cloud."
|
|
191
|
+
elif branch is not None:
|
|
192
|
+
api_url = f"{self.base_url}/{repository}/commits/{branch}/artifacts"
|
|
193
|
+
error_message = "Failed to delete artifacts from Recce Cloud."
|
|
194
|
+
else:
|
|
195
|
+
raise ValueError(
|
|
196
|
+
"Please either run this command from within a pull request context "
|
|
197
|
+
"or specify a branch using the --branch option."
|
|
198
|
+
)
|
|
172
199
|
response = self._request("DELETE", api_url)
|
|
173
200
|
if response.status_code != 204:
|
|
174
201
|
raise RecceCloudException(
|
|
175
|
-
message=
|
|
202
|
+
message=error_message,
|
|
176
203
|
reason=response.text,
|
|
177
204
|
status_code=response.status_code,
|
|
178
205
|
)
|
|
@@ -232,8 +259,161 @@ class RecceCloud:
|
|
|
232
259
|
logger.warning(f"Failed to set Onboarding State in Recce Cloud. Reason: {str(e)}")
|
|
233
260
|
return
|
|
234
261
|
|
|
262
|
+
def get_session(self, session_id: str):
|
|
263
|
+
api_url = f"{self.base_url_v2}/sessions/{session_id}"
|
|
264
|
+
response = self._request("GET", api_url)
|
|
265
|
+
if response.status_code == 403:
|
|
266
|
+
return {"status": "error", "message": response.json().get("detail")}
|
|
267
|
+
if response.status_code != 200:
|
|
268
|
+
raise RecceCloudException(
|
|
269
|
+
message="Failed to get session from Recce Cloud.",
|
|
270
|
+
reason=response.text,
|
|
271
|
+
status_code=response.status_code,
|
|
272
|
+
)
|
|
273
|
+
data = response.json()
|
|
274
|
+
if data["success"] is not True:
|
|
275
|
+
raise RecceCloudException(
|
|
276
|
+
message="Failed to get session from Recce Cloud.",
|
|
277
|
+
reason=data.get("message", "Unknown error"),
|
|
278
|
+
status_code=response.status_code,
|
|
279
|
+
)
|
|
280
|
+
return data["session"]
|
|
281
|
+
|
|
282
|
+
def update_session(self, org_id: str, project_id: str, session_id: str, adapter_type: str):
|
|
283
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}"
|
|
284
|
+
data = {"adapter_type": adapter_type}
|
|
285
|
+
response = self._request("PATCH", api_url, json=data)
|
|
286
|
+
if response.status_code == 403:
|
|
287
|
+
return {"status": "error", "message": response.json().get("detail")}
|
|
288
|
+
if response.status_code != 200:
|
|
289
|
+
raise RecceCloudException(
|
|
290
|
+
message="Failed to update session in Recce Cloud.",
|
|
291
|
+
reason=response.text,
|
|
292
|
+
status_code=response.status_code,
|
|
293
|
+
)
|
|
294
|
+
return response.json()
|
|
295
|
+
|
|
296
|
+
def get_download_urls_by_session_id(self, org_id: str, project_id: str, session_id: str) -> dict[str, str]:
|
|
297
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/download-url"
|
|
298
|
+
response = self._request("GET", api_url)
|
|
299
|
+
if response.status_code != 200:
|
|
300
|
+
raise RecceCloudException(
|
|
301
|
+
message="Failed to download session from Recce Cloud.",
|
|
302
|
+
reason=response.text,
|
|
303
|
+
status_code=response.status_code,
|
|
304
|
+
)
|
|
305
|
+
data = response.json()
|
|
306
|
+
if data["presigned_urls"] is None:
|
|
307
|
+
raise RecceCloudException(
|
|
308
|
+
message="No presigned URLs returned from the server.",
|
|
309
|
+
reason="",
|
|
310
|
+
status_code=404,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
presigned_urls = data["presigned_urls"]
|
|
314
|
+
for key, url in presigned_urls.items():
|
|
315
|
+
presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
|
|
316
|
+
return presigned_urls
|
|
317
|
+
|
|
318
|
+
def get_base_session_download_urls(self, org_id: str, project_id: str) -> dict[str, str]:
|
|
319
|
+
"""Get download URLs for the base session of a project."""
|
|
320
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/base-session/download-url"
|
|
321
|
+
response = self._request("GET", api_url)
|
|
322
|
+
if response.status_code != 200:
|
|
323
|
+
raise RecceCloudException(
|
|
324
|
+
message="Failed to download base session from Recce Cloud.",
|
|
325
|
+
reason=response.text,
|
|
326
|
+
status_code=response.status_code,
|
|
327
|
+
)
|
|
328
|
+
data = response.json()
|
|
329
|
+
if data["presigned_urls"] is None:
|
|
330
|
+
raise RecceCloudException(
|
|
331
|
+
message="No presigned URLs returned from the server.",
|
|
332
|
+
reason="",
|
|
333
|
+
status_code=404,
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
presigned_urls = data["presigned_urls"]
|
|
337
|
+
for key, url in presigned_urls.items():
|
|
338
|
+
presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
|
|
339
|
+
return presigned_urls
|
|
340
|
+
|
|
341
|
+
def get_upload_urls_by_session_id(self, org_id: str, project_id: str, session_id: str) -> dict[str, str]:
|
|
342
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/upload-url"
|
|
343
|
+
response = self._request("GET", api_url)
|
|
344
|
+
if response.status_code != 200:
|
|
345
|
+
raise RecceCloudException(
|
|
346
|
+
message="Failed to get upload URLs for session from Recce Cloud.",
|
|
347
|
+
reason=response.text,
|
|
348
|
+
status_code=response.status_code,
|
|
349
|
+
)
|
|
350
|
+
data = response.json()
|
|
351
|
+
if data["presigned_urls"] is None:
|
|
352
|
+
raise RecceCloudException(
|
|
353
|
+
message="No presigned URLs returned from the server.",
|
|
354
|
+
reason="",
|
|
355
|
+
status_code=404,
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
presigned_urls = data["presigned_urls"]
|
|
359
|
+
for key, url in presigned_urls.items():
|
|
360
|
+
presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
|
|
361
|
+
return presigned_urls
|
|
362
|
+
|
|
363
|
+
def post_recce_state_uploaded_by_session_id(self, org_id: str, project_id: str, session_id: str):
|
|
364
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/recce-state-uploaded"
|
|
365
|
+
response = self._request("POST", api_url)
|
|
366
|
+
if response.status_code != 204:
|
|
367
|
+
raise RecceCloudException(
|
|
368
|
+
message="Failed to notify state uploaded for session in Recce Cloud.",
|
|
369
|
+
reason=response.text,
|
|
370
|
+
status_code=response.status_code,
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
def list_organizations(self) -> list:
|
|
374
|
+
"""List all organizations the user has access to."""
|
|
375
|
+
api_url = f"{self.base_url_v2}/organizations"
|
|
376
|
+
response = self._request("GET", api_url)
|
|
377
|
+
if response.status_code != 200:
|
|
378
|
+
raise RecceCloudException(
|
|
379
|
+
message="Failed to list organizations from Recce Cloud.",
|
|
380
|
+
reason=response.text,
|
|
381
|
+
status_code=response.status_code,
|
|
382
|
+
)
|
|
383
|
+
data = response.json()
|
|
384
|
+
return data.get("organizations", [])
|
|
385
|
+
|
|
386
|
+
def list_projects(self, org_id: str) -> list:
|
|
387
|
+
"""List all projects in an organization."""
|
|
388
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects"
|
|
389
|
+
response = self._request("GET", api_url)
|
|
390
|
+
if response.status_code != 200:
|
|
391
|
+
raise RecceCloudException(
|
|
392
|
+
message="Failed to list projects from Recce Cloud.",
|
|
393
|
+
reason=response.text,
|
|
394
|
+
status_code=response.status_code,
|
|
395
|
+
)
|
|
396
|
+
data = response.json()
|
|
397
|
+
return data.get("projects", [])
|
|
398
|
+
|
|
399
|
+
def list_sessions(self, org_id: str, project_id: str) -> list:
|
|
400
|
+
"""List all sessions in a project."""
|
|
401
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions"
|
|
402
|
+
response = self._request("GET", api_url)
|
|
403
|
+
if response.status_code != 200:
|
|
404
|
+
raise RecceCloudException(
|
|
405
|
+
message="Failed to list sessions from Recce Cloud.",
|
|
406
|
+
reason=response.text,
|
|
407
|
+
status_code=response.status_code,
|
|
408
|
+
)
|
|
409
|
+
data = response.json()
|
|
410
|
+
return data.get("sessions", [])
|
|
411
|
+
|
|
235
412
|
|
|
236
413
|
def get_recce_cloud_onboarding_state(token: str) -> str:
|
|
414
|
+
if token and token.startswith("rct-"):
|
|
415
|
+
return "undefined"
|
|
416
|
+
|
|
237
417
|
try:
|
|
238
418
|
recce_cloud = RecceCloud(token)
|
|
239
419
|
user_info = recce_cloud.get_user_info()
|
recce/yaml/__init__.py
CHANGED
|
@@ -34,7 +34,7 @@ def dump(data, stream: Any = None, *, transform: Any = None) -> Any:
|
|
|
34
34
|
|
|
35
35
|
def safe_load_yaml(file_path):
|
|
36
36
|
try:
|
|
37
|
-
with open(file_path, "r") as f:
|
|
37
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
38
38
|
payload = safe_load(f)
|
|
39
39
|
except yaml.YAMLError as e:
|
|
40
40
|
print(e)
|
|
@@ -45,7 +45,7 @@ def safe_load_yaml(file_path):
|
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
def round_trip_load_yaml(file_path):
|
|
48
|
-
with open(file_path, "r") as f:
|
|
48
|
+
with open(file_path, "r", encoding="utf-8") as f:
|
|
49
49
|
try:
|
|
50
50
|
payload = load(f)
|
|
51
51
|
except yaml.YAMLError as e:
|
recce_cloud/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Recce Cloud - Lightweight CLI for Recce Cloud operations."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def get_version():
|
|
7
|
+
"""Get version from VERSION file."""
|
|
8
|
+
# Try recce_cloud/VERSION first (for standalone package)
|
|
9
|
+
version_file = os.path.join(os.path.dirname(__file__), "VERSION")
|
|
10
|
+
if os.path.exists(version_file):
|
|
11
|
+
with open(version_file) as fh:
|
|
12
|
+
return fh.read().strip()
|
|
13
|
+
|
|
14
|
+
# Fallback to ../recce/VERSION (for development)
|
|
15
|
+
version_file = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "recce", "VERSION"))
|
|
16
|
+
if os.path.exists(version_file):
|
|
17
|
+
with open(version_file) as fh:
|
|
18
|
+
return fh.read().strip()
|
|
19
|
+
|
|
20
|
+
# Last resort
|
|
21
|
+
return "unknown"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
__version__ = get_version()
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Recce Cloud API client module."""
|
|
2
|
+
|
|
3
|
+
from recce_cloud.api.base import BaseRecceCloudClient
|
|
4
|
+
from recce_cloud.api.client import RecceCloudClient
|
|
5
|
+
from recce_cloud.api.exceptions import RecceCloudException
|
|
6
|
+
from recce_cloud.api.factory import create_platform_client
|
|
7
|
+
from recce_cloud.api.github import GitHubRecceCloudClient
|
|
8
|
+
from recce_cloud.api.gitlab import GitLabRecceCloudClient
|
|
9
|
+
|
|
10
|
+
__all__ = [
|
|
11
|
+
"BaseRecceCloudClient",
|
|
12
|
+
"RecceCloudClient",
|
|
13
|
+
"RecceCloudException",
|
|
14
|
+
"create_platform_client",
|
|
15
|
+
"GitHubRecceCloudClient",
|
|
16
|
+
"GitLabRecceCloudClient",
|
|
17
|
+
]
|
recce_cloud/api/base.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Base API client for Recce Cloud.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from abc import ABC, abstractmethod
|
|
7
|
+
from typing import Dict, Optional
|
|
8
|
+
|
|
9
|
+
import requests
|
|
10
|
+
|
|
11
|
+
from recce_cloud.api.exceptions import RecceCloudException
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class BaseRecceCloudClient(ABC):
|
|
15
|
+
"""Abstract base class for platform-specific Recce Cloud API clients."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, token: str, api_host: Optional[str] = None):
|
|
18
|
+
"""
|
|
19
|
+
Initialize the API client.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
token: Authentication token (GITHUB_TOKEN, CI_JOB_TOKEN, or RECCE_API_TOKEN)
|
|
23
|
+
api_host: Recce Cloud API host (defaults to RECCE_CLOUD_API_HOST or https://cloud.datarecce.io)
|
|
24
|
+
"""
|
|
25
|
+
self.token = token
|
|
26
|
+
self.api_host = api_host or os.getenv("RECCE_CLOUD_API_HOST", "https://cloud.datarecce.io")
|
|
27
|
+
|
|
28
|
+
def _make_request(self, method: str, url: str, **kwargs) -> Dict:
|
|
29
|
+
"""
|
|
30
|
+
Make an HTTP request to Recce Cloud API.
|
|
31
|
+
|
|
32
|
+
Args:
|
|
33
|
+
method: HTTP method (GET, POST, PUT, etc.)
|
|
34
|
+
url: Full URL for the request
|
|
35
|
+
**kwargs: Additional arguments passed to requests
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
Response JSON as dictionary
|
|
39
|
+
|
|
40
|
+
Raises:
|
|
41
|
+
RecceCloudException: If the request fails
|
|
42
|
+
"""
|
|
43
|
+
headers = kwargs.pop("headers", {})
|
|
44
|
+
headers.update(
|
|
45
|
+
{
|
|
46
|
+
"Authorization": f"Bearer {self.token}",
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
response = requests.request(method, url, headers=headers, **kwargs)
|
|
53
|
+
response.raise_for_status()
|
|
54
|
+
|
|
55
|
+
# Handle empty responses (e.g., 204 No Content)
|
|
56
|
+
if response.status_code == 204 or not response.content:
|
|
57
|
+
return {}
|
|
58
|
+
|
|
59
|
+
return response.json()
|
|
60
|
+
except requests.exceptions.HTTPError as e:
|
|
61
|
+
reason = str(e)
|
|
62
|
+
if e.response is not None:
|
|
63
|
+
try:
|
|
64
|
+
error_detail = e.response.json()
|
|
65
|
+
reason = error_detail.get("message", str(e))
|
|
66
|
+
except Exception:
|
|
67
|
+
reason = e.response.text or str(e)
|
|
68
|
+
raise RecceCloudException(reason=reason, status_code=e.response.status_code if e.response else None)
|
|
69
|
+
except requests.exceptions.RequestException as e:
|
|
70
|
+
raise RecceCloudException(reason=str(e))
|
|
71
|
+
|
|
72
|
+
@abstractmethod
|
|
73
|
+
def touch_recce_session(
|
|
74
|
+
self,
|
|
75
|
+
branch: str,
|
|
76
|
+
adapter_type: str,
|
|
77
|
+
cr_number: Optional[int] = None,
|
|
78
|
+
commit_sha: Optional[str] = None,
|
|
79
|
+
session_type: Optional[str] = None,
|
|
80
|
+
) -> Dict:
|
|
81
|
+
"""
|
|
82
|
+
Create or touch a Recce session.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
branch: Branch name
|
|
86
|
+
adapter_type: DBT adapter type (e.g., 'postgres', 'snowflake', 'bigquery')
|
|
87
|
+
cr_number: Change request number (PR/MR number) for CR sessions
|
|
88
|
+
commit_sha: Commit SHA (GitLab requires this)
|
|
89
|
+
session_type: Session type ("cr", "prod", "dev") - determines if cr_number is used
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
Dictionary containing:
|
|
93
|
+
- session_id: Session ID
|
|
94
|
+
- manifest_upload_url: Presigned URL for manifest.json upload
|
|
95
|
+
- catalog_upload_url: Presigned URL for catalog.json upload
|
|
96
|
+
"""
|
|
97
|
+
pass
|
|
98
|
+
|
|
99
|
+
@abstractmethod
|
|
100
|
+
def upload_completed(self, session_id: str, commit_sha: Optional[str] = None) -> Dict:
|
|
101
|
+
"""
|
|
102
|
+
Notify Recce Cloud that upload is complete.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
session_id: Session ID from touch_recce_session
|
|
106
|
+
commit_sha: Commit SHA (GitLab requires this)
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
Empty dictionary or acknowledgement
|
|
110
|
+
"""
|
|
111
|
+
pass
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Recce Cloud API client for lightweight operations.
|
|
3
|
+
|
|
4
|
+
Simplified version of recce.util.recce_cloud.RecceCloud with only
|
|
5
|
+
the methods needed for upload-session functionality.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import os
|
|
9
|
+
|
|
10
|
+
import requests
|
|
11
|
+
|
|
12
|
+
from recce_cloud.api.exceptions import RecceCloudException
|
|
13
|
+
|
|
14
|
+
RECCE_CLOUD_API_HOST = os.environ.get("RECCE_CLOUD_API_HOST", "https://cloud.datarecce.io")
|
|
15
|
+
|
|
16
|
+
DOCKER_INTERNAL_URL_PREFIX = "http://host.docker.internal"
|
|
17
|
+
LOCALHOST_URL_PREFIX = "http://localhost"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class RecceCloudClient:
|
|
21
|
+
"""
|
|
22
|
+
Lightweight Recce Cloud API client.
|
|
23
|
+
|
|
24
|
+
Supports authentication with Recce Cloud API token (starts with "rct-").
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, token: str):
|
|
28
|
+
if token is None:
|
|
29
|
+
raise ValueError("Token cannot be None.")
|
|
30
|
+
self.token = token
|
|
31
|
+
self.base_url_v2 = f"{RECCE_CLOUD_API_HOST}/api/v2"
|
|
32
|
+
|
|
33
|
+
def _request(self, method: str, url: str, headers: dict = None, **kwargs):
|
|
34
|
+
"""Make authenticated HTTP request to Recce Cloud API."""
|
|
35
|
+
headers = {
|
|
36
|
+
**(headers or {}),
|
|
37
|
+
"Authorization": f"Bearer {self.token}",
|
|
38
|
+
}
|
|
39
|
+
return requests.request(method, url, headers=headers, **kwargs)
|
|
40
|
+
|
|
41
|
+
def _replace_localhost_with_docker_internal(self, url: str) -> str:
|
|
42
|
+
"""Convert localhost URLs to docker internal URLs if running in Docker."""
|
|
43
|
+
if url is None:
|
|
44
|
+
return None
|
|
45
|
+
if (
|
|
46
|
+
os.environ.get("RECCE_SHARE_INSTANCE_ENV") == "docker"
|
|
47
|
+
or os.environ.get("RECCE_TASK_INSTANCE_ENV") == "docker"
|
|
48
|
+
or os.environ.get("RECCE_INSTANCE_ENV") == "docker"
|
|
49
|
+
):
|
|
50
|
+
# For local development, convert the presigned URL from localhost to host.docker.internal
|
|
51
|
+
if url.startswith(LOCALHOST_URL_PREFIX):
|
|
52
|
+
return url.replace(LOCALHOST_URL_PREFIX, DOCKER_INTERNAL_URL_PREFIX)
|
|
53
|
+
return url
|
|
54
|
+
|
|
55
|
+
def get_session(self, session_id: str) -> dict:
|
|
56
|
+
"""
|
|
57
|
+
Get session information from Recce Cloud.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
session_id: The session ID to retrieve
|
|
61
|
+
|
|
62
|
+
Returns:
|
|
63
|
+
dict containing session information with keys:
|
|
64
|
+
- org_id: Organization ID
|
|
65
|
+
- project_id: Project ID
|
|
66
|
+
- ... other session fields
|
|
67
|
+
|
|
68
|
+
Raises:
|
|
69
|
+
RecceCloudException: If the request fails
|
|
70
|
+
"""
|
|
71
|
+
api_url = f"{self.base_url_v2}/sessions/{session_id}"
|
|
72
|
+
response = self._request("GET", api_url)
|
|
73
|
+
if response.status_code == 403:
|
|
74
|
+
return {"status": "error", "message": response.json().get("detail")}
|
|
75
|
+
if response.status_code != 200:
|
|
76
|
+
raise RecceCloudException(
|
|
77
|
+
reason=response.text,
|
|
78
|
+
status_code=response.status_code,
|
|
79
|
+
)
|
|
80
|
+
data = response.json()
|
|
81
|
+
if data["success"] is not True:
|
|
82
|
+
raise RecceCloudException(
|
|
83
|
+
reason=data.get("message", "Unknown error"),
|
|
84
|
+
status_code=response.status_code,
|
|
85
|
+
)
|
|
86
|
+
return data["session"]
|
|
87
|
+
|
|
88
|
+
def get_upload_urls_by_session_id(self, org_id: str, project_id: str, session_id: str) -> dict:
|
|
89
|
+
"""
|
|
90
|
+
Get presigned S3 upload URLs for a session.
|
|
91
|
+
|
|
92
|
+
Args:
|
|
93
|
+
org_id: Organization ID
|
|
94
|
+
project_id: Project ID
|
|
95
|
+
session_id: Session ID
|
|
96
|
+
|
|
97
|
+
Returns:
|
|
98
|
+
dict with keys:
|
|
99
|
+
- manifest_url: Presigned URL for uploading manifest.json
|
|
100
|
+
- catalog_url: Presigned URL for uploading catalog.json
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
RecceCloudException: If the request fails
|
|
104
|
+
"""
|
|
105
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}/upload-url"
|
|
106
|
+
response = self._request("GET", api_url)
|
|
107
|
+
if response.status_code != 200:
|
|
108
|
+
raise RecceCloudException(
|
|
109
|
+
reason=response.text,
|
|
110
|
+
status_code=response.status_code,
|
|
111
|
+
)
|
|
112
|
+
data = response.json()
|
|
113
|
+
if data["presigned_urls"] is None:
|
|
114
|
+
raise RecceCloudException(
|
|
115
|
+
reason="No presigned URLs returned from the server.",
|
|
116
|
+
status_code=404,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
presigned_urls = data["presigned_urls"]
|
|
120
|
+
for key, url in presigned_urls.items():
|
|
121
|
+
presigned_urls[key] = self._replace_localhost_with_docker_internal(url)
|
|
122
|
+
return presigned_urls
|
|
123
|
+
|
|
124
|
+
def update_session(self, org_id: str, project_id: str, session_id: str, adapter_type: str) -> dict:
|
|
125
|
+
"""
|
|
126
|
+
Update session metadata with adapter type.
|
|
127
|
+
|
|
128
|
+
Args:
|
|
129
|
+
org_id: Organization ID
|
|
130
|
+
project_id: Project ID
|
|
131
|
+
session_id: Session ID
|
|
132
|
+
adapter_type: dbt adapter type (e.g., "postgres", "snowflake", "bigquery")
|
|
133
|
+
|
|
134
|
+
Returns:
|
|
135
|
+
dict containing updated session information
|
|
136
|
+
|
|
137
|
+
Raises:
|
|
138
|
+
RecceCloudException: If the request fails
|
|
139
|
+
"""
|
|
140
|
+
api_url = f"{self.base_url_v2}/organizations/{org_id}/projects/{project_id}/sessions/{session_id}"
|
|
141
|
+
data = {"adapter_type": adapter_type}
|
|
142
|
+
response = self._request("PATCH", api_url, json=data)
|
|
143
|
+
if response.status_code == 403:
|
|
144
|
+
return {"status": "error", "message": response.json().get("detail")}
|
|
145
|
+
if response.status_code != 200:
|
|
146
|
+
raise RecceCloudException(
|
|
147
|
+
reason=response.text,
|
|
148
|
+
status_code=response.status_code,
|
|
149
|
+
)
|
|
150
|
+
return response.json()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Exceptions for Recce Cloud API.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RecceCloudException(Exception):
|
|
9
|
+
"""Exception raised when Recce Cloud API returns an error."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, reason: str, status_code: int = None):
|
|
12
|
+
"""
|
|
13
|
+
Initialize exception.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
reason: Error reason/message
|
|
17
|
+
status_code: HTTP status code (optional)
|
|
18
|
+
"""
|
|
19
|
+
try:
|
|
20
|
+
reason = json.loads(reason).get("detail", reason)
|
|
21
|
+
except (json.JSONDecodeError, AttributeError):
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
super().__init__(reason)
|
|
25
|
+
self.reason = reason
|
|
26
|
+
self.status_code = status_code
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Factory for creating platform-specific API clients.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from typing import Optional
|
|
7
|
+
|
|
8
|
+
from recce_cloud.api.github import GitHubRecceCloudClient
|
|
9
|
+
from recce_cloud.api.gitlab import GitLabRecceCloudClient
|
|
10
|
+
from recce_cloud.ci_providers import CIDetector
|
|
11
|
+
from recce_cloud.ci_providers.base import CIInfo
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def create_platform_client(
|
|
15
|
+
token: str,
|
|
16
|
+
ci_info: Optional[CIInfo] = None,
|
|
17
|
+
api_host: Optional[str] = None,
|
|
18
|
+
):
|
|
19
|
+
"""
|
|
20
|
+
Create a platform-specific Recce Cloud API client based on CI environment.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
token: Authentication token (GITHUB_TOKEN, CI_JOB_TOKEN, or RECCE_API_TOKEN)
|
|
24
|
+
ci_info: CI information (auto-detected if not provided)
|
|
25
|
+
api_host: Recce Cloud API host (optional)
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
GitHubRecceCloudClient or GitLabRecceCloudClient
|
|
29
|
+
|
|
30
|
+
Raises:
|
|
31
|
+
ValueError: If platform is not supported or required information is missing
|
|
32
|
+
"""
|
|
33
|
+
# Auto-detect CI info if not provided
|
|
34
|
+
if ci_info is None:
|
|
35
|
+
ci_info = CIDetector.detect()
|
|
36
|
+
|
|
37
|
+
if ci_info.platform == "github-actions":
|
|
38
|
+
repository = ci_info.repository or os.getenv("GITHUB_REPOSITORY")
|
|
39
|
+
if not repository:
|
|
40
|
+
raise ValueError("GitHub repository information is required but not detected")
|
|
41
|
+
|
|
42
|
+
return GitHubRecceCloudClient(token=token, repository=repository, api_host=api_host)
|
|
43
|
+
|
|
44
|
+
elif ci_info.platform == "gitlab-ci":
|
|
45
|
+
project_path = ci_info.repository or os.getenv("CI_PROJECT_PATH")
|
|
46
|
+
repository_url = os.getenv("CI_PROJECT_URL")
|
|
47
|
+
|
|
48
|
+
if not project_path:
|
|
49
|
+
raise ValueError("GitLab project path is required but not detected")
|
|
50
|
+
if not repository_url:
|
|
51
|
+
raise ValueError("GitLab project URL is required but not detected")
|
|
52
|
+
|
|
53
|
+
return GitLabRecceCloudClient(
|
|
54
|
+
token=token,
|
|
55
|
+
project_path=project_path,
|
|
56
|
+
repository_url=repository_url,
|
|
57
|
+
api_host=api_host,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
else:
|
|
61
|
+
raise ValueError(
|
|
62
|
+
f"Unsupported platform: {ci_info.platform}. " "Only GitHub Actions and GitLab CI are supported."
|
|
63
|
+
)
|