33 if adapter not in modes or auth not in modes[adapter]:
34 raise failure("cu-adapter-auth-unsupported", "Select the supported adapter's verified CU auth contract; no cross-adapter auth fallback.")
35 return {
36 "adapter": adapter, "mode": auth,
37 "contract": (
38 "File system MI is implemented in inspected service code; live compatibility is unverified. Explicit legacy key modes remain supported, without fallback."
39 if adapter == "file" else
40 "Documented Search system-assigned CU identity; Cognitive Services User on the selected CU account. No key fallback."
41 ),
42 "credential_read": (
43 "none: exact source reuse" if not creating else
44 "private ARM listKeys/key1 for the exact source PUT only" if auth == "api-key-arm" else
45 "explicit existing ENV only" if auth == "api-key-environment" else
46 "none: managed identity"
47 ),
48 "setup": (
49 "Reuse verified dependencies. Resolve only missing changes through packaged native bootstrap with exact identity/role/scope and explicit permission/local-auth approval; source execution does not alter them and unsupported updates block."
50 if creating else "No CU setup or reingestion for exact source reuse."
51 ),
52 "consent": "Disclose auth and cost/data/access in the concrete source approval; no separate manual credential/MI/ENV confirmation. Material changes require refreshed approval.",
124 resource = RESOURCE.fullmatch(value.get("resource_id", "")) if isinstance(value.get("resource_id"), str) else None
125 if (
126 resource is None or not isinstance(value.get("endpoint"), str)
127 or ENDPOINT.fullmatch(value["endpoint"]) is None
128 or value["endpoint"] != endpoint.rstrip("/")
129 or value.get("api_version") != API_VERSION or value.get("key_name") != "key1"
130 or value.get("purpose") != PURPOSE
131 ):
132 raise failure("cu-acquisition-invalid", "Only the exact selected AIServices account, endpoint and key1 source-PUT purpose are supported.")
133 validate_context(value.get("context"))
134 if resource.group(1).casefold() != value["context"]["subscription_id"].casefold():
135 raise failure("cu-subscription-mismatch", "Select the approved CU account's existing CLI subscription, then refresh the plan; no context switching was performed.")
136
137
138def check_context(expected, provider):
139 current = provider()
140 validate_context(current)
141 if current != expected:
142 raise failure("cu-context-drift", "Signed-in tenant, subscription or principal changed; restore the approved context or refresh the plan and approval.")
196 status = status if type(status) is int and 100 <= status <= 599 else None
197 if status in (401, 403):
198 return failure(
199 "cu-key-access-denied",
200 "The signed-in caller needs Microsoft.CognitiveServices/accounts/listKeys/action on the exact approved CU account. Have its owner resolve access under separate concrete approval; no roles or policies were changed.",
201 status=status,
202 )
203 return failure("cu-key-acquisition-failed", "ARM listKeys failed for the approved CU account; details withheld and no retry or auth fallback performed.", status=status)
204
205 def _redact(self, value):
206 if isinstance(value, str):
207 for secret in self._secrets:
208 value = value.replace(secret, "[REDACTED]")
209 return value
210 if isinstance(value, dict):
211 return {self._redact(k): self._redact(v) for k, v in value.items()}