pub struct ProtectedTool<T: Tool> { /* private fields */ }Expand description
A tool wrapper that enforces access control and optionally logs audit events.
Wraps any tool and checks permissions before execution.
§Example
ⓘ
use adk_auth::{AccessControl, ProtectedTool, Permission, Role};
use std::sync::Arc;
let ac = AccessControl::builder()
.role(Role::new("user").allow(Permission::Tool("search".into())))
.build()?;
let protected_search = ProtectedTool::new(search_tool, Arc::new(ac));Implementations§
Source§impl<T: Tool> ProtectedTool<T>
impl<T: Tool> ProtectedTool<T>
Sourcepub fn new(tool: T, access_control: Arc<AccessControl>) -> Self
pub fn new(tool: T, access_control: Arc<AccessControl>) -> Self
Create a new protected tool.
Sourcepub fn with_audit(
tool: T,
access_control: Arc<AccessControl>,
audit_sink: Arc<dyn AuditSink>,
) -> Self
pub fn with_audit( tool: T, access_control: Arc<AccessControl>, audit_sink: Arc<dyn AuditSink>, ) -> Self
Create a new protected tool with audit logging.
Trait Implementations§
Source§impl<T: Tool + Send + Sync> Tool for ProtectedTool<T>
impl<T: Tool + Send + Sync> Tool for ProtectedTool<T>
fn name(&self) -> &str
fn description(&self) -> &str
Source§fn enhanced_description(&self) -> String
fn enhanced_description(&self) -> String
Returns an enhanced description that may include additional notes.
For long-running tools, this includes a warning not to call the tool
again if it has already returned a pending status.
Default implementation returns the base description.
Source§fn is_long_running(&self) -> bool
fn is_long_running(&self) -> bool
Indicates whether the tool is a long-running operation.
Long-running tools typically return a task ID immediately and
complete the operation asynchronously.
fn parameters_schema(&self) -> Option<Value>
fn response_schema(&self) -> Option<Value>
fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Arc<dyn ToolContext>,
args: Value,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl<T> Freeze for ProtectedTool<T>where
T: Freeze,
impl<T> !RefUnwindSafe for ProtectedTool<T>
impl<T> Send for ProtectedTool<T>
impl<T> Sync for ProtectedTool<T>
impl<T> Unpin for ProtectedTool<T>where
T: Unpin,
impl<T> !UnwindSafe for ProtectedTool<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> ToolExt for Twhere
T: Tool,
impl<T> ToolExt for Twhere
T: Tool,
Source§fn with_access_control(self, ac: Arc<AccessControl>) -> ProtectedTool<Self>
fn with_access_control(self, ac: Arc<AccessControl>) -> ProtectedTool<Self>
Wrap this tool with access control.
Source§fn with_access_control_and_audit(
self,
ac: Arc<AccessControl>,
audit: Arc<dyn AuditSink>,
) -> ProtectedTool<Self>
fn with_access_control_and_audit( self, ac: Arc<AccessControl>, audit: Arc<dyn AuditSink>, ) -> ProtectedTool<Self>
Wrap this tool with access control and audit logging.