fix: Tool secret keys must use a case-insensitive comparison (#275)
Missed one test case here.
This commit is contained in:
parent
e9ee3bba40
commit
4a0e2b8667
2 changed files with 3 additions and 9 deletions
|
|
@ -2,7 +2,7 @@ import os
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Literal, Optional, Union
|
from typing import Any, Literal, Optional, Union
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, field_validator
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
# allow for custom tool name separator
|
# allow for custom tool name separator
|
||||||
TOOL_NAME_SEPARATOR = os.getenv("ARCADE_TOOL_NAME_SEPARATOR", ".")
|
TOOL_NAME_SEPARATOR = os.getenv("ARCADE_TOOL_NAME_SEPARATOR", ".")
|
||||||
|
|
@ -262,12 +262,6 @@ class ToolContext(BaseModel):
|
||||||
user_id: str | None = None
|
user_id: str | None = None
|
||||||
"""The user ID for the tool invocation (if any)."""
|
"""The user ID for the tool invocation (if any)."""
|
||||||
|
|
||||||
@field_validator("secrets", mode="before")
|
|
||||||
def lower_keys(cls, v: dict[str, ToolSecretItem] | None) -> dict[str, ToolSecretItem] | None:
|
|
||||||
if isinstance(v, dict):
|
|
||||||
return {k.lower(): value for k, value in v.items()}
|
|
||||||
return v
|
|
||||||
|
|
||||||
def get_auth_token_or_empty(self) -> str:
|
def get_auth_token_or_empty(self) -> str:
|
||||||
"""Retrieve the authorization token, or return an empty string if not available."""
|
"""Retrieve the authorization token, or return an empty string if not available."""
|
||||||
return self.authorization.token if self.authorization and self.authorization.token else ""
|
return self.authorization.token if self.authorization and self.authorization.token else ""
|
||||||
|
|
@ -282,7 +276,7 @@ class ToolContext(BaseModel):
|
||||||
|
|
||||||
normalized_key = key.lower()
|
normalized_key = key.lower()
|
||||||
for secret in self.secrets:
|
for secret in self.secrets:
|
||||||
if secret.key == normalized_key:
|
if secret.key.lower() == normalized_key:
|
||||||
return secret.value
|
return secret.value
|
||||||
raise ValueError(f"Secret {key} not found in context.")
|
raise ValueError(f"Secret {key} not found in context.")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ def test_get_secret_valid():
|
||||||
|
|
||||||
|
|
||||||
def test_get_secret_with_case_insensitive_key():
|
def test_get_secret_with_case_insensitive_key():
|
||||||
key = "my_key"
|
key = "My_key"
|
||||||
val = "secret_value"
|
val = "secret_value"
|
||||||
secrets = [ToolSecretItem(key=key, value=val)]
|
secrets = [ToolSecretItem(key=key, value=val)]
|
||||||
tool_context = ToolContext(secrets=secrets)
|
tool_context = ToolContext(secrets=secrets)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue