mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-13 22:26:53 +00:00
refactor(secrets): address Secrets the way every other object is addressed
Secret CRUD used plural collection routes with the identity in the body, which is the one shape in the HTTP surface that does not match Table and Function CRUD. #4166 moved Functions onto `<object>/{id}/<action>`; this does the same for Secrets, so there is one route grammar rather than one per object type. POST /v1/secrets/create -> POST /v1/secret/{id}/create POST /v1/secrets/alter -> POST /v1/secret/{id}/alter POST /v1/secrets/describe -> POST /v1/secret/{id}/describe POST /v1/secrets/drop -> POST /v1/secret/{id}/drop POST /v1/secrets/list -> GET /v1/namespace/{id}/secret/list `{id}` is the namespace path and the name joined with the client's configured delimiter, built by the same helper a table identifier is. The name and the namespace therefore leave every request body: create and alter carry the value alone, drop and describe carry nothing, and listing moves its `page_token` to a query parameter. `add_namespace_path` goes with them -- a root Secret is addressed by its bare name, so there is no longer an empty field to omit. Identifiers are written into the path as-is rather than percent-encoded. The charset a Secret name and a namespace segment admit already excludes everything that would need escaping, and a route that reads like the ones beside it is worth more than encoding against a charset that does not exist yet. If that charset widens, this is the place that has to widen with it. Listing takes a real namespace rather than rejecting a non-root one the way the Function route does: Secrets are addressable inside nested namespaces, so the namespace identifier is the whole point of the route. `build_secret_identifier` is a wrapper over `build_table_identifier` rather than a second implementation. The grammar belongs to the namespace spec rather than to tables, and a call site should read as the thing it addresses. Also removes `_DECLARED_SECRET`, which has been unreferenced since client-side binding validation was dropped, and whose pattern was the environment variable grammar rather than a Secret name's. Tests: lancedb secret unit tests 7, `first_class_function_slice1` 9, `first_class_function_slice2` 3, 93 Python tests across both slices. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UfmeJ533rQDnPBkMtjerV6
This commit is contained in:
co-authored by
Claude Opus 5
parent
6a4366b76e
commit
2041c1a240
@@ -559,7 +559,6 @@ class RefreshColumnResult(_RemoteValue):
|
||||
|
||||
|
||||
_FUNCTION_NAME = re.compile(r"^[A-Za-z_][A-Za-z0-9_.-]*$")
|
||||
_DECLARED_SECRET = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")
|
||||
|
||||
_FUNCTION_BLOB_V2_TYPE = "blob_v2"
|
||||
_ARROW_EXTENSION_NAME_KEY = "ARROW:extension:name"
|
||||
|
||||
@@ -1528,6 +1528,11 @@ def _mock_remote_function_catalog():
|
||||
if len(parts) == 4 and parts[0] == "v1" and parts[1] == "function"
|
||||
else (None, None)
|
||||
)
|
||||
secret_action = (
|
||||
(urllib.parse.unquote(parts[2]), parts[3])
|
||||
if len(parts) == 4 and parts[0] == "v1" and parts[1] == "secret"
|
||||
else (None, None)
|
||||
)
|
||||
if function_action[1] == "create":
|
||||
state["version"] = {
|
||||
"name": function_action[0],
|
||||
@@ -1559,20 +1564,14 @@ def _mock_remote_function_catalog():
|
||||
elif function_action[1] == "drop":
|
||||
assert body == {"version": "fv_exact"}
|
||||
response = {"dropped": True}
|
||||
elif self.path in ("/v1/secrets/create", "/v1/secrets/alter"):
|
||||
assert set(body) == {"name", "value"}
|
||||
elif secret_action[1] in ("create", "alter"):
|
||||
# The Secret is the path identifier, so the body is the value.
|
||||
assert set(body) == {"value"}
|
||||
assert secret_action[0] == "openai-prod"
|
||||
response = {}
|
||||
elif self.path == "/v1/secrets/list":
|
||||
if "page_token" not in body:
|
||||
response = {
|
||||
"secrets": [{"name": "openai-prod"}],
|
||||
"page_token": "next",
|
||||
}
|
||||
else:
|
||||
assert body["page_token"] == "next"
|
||||
response = {"secrets": [{"name": "hf-prod"}]}
|
||||
elif self.path == "/v1/secrets/drop":
|
||||
assert body == {"name": "openai-prod"}
|
||||
elif secret_action[1] == "drop":
|
||||
assert secret_action[0] == "openai-prod"
|
||||
assert body == {}
|
||||
response = {}
|
||||
else:
|
||||
status = 404
|
||||
@@ -1586,6 +1585,16 @@ def _mock_remote_function_catalog():
|
||||
for key, values in urllib.parse.parse_qs(url.query).items()
|
||||
}
|
||||
state["requests"].append((url.path, query))
|
||||
if url.path == "/v1/namespace/$/secret/list":
|
||||
if "page_token" not in query:
|
||||
self._write_response(
|
||||
200,
|
||||
{"secrets": [{"name": "openai-prod"}], "page_token": "next"},
|
||||
)
|
||||
else:
|
||||
assert query["page_token"] == "next"
|
||||
self._write_response(200, {"secrets": [{"name": "hf-prod"}]})
|
||||
return
|
||||
if url.path != "/v1/namespace/$/function/list":
|
||||
self._write_response(404, {"error": "not found"})
|
||||
return
|
||||
@@ -1698,15 +1707,18 @@ def test_remote_secret_verbs_round_trip():
|
||||
|
||||
routes = [path for path, _ in state["requests"]]
|
||||
assert routes == [
|
||||
"/v1/secrets/create",
|
||||
"/v1/secrets/alter",
|
||||
"/v1/secrets/list",
|
||||
"/v1/secrets/list",
|
||||
"/v1/secrets/drop",
|
||||
"/v1/secret/openai-prod/create",
|
||||
"/v1/secret/openai-prod/alter",
|
||||
"/v1/namespace/$/secret/list",
|
||||
"/v1/namespace/$/secret/list",
|
||||
"/v1/secret/openai-prod/drop",
|
||||
]
|
||||
assert state["requests"][0][1] == {"name": "openai-prod", "value": "sk-live-0001"}
|
||||
# The listing returns names, and the client has no way to ask for more.
|
||||
# The Secret is the path identifier, so the body is the value alone.
|
||||
assert state["requests"][0][1] == {"value": "sk-live-0001"}
|
||||
# Listing is a GET: the first page asks for nothing, the second resumes on
|
||||
# the token the server handed back, and neither carries a body.
|
||||
assert state["requests"][2][1] == {}
|
||||
assert state["requests"][3][1] == {"page_token": "next"}
|
||||
|
||||
|
||||
def test_building_a_binding_contacts_no_server():
|
||||
|
||||
Reference in New Issue
Block a user