Skip to content

Commit

Permalink
Enhance credential validation by stripping whitespace from API endpoi…
Browse files Browse the repository at this point in the history
…nt and key, and add error handling for missing values
  • Loading branch information
fujita-h committed Jan 17, 2025
1 parent c6ac604 commit 41bda4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions provider/azure_ai_document_intelligence.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
class AzureAiDocumentIntelligenceProvider(ToolProvider):
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
try:
api_endpoint = credentials.get("api_endpoint")
api_key = credentials.get("api_key")
api_endpoint = str(credentials.get("api_endpoint", "")).strip()
api_key = str(credentials.get("api_key", "")).strip()

# Ensure API key and endpoint are provided
if not api_endpoint:
Expand Down
10 changes: 8 additions & 2 deletions tools/extract_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessag
raise Exception("Tool runtime or credentials are missing")

# Get endpoint and api key
endpoint = str(self.runtime.credentials.get("api_endpoint"))
api_key = str(self.runtime.credentials.get("api_key"))
endpoint = str(self.runtime.credentials.get("api_endpoint", "")).strip()
api_key = str(self.runtime.credentials.get("api_key", "")).strip()

# Check if endpoint and api key are provided
if not endpoint:
raise ValueError("API endpoint is missing")
if not api_key:
raise ValueError("API key is missing")

# Create credential
credential = AzureKeyCredential(api_key)
Expand Down

0 comments on commit 41bda4c

Please # to comment.