-
Notifications
You must be signed in to change notification settings - Fork 38
Plugin updates #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin updates #69
Changes from 3 commits
afe4e07
aa448aa
6a35aab
7c5a4a0
0361323
f378e67
88e7ded
fcc7856
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from utcp.data.call_template import CallTemplate, CallTemplateSerializer | ||
from utcp.data.auth import Auth | ||
from utcp.data.auth import Auth, AuthSerializer | ||
from utcp.interfaces.serializer import Serializer | ||
from utcp.exceptions import UtcpSerializerValidationError | ||
import traceback | ||
from typing import Optional, Dict, List, Literal | ||
from pydantic import Field | ||
from typing import Optional, Dict, List, Literal, Any | ||
from pydantic import Field, field_serializer, field_validator | ||
|
||
class HttpCallTemplate(CallTemplate): | ||
"""REQUIRED | ||
|
@@ -40,6 +40,12 @@ class HttpCallTemplate(CallTemplate): | |
"var_name": "Authorization", | ||
"location": "header" | ||
}, | ||
"auth_tools": { | ||
"auth_type": "api_key", | ||
"api_key": "Bearer ${TOOL_API_KEY}", | ||
"var_name": "Authorization", | ||
"location": "header" | ||
}, | ||
"headers": { | ||
"X-Custom-Header": "value" | ||
}, | ||
|
@@ -85,7 +91,8 @@ class HttpCallTemplate(CallTemplate): | |
url: The base URL for the HTTP endpoint. Supports path parameters like | ||
"https://api.example.com/users/{user_id}/posts/{post_id}". | ||
content_type: The Content-Type header for requests. | ||
auth: Optional authentication configuration. | ||
auth: Optional authentication configuration for accessing the OpenAPI spec URL. | ||
auth_tools: Optional authentication configuration for generated tools. Applied only to endpoints requiring auth per OpenAPI spec. | ||
headers: Optional static headers to include in all requests. | ||
body_field: Name of the tool argument to map to the HTTP request body. | ||
header_fields: List of tool argument names to map to HTTP request headers. | ||
|
@@ -96,10 +103,49 @@ class HttpCallTemplate(CallTemplate): | |
url: str | ||
content_type: str = Field(default="application/json") | ||
auth: Optional[Auth] = None | ||
auth_tools: Optional[Auth] = Field(default=None, description="Authentication configuration for generated tools (applied only to endpoints requiring auth per OpenAPI spec)") | ||
headers: Optional[Dict[str, str]] = None | ||
body_field: Optional[str] = Field(default="body", description="The name of the single input field to be sent as the request body.") | ||
header_fields: Optional[List[str]] = Field(default=None, description="List of input fields to be sent as request headers.") | ||
|
||
@field_serializer('auth') | ||
|
||
def serialize_auth(self, auth: Optional[Auth]) -> Optional[dict]: | ||
"""Serialize auth to dictionary.""" | ||
if auth is None: | ||
return None | ||
return AuthSerializer().to_dict(auth) | ||
|
||
@field_validator('auth', mode='before') | ||
|
||
@classmethod | ||
def validate_auth(cls, v: Any) -> Optional[Auth]: | ||
"""Validate and deserialize auth from dictionary.""" | ||
if v is None: | ||
return None | ||
if isinstance(v, Auth): | ||
return v | ||
if isinstance(v, dict): | ||
return AuthSerializer().validate_dict(v) | ||
raise ValueError(f"auth must be None, Auth instance, or dict, got {type(v)}") | ||
|
||
@field_serializer('auth_tools') | ||
def serialize_auth_tools(self, auth_tools: Optional[Auth]) -> Optional[dict]: | ||
"""Serialize auth_tools to dictionary.""" | ||
if auth_tools is None: | ||
return None | ||
return AuthSerializer().to_dict(auth_tools) | ||
|
||
@field_validator('auth_tools', mode='before') | ||
@classmethod | ||
def validate_auth_tools(cls, v: Any) -> Optional[Auth]: | ||
"""Validate and deserialize auth_tools from dictionary.""" | ||
if v is None: | ||
return None | ||
if isinstance(v, Auth): | ||
return v | ||
if isinstance(v, dict): | ||
return AuthSerializer().validate_dict(v) | ||
raise ValueError(f"auth_tools must be None, Auth instance, or dict, got {type(v)}") | ||
|
||
|
||
class HttpCallTemplateSerializer(Serializer[HttpCallTemplate]): | ||
"""REQUIRED | ||
|
Uh oh!
There was an error while loading. Please reload this page.