diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler.rs | 1 | ||||
-rw-r--r-- | src/flags.rs | 5 | ||||
-rw-r--r-- | src/ops.rs | 4 | ||||
-rw-r--r-- | src/permissions.rs | 28 |
4 files changed, 32 insertions, 6 deletions
diff --git a/src/compiler.rs b/src/compiler.rs index 5fe335c55..12554dcec 100644 --- a/src/compiler.rs +++ b/src/compiler.rs @@ -58,6 +58,7 @@ fn lazy_start(parent_state: &Arc<IsolateState>) -> Resource { allow_env: AtomicBool::new(false), allow_net: AtomicBool::new(true), allow_run: AtomicBool::new(false), + ..Default::default() }; let rid = cell.get_or_insert_with(|| { let resource = workers::spawn( diff --git a/src/flags.rs b/src/flags.rs index 471fc58ed..d6a63a9fb 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -22,6 +22,7 @@ pub struct DenoFlags { pub allow_net: bool, pub allow_env: bool, pub allow_run: bool, + pub no_prompts: bool, pub types: bool, pub prefetch: bool, pub info: bool, @@ -108,6 +109,9 @@ fn set_recognized_flags( flags.allow_read = true; flags.allow_write = true; } + if matches.opt_present("no-prompt") { + flags.no_prompts = true; + } if matches.opt_present("types") { flags.types = true; } @@ -149,6 +153,7 @@ pub fn set_flags( opts.optflag("", "allow-env", "Allow environment access"); opts.optflag("", "allow-run", "Allow running subprocesses"); opts.optflag("A", "allow-all", "Allow all permissions"); + opts.optflag("", "no-prompt", "Do not use prompts"); opts.optflag("", "recompile", "Force recompilation of TypeScript code"); opts.optflag("h", "help", "Print this message"); opts.optflag("D", "log-debug", "Log debug output"); diff --git a/src/ops.rs b/src/ops.rs index 17cb008db..da4a01863 100644 --- a/src/ops.rs +++ b/src/ops.rs @@ -1899,6 +1899,7 @@ mod tests { allow_env: AtomicBool::new(true), allow_net: AtomicBool::new(true), allow_run: AtomicBool::new(true), + ..Default::default() }; let isolate = Isolate::new( IsolateInit { @@ -1944,6 +1945,7 @@ mod tests { allow_env: AtomicBool::new(true), allow_net: AtomicBool::new(true), allow_run: AtomicBool::new(true), + ..Default::default() }; let isolate = Isolate::new( IsolateInit { @@ -1989,6 +1991,7 @@ mod tests { allow_env: AtomicBool::new(true), allow_net: AtomicBool::new(false), allow_run: AtomicBool::new(true), + ..Default::default() }; let isolate = Isolate::new( IsolateInit { @@ -2034,6 +2037,7 @@ mod tests { allow_env: AtomicBool::new(false), allow_net: AtomicBool::new(true), allow_run: AtomicBool::new(false), + ..Default::default() }; let isolate = Isolate::new( IsolateInit { diff --git a/src/permissions.rs b/src/permissions.rs index 03ffd20cb..5f9588a1e 100644 --- a/src/permissions.rs +++ b/src/permissions.rs @@ -18,6 +18,7 @@ pub struct DenoPermissions { pub allow_net: AtomicBool, pub allow_env: AtomicBool, pub allow_run: AtomicBool, + pub no_prompts: AtomicBool, } impl DenoPermissions { @@ -28,6 +29,7 @@ impl DenoPermissions { allow_env: AtomicBool::new(flags.allow_env), allow_net: AtomicBool::new(flags.allow_net), allow_run: AtomicBool::new(flags.allow_run), + no_prompts: AtomicBool::new(flags.no_prompts), } } @@ -36,7 +38,7 @@ impl DenoPermissions { return Ok(()); }; // TODO get location (where access occurred) - let r = permission_prompt("access to run a subprocess"); + let r = self.try_permissions_prompt("access to run a subprocess"); if r.is_ok() { self.allow_run.store(true, Ordering::SeqCst); } @@ -48,7 +50,8 @@ impl DenoPermissions { return Ok(()); }; // TODO get location (where access occurred) - let r = permission_prompt(&format!("read access to \"{}\"", filename));; + let r = + self.try_permissions_prompt(&format!("read access to \"{}\"", filename));; if r.is_ok() { self.allow_read.store(true, Ordering::SeqCst); } @@ -60,7 +63,8 @@ impl DenoPermissions { return Ok(()); }; // TODO get location (where access occurred) - let r = permission_prompt(&format!("write access to \"{}\"", filename));; + let r = + self.try_permissions_prompt(&format!("write access to \"{}\"", filename));; if r.is_ok() { self.allow_write.store(true, Ordering::SeqCst); } @@ -72,8 +76,10 @@ impl DenoPermissions { return Ok(()); }; // TODO get location (where access occurred) - let r = - permission_prompt(&format!("network access to \"{}\"", domain_name)); + let r = self.try_permissions_prompt(&format!( + "network access to \"{}\"", + domain_name + )); if r.is_ok() { self.allow_net.store(true, Ordering::SeqCst); } @@ -85,13 +91,22 @@ impl DenoPermissions { return Ok(()); }; // TODO get location (where access occurred) - let r = permission_prompt(&"access to environment variables"); + let r = self.try_permissions_prompt(&"access to environment variables"); if r.is_ok() { self.allow_env.store(true, Ordering::SeqCst); } r } + /// Try to present the user with a permission prompt + /// will error with permission_denied if no_prompts is enabled + fn try_permissions_prompt(&self, message: &str) -> DenoResult<()> { + if self.no_prompts.load(Ordering::SeqCst) { + return Err(permission_denied()); + } + permission_prompt(message) + } + pub fn allows_run(&self) -> bool { return self.allow_run.load(Ordering::SeqCst); } @@ -144,6 +159,7 @@ impl DenoPermissions { allow_env: AtomicBool::new(false), allow_net: AtomicBool::new(false), allow_run: AtomicBool::new(false), + ..Default::default() } } } |