Platform scripts, MCP servers, deployment and docs for the KAB runs
- Scripts to run workflows from a YAML context or run inputs (kab_run_workflow.py, with --input name=@file), store per-project discovery connections, bootstrap agent MCP keys, refresh the KAB token, publish reports and build estate snapshots. - Hyperscaler discovery servers extended in place; cloud-knowledge folded into them. - deploy/crucible-kab-dev.yaml: the Discovery package agent and the Assessment agents. - Platform issue write-ups and current-wiring notes under docs/platform-issues/. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,8 @@ def _gcp_client():
|
||||
|
||||
async def _gcp_token() -> str:
|
||||
connection = get_connection()
|
||||
if connection.get("access_token"):
|
||||
return str(connection["access_token"])
|
||||
key = hashlib.sha256(json.dumps(connection, sort_keys=True).encode()).hexdigest()
|
||||
cached = GCP_TOKENS.get(key)
|
||||
now = time.time()
|
||||
@@ -75,10 +77,32 @@ async def _gcp_token() -> str:
|
||||
return token
|
||||
|
||||
|
||||
def _gcp_quota_project() -> str:
|
||||
"""The project Google bills a user credential's calls to: the connection's quota_project, else a projects/<id>
|
||||
scope root. Recommender and Developer Knowledge refuse a user token without one; Cloud Asset doesn't need it."""
|
||||
connection = get_connection()
|
||||
if connection.get("quota_project"):
|
||||
return str(connection["quota_project"])
|
||||
kind, _, identifier = str(connection.get("scope_root", "")).strip("/").partition("/")
|
||||
return identifier if kind == "projects" else ""
|
||||
|
||||
|
||||
# The APIs that need a quota project for a user credential. Sent only to these, so Cloud Asset keeps working for a
|
||||
# caller who lacks serviceusage.services.use on the quota project.
|
||||
GCP_QUOTA_APIS = ("https://recommender.googleapis.com/",) # a literal: the builder refuses computed module-level values
|
||||
|
||||
|
||||
async def _gcp_auth(quota: bool) -> Dict[str, str]:
|
||||
headers = {"Authorization": f"Bearer {await _gcp_token()}"}
|
||||
project = _gcp_quota_project() if quota else ""
|
||||
if project:
|
||||
headers["x-goog-user-project"] = project
|
||||
return headers
|
||||
|
||||
|
||||
async def _gcp_get(url: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
||||
token = await _gcp_token()
|
||||
response = await _with_backoff(
|
||||
lambda: _gcp_client().get(url, params=params, headers={"Authorization": f"Bearer {token}"}))
|
||||
headers = await _gcp_auth(url.startswith(GCP_QUOTA_APIS))
|
||||
response = await _with_backoff(lambda: _gcp_client().get(url, params=params, headers=headers))
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user