pub struct PathValidator { /* private fields */ }Implementations§
Source§impl PathValidator
impl PathValidator
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/sandbox.rs (line 11)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 // Path validation
11 let mut validator = PathValidator::new();
12 validator.add_workspace_folder(std::env::current_dir()?);
13 let safe = validator.validate_path("file:///workspace/src/main.rs")?;
14 println!("Validated path: {}", safe.display());
15
16 // Permissions
17 let perms = ExtensionPermissions::from_manifest(
18 "my-extension".to_string(),
19 Some(vec!["fileSystem.read".to_string()]),
20 )?;
21 perms.check_permission(&Permission::FileSystemRead)?;
22 println!("Permission check passed.");
23
24 // Rate limiting
25 let limiter = RateLimiter::new();
26 limiter.check_rate_limit("my-extension")?;
27 println!("Rate limit check passed.");
28
29 // Secret storage
30 let secrets = SecretStorage::new();
31 secrets.set("my-extension", "api_key", "secret-value")?;
32 let value = secrets.get("my-extension", "api_key")?;
33 println!("Retrieved secret: {}", value.unwrap_or_default());
34
35 Ok(())
36}Sourcepub fn add_workspace_folder(&mut self, path: PathBuf)
pub fn add_workspace_folder(&mut self, path: PathBuf)
Examples found in repository?
examples/sandbox.rs (line 12)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 // Path validation
11 let mut validator = PathValidator::new();
12 validator.add_workspace_folder(std::env::current_dir()?);
13 let safe = validator.validate_path("file:///workspace/src/main.rs")?;
14 println!("Validated path: {}", safe.display());
15
16 // Permissions
17 let perms = ExtensionPermissions::from_manifest(
18 "my-extension".to_string(),
19 Some(vec!["fileSystem.read".to_string()]),
20 )?;
21 perms.check_permission(&Permission::FileSystemRead)?;
22 println!("Permission check passed.");
23
24 // Rate limiting
25 let limiter = RateLimiter::new();
26 limiter.check_rate_limit("my-extension")?;
27 println!("Rate limit check passed.");
28
29 // Secret storage
30 let secrets = SecretStorage::new();
31 secrets.set("my-extension", "api_key", "secret-value")?;
32 let value = secrets.get("my-extension", "api_key")?;
33 println!("Retrieved secret: {}", value.unwrap_or_default());
34
35 Ok(())
36}pub fn set_extensions_dir(&mut self, path: PathBuf)
pub fn set_storage_dir(&mut self, path: PathBuf)
pub fn set_logs_dir(&mut self, path: PathBuf)
pub fn set_temp_dir(&mut self, path: PathBuf)
Sourcepub fn validate_path(&self, uri: &str) -> Result<PathBuf, String>
pub fn validate_path(&self, uri: &str) -> Result<PathBuf, String>
Validate and normalize a path from a URI
Examples found in repository?
examples/sandbox.rs (line 13)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 // Path validation
11 let mut validator = PathValidator::new();
12 validator.add_workspace_folder(std::env::current_dir()?);
13 let safe = validator.validate_path("file:///workspace/src/main.rs")?;
14 println!("Validated path: {}", safe.display());
15
16 // Permissions
17 let perms = ExtensionPermissions::from_manifest(
18 "my-extension".to_string(),
19 Some(vec!["fileSystem.read".to_string()]),
20 )?;
21 perms.check_permission(&Permission::FileSystemRead)?;
22 println!("Permission check passed.");
23
24 // Rate limiting
25 let limiter = RateLimiter::new();
26 limiter.check_rate_limit("my-extension")?;
27 println!("Rate limit check passed.");
28
29 // Secret storage
30 let secrets = SecretStorage::new();
31 secrets.set("my-extension", "api_key", "secret-value")?;
32 let value = secrets.get("my-extension", "api_key")?;
33 println!("Retrieved secret: {}", value.unwrap_or_default());
34
35 Ok(())
36}pub fn validate_file_path(&self, path_str: &str) -> Result<PathBuf, String>
Sourcepub fn sanitize_error(error: &dyn Display) -> String
pub fn sanitize_error(error: &dyn Display) -> String
Sanitize error messages to not leak full file system paths
Sourcepub fn get_relative_path(&self, canonical_path: &Path) -> PathBuf
pub fn get_relative_path(&self, canonical_path: &Path) -> PathBuf
Get relative path for display (doesn’t leak full FS structure)
Trait Implementations§
Source§impl Clone for PathValidator
impl Clone for PathValidator
Source§fn clone(&self) -> PathValidator
fn clone(&self) -> PathValidator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for PathValidator
impl Debug for PathValidator
Auto Trait Implementations§
impl Freeze for PathValidator
impl RefUnwindSafe for PathValidator
impl Send for PathValidator
impl Sync for PathValidator
impl Unpin for PathValidator
impl UnsafeUnpin for PathValidator
impl UnwindSafe for PathValidator
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more