refs #703: configure OCI GenAI root compartment

This commit is contained in:
devmrko
2026-07-22 20:07:47 +09:00
parent 4211f11cae
commit 27757ebff3
2 changed files with 56 additions and 2 deletions

View File

@@ -26,7 +26,10 @@ ALLOWED_OCI_SETTINGS = frozenset(
"OCI_PROFILE",
}
)
_COMPARTMENT_ID = re.compile(r"^ocid1\.compartment\.[A-Za-z0-9._-]+$")
# OCI permits the tenancy OCID when the root compartment is selected.
_COMPARTMENT_OR_ROOT_ID = re.compile(
r"^ocid1\.(?:compartment|tenancy)\.[A-Za-z0-9._-]+$"
)
class CompletionClient(Protocol):
@@ -95,7 +98,7 @@ def load_oci_settings() -> OCISettings:
raise ValueError("unsupported OCI authentication mode")
compartment_id = values.get("OCI_GENAI_COMPARTMENT_ID", "").strip()
if not _COMPARTMENT_ID.fullmatch(compartment_id):
if not _COMPARTMENT_OR_ROOT_ID.fullmatch(compartment_id):
raise ValueError("OCI Generative AI compartment is not configured")
return OCISettings(
auth_type=auth_type,