From 212b7dd6da487c070229b6348ec7907b4fecbcf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 27 Sep 2022 22:36:33 +0200 Subject: feat: Add requesting API name to permission prompt (#15936) Co-authored-by: Leo Kettmeir --- ext/fetch/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ext/fetch/lib.rs') diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index 3988acf9e..a7daaa63a 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -167,8 +167,12 @@ impl FetchHandler for DefaultFileFetchHandler { } pub trait FetchPermissions { - fn check_net_url(&mut self, _url: &Url) -> Result<(), AnyError>; - fn check_read(&mut self, _p: &Path) -> Result<(), AnyError>; + fn check_net_url( + &mut self, + _url: &Url, + api_name: &str, + ) -> Result<(), AnyError>; + fn check_read(&mut self, _p: &Path, api_name: &str) -> Result<(), AnyError>; } pub fn get_declaration() -> PathBuf { @@ -215,7 +219,7 @@ where type_error("NetworkError when attempting to fetch resource.") })?; let permissions = state.borrow_mut::(); - permissions.check_read(&path)?; + permissions.check_read(&path, "fetch()")?; if method != Method::GET { return Err(type_error(format!( @@ -240,7 +244,7 @@ where } "http" | "https" => { let permissions = state.borrow_mut::(); - permissions.check_net_url(&url)?; + permissions.check_net_url(&url, "fetch()")?; let mut request = client.request(method.clone(), url); @@ -535,7 +539,7 @@ where if let Some(proxy) = args.proxy.clone() { let permissions = state.borrow_mut::(); let url = Url::parse(&proxy.url)?; - permissions.check_net_url(&url)?; + permissions.check_net_url(&url, "Deno.createHttpClient()")?; } let client_cert_chain_and_key = { -- cgit v1.2.3