mirror of
https://github.com/denoland/deno.git
synced 2025-09-24 19:32:30 +00:00
feat(permissions): allow env permission to take values (#9825)
This commit is contained in:
parent
ec1fce58d9
commit
8b59d9f7bc
6 changed files with 350 additions and 59 deletions
|
@ -54,7 +54,7 @@ fn op_set_env(
|
|||
args: SetEnv,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<(), AnyError> {
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check(&args.key)?;
|
||||
let invalid_key =
|
||||
args.key.is_empty() || args.key.contains(&['=', '\0'] as &[char]);
|
||||
let invalid_value = args.value.contains('\0');
|
||||
|
@ -70,7 +70,7 @@ fn op_env(
|
|||
_args: (),
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<HashMap<String, String>, AnyError> {
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||
Ok(env::vars().collect())
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ fn op_get_env(
|
|||
key: String,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<Option<String>, AnyError> {
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check(&key)?;
|
||||
if key.is_empty() || key.contains(&['=', '\0'] as &[char]) {
|
||||
return Err(type_error("Key contains invalid characters."));
|
||||
}
|
||||
|
@ -89,12 +89,13 @@ fn op_get_env(
|
|||
};
|
||||
Ok(r)
|
||||
}
|
||||
|
||||
fn op_delete_env(
|
||||
state: &mut OpState,
|
||||
key: String,
|
||||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<(), AnyError> {
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check(&key)?;
|
||||
if key.is_empty() || key.contains(&['=', '\0'] as &[char]) {
|
||||
return Err(type_error("Key contains invalid characters."));
|
||||
}
|
||||
|
@ -116,7 +117,7 @@ fn op_loadavg(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<(f64, f64, f64), AnyError> {
|
||||
super::check_unstable(state, "Deno.loadavg");
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||
match sys_info::loadavg() {
|
||||
Ok(loadavg) => Ok((loadavg.one, loadavg.five, loadavg.fifteen)),
|
||||
Err(_) => Ok((0.0, 0.0, 0.0)),
|
||||
|
@ -129,7 +130,7 @@ fn op_hostname(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<String, AnyError> {
|
||||
super::check_unstable(state, "Deno.hostname");
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||
let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_string());
|
||||
Ok(hostname)
|
||||
}
|
||||
|
@ -140,7 +141,7 @@ fn op_os_release(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<String, AnyError> {
|
||||
super::check_unstable(state, "Deno.osRelease");
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||
let release = sys_info::os_release().unwrap_or_else(|_| "".to_string());
|
||||
Ok(release)
|
||||
}
|
||||
|
@ -164,7 +165,7 @@ fn op_system_memory_info(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<Option<MemInfo>, AnyError> {
|
||||
super::check_unstable(state, "Deno.systemMemoryInfo");
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||
match sys_info::mem_info() {
|
||||
Ok(info) => Ok(Some(MemInfo {
|
||||
total: info.total,
|
||||
|
@ -191,7 +192,7 @@ fn op_system_cpu_info(
|
|||
_zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<CpuInfo, AnyError> {
|
||||
super::check_unstable(state, "Deno.systemCpuInfo");
|
||||
state.borrow_mut::<Permissions>().env.check()?;
|
||||
state.borrow_mut::<Permissions>().env.check_all()?;
|
||||
|
||||
let cores = sys_info::cpu_num().ok();
|
||||
let speed = sys_info::cpu_speed().ok();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue