summaryrefslogtreecommitdiff
path: root/src/permissions.rs
diff options
context:
space:
mode:
authorSimon Menke <simon.menke@gmail.com>2019-03-04 17:04:19 +0100
committerRyan Dahl <ry@tinyclouds.org>2019-03-04 11:04:19 -0500
commit77d7ad61f39641b79a60a99da2f939cbc1d8fe39 (patch)
tree3bc46c49b0007fb83c435d6cf417dd0f844d947c /src/permissions.rs
parent048a8a77753881936d7c6b32f4534ee364eb42ad (diff)
Allow inspection and revocation of permissions (#1875)
Diffstat (limited to 'src/permissions.rs')
-rw-r--r--src/permissions.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/permissions.rs b/src/permissions.rs
index b40afb64e..03ffd20cb 100644
--- a/src/permissions.rs
+++ b/src/permissions.rs
@@ -12,6 +12,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
#[cfg_attr(feature = "cargo-clippy", allow(stutter))]
#[derive(Debug, Default)]
pub struct DenoPermissions {
+ // Keep in sync with src/permissions.ts
pub allow_read: AtomicBool,
pub allow_write: AtomicBool,
pub allow_net: AtomicBool,
@@ -91,6 +92,51 @@ impl DenoPermissions {
r
}
+ pub fn allows_run(&self) -> bool {
+ return self.allow_run.load(Ordering::SeqCst);
+ }
+
+ pub fn allows_read(&self) -> bool {
+ return self.allow_read.load(Ordering::SeqCst);
+ }
+
+ pub fn allows_write(&self) -> bool {
+ return self.allow_write.load(Ordering::SeqCst);
+ }
+
+ pub fn allows_net(&self) -> bool {
+ return self.allow_net.load(Ordering::SeqCst);
+ }
+
+ pub fn allows_env(&self) -> bool {
+ return self.allow_env.load(Ordering::SeqCst);
+ }
+
+ pub fn revoke_run(&self) -> DenoResult<()> {
+ self.allow_run.store(false, Ordering::SeqCst);
+ return Ok(());
+ }
+
+ pub fn revoke_read(&self) -> DenoResult<()> {
+ self.allow_read.store(false, Ordering::SeqCst);
+ return Ok(());
+ }
+
+ pub fn revoke_write(&self) -> DenoResult<()> {
+ self.allow_write.store(false, Ordering::SeqCst);
+ return Ok(());
+ }
+
+ pub fn revoke_net(&self) -> DenoResult<()> {
+ self.allow_net.store(false, Ordering::SeqCst);
+ return Ok(());
+ }
+
+ pub fn revoke_env(&self) -> DenoResult<()> {
+ self.allow_env.store(false, Ordering::SeqCst);
+ return Ok(());
+ }
+
pub fn default() -> Self {
Self {
allow_read: AtomicBool::new(false),