Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No prompts flag for non interactive environments. #1913

Merged
merged 8 commits into from
Mar 13, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Applied a little DRY to no prompts checks in permissions.
  • Loading branch information
afinch7 committed Mar 12, 2019
commit ddd043d1f75b72d247bd662d3777a117ada5b5dc
71 changes: 31 additions & 40 deletions src/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,80 +38,71 @@ impl DenoPermissions {
return Ok(());
};
// TODO get location (where access occurred)
if !self.no_prompts.load(Ordering::SeqCst) {
let r = permission_prompt("access to run a subprocess");
if r.is_ok() {
self.allow_run.store(true, Ordering::SeqCst);
}
r
} else {
Err(permission_denied())
let r = self.try_permissions_prompt("access to run a subprocess");
if r.is_ok() {
self.allow_run.store(true, Ordering::SeqCst);
}
r
}

pub fn check_read(&self, filename: &str) -> DenoResult<()> {
if self.allow_read.load(Ordering::SeqCst) {
return Ok(());
};
// TODO get location (where access occurred)
if !self.no_prompts.load(Ordering::SeqCst) {
let r = permission_prompt(&format!("read access to \"{}\"", filename));;
if r.is_ok() {
self.allow_read.store(true, Ordering::SeqCst);
}
r
} else {
Err(permission_denied())
let r =
self.try_permissions_prompt(&format!("read access to \"{}\"", filename));;
if r.is_ok() {
self.allow_read.store(true, Ordering::SeqCst);
}
r
}

pub fn check_write(&self, filename: &str) -> DenoResult<()> {
if self.allow_write.load(Ordering::SeqCst) {
return Ok(());
};
// TODO get location (where access occurred)
if !self.no_prompts.load(Ordering::SeqCst) {
let r = permission_prompt(&format!("write access to \"{}\"", filename));;
if r.is_ok() {
self.allow_write.store(true, Ordering::SeqCst);
}
r
} else {
Err(permission_denied())
let r =
self.try_permissions_prompt(&format!("write access to \"{}\"", filename));;
if r.is_ok() {
self.allow_write.store(true, Ordering::SeqCst);
}
r
}

pub fn check_net(&self, domain_name: &str) -> DenoResult<()> {
if self.allow_net.load(Ordering::SeqCst) {
return Ok(());
};
// TODO get location (where access occurred)
if !self.no_prompts.load(Ordering::SeqCst) {
let r =
permission_prompt(&format!("network access to \"{}\"", domain_name));
if r.is_ok() {
self.allow_net.store(true, Ordering::SeqCst);
}
r
} else {
Err(permission_denied())
let r = self.try_permissions_prompt(&format!(
"network access to \"{}\"",
domain_name
));
if r.is_ok() {
self.allow_net.store(true, Ordering::SeqCst);
}
r
}

pub fn check_env(&self) -> DenoResult<()> {
if self.allow_env.load(Ordering::SeqCst) {
return Ok(());
};
// TODO get location (where access occurred)
if !self.no_prompts.load(Ordering::SeqCst) {
let r = permission_prompt(&"access to environment variables");
if r.is_ok() {
self.allow_env.store(true, Ordering::SeqCst);
}
r
} else {
let r = self.try_permissions_prompt(&"access to environment variables");
if r.is_ok() {
self.allow_env.store(true, Ordering::SeqCst);
}
r
}

fn try_permissions_prompt(message: &str) {
if self.no_prompts.load(Ordering::SeqCst) {
Err(permission_denied())
}
permission_prompt(message)
}

pub fn allows_run(&self) -> bool {
Expand Down