diff options
Diffstat (limited to 'runtime/permissions')
| -rw-r--r-- | runtime/permissions/mod.rs | 47 | ||||
| -rw-r--r-- | runtime/permissions/prompter.rs | 18 |
2 files changed, 32 insertions, 33 deletions
diff --git a/runtime/permissions/mod.rs b/runtime/permissions/mod.rs index 494e603a3..298146312 100644 --- a/runtime/permissions/mod.rs +++ b/runtime/permissions/mod.rs @@ -67,7 +67,7 @@ impl PermissionState { format!( "{} access{}", name, - info().map_or(String::new(), |info| { format!(" to {}", info) }), + info().map_or(String::new(), |info| { format!(" to {info}") }), ) } @@ -111,7 +111,7 @@ impl PermissionState { let msg = format!( "{} access{}", name, - info().map_or(String::new(), |info| { format!(" to {}", info) }), + info().map_or(String::new(), |info| { format!(" to {info}") }), ); if PromptResponse::Allow == permission_prompt(&msg, name, api_name) { Self::log_perm_access(name, info); @@ -314,7 +314,7 @@ pub fn parse_sys_kind(kind: &str) -> Result<&str, AnyError> { match kind { "hostname" | "osRelease" | "osUptime" | "loadavg" | "networkInterfaces" | "systemMemoryInfo" | "uid" | "gid" => Ok(kind), - _ => Err(type_error(format!("unknown system info kind \"{}\"", kind))), + _ => Err(type_error(format!("unknown system info kind \"{kind}\""))), } } @@ -451,7 +451,7 @@ impl UnaryPermission<ReadDescriptor> { let (result, prompted) = self.query(Some(&resolved_path)).check( self.name, Some(api_name), - Some(&format!("<{}>", display)), + Some(&format!("<{display}>")), self.prompt, ); if prompted { @@ -687,7 +687,7 @@ impl UnaryPermission<NetDescriptor> { if state == PermissionState::Prompt { if PromptResponse::Allow == permission_prompt( - &format!("network access to \"{}\"", host), + &format!("network access to \"{host}\""), self.name, Some("Deno.permissions.query()"), ) @@ -759,7 +759,7 @@ impl UnaryPermission<NetDescriptor> { let (result, prompted) = self.query(Some(host)).check( self.name, api_name, - Some(&format!("\"{}\"", new_host)), + Some(&format!("\"{new_host}\"")), self.prompt, ); if prompted { @@ -784,13 +784,13 @@ impl UnaryPermission<NetDescriptor> { .to_string(); let display_host = match url.port() { None => hostname.clone(), - Some(port) => format!("{}:{}", hostname, port), + Some(port) => format!("{hostname}:{port}"), }; let host = &(&hostname, url.port_or_known_default()); let (result, prompted) = self.query(Some(host)).check( self.name, api_name, - Some(&format!("\"{}\"", display_host)), + Some(&format!("\"{display_host}\"")), self.prompt, ); if prompted { @@ -861,7 +861,7 @@ impl UnaryPermission<EnvDescriptor> { if state == PermissionState::Prompt { if PromptResponse::Allow == permission_prompt( - &format!("env access to \"{}\"", env), + &format!("env access to \"{env}\""), self.name, Some("Deno.permissions.query()"), ) @@ -918,7 +918,7 @@ impl UnaryPermission<EnvDescriptor> { let (result, prompted) = self.query(Some(env)).check( self.name, None, - Some(&format!("\"{}\"", env)), + Some(&format!("\"{env}\"")), self.prompt, ); if prompted { @@ -995,7 +995,7 @@ impl UnaryPermission<SysDescriptor> { let desc = SysDescriptor(kind.to_string()); if PromptResponse::Allow == permission_prompt( - &format!("sys access to \"{}\"", kind), + &format!("sys access to \"{kind}\""), self.name, Some("Deno.permissions.query()"), ) @@ -1044,7 +1044,7 @@ impl UnaryPermission<SysDescriptor> { let (result, prompted) = self.query(Some(kind)).check( self.name, api_name, - Some(&format!("\"{}\"", kind)), + Some(&format!("\"{kind}\"")), self.prompt, ); if prompted { @@ -1118,7 +1118,7 @@ impl UnaryPermission<RunDescriptor> { if state == PermissionState::Prompt { if PromptResponse::Allow == permission_prompt( - &format!("run access to \"{}\"", cmd), + &format!("run access to \"{cmd}\""), self.name, Some("Deno.permissions.query()"), ) @@ -1187,7 +1187,7 @@ impl UnaryPermission<RunDescriptor> { let (result, prompted) = self.query(Some(cmd)).check( self.name, api_name, - Some(&format!("\"{}\"", cmd)), + Some(&format!("\"{cmd}\"")), self.prompt, ); if prompted { @@ -1606,8 +1606,7 @@ impl Permissions { "file" => match specifier.to_file_path() { Ok(path) => self.read.check(&path, Some("import()")), Err(_) => Err(uri_error(format!( - "Invalid file path.\n Specifier: {}", - specifier + "Invalid file path.\n Specifier: {specifier}" ))), }, "data" => Ok(()), @@ -2121,42 +2120,42 @@ impl<'de> Deserialize<'de> for ChildPermissionsArg { if key == "env" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.env = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.env) {}", e)) + de::Error::custom(format!("(deno.permissions.env) {e}")) })?; } else if key == "hrtime" { let arg = serde_json::from_value::<ChildUnitPermissionArg>(value); child_permissions_arg.hrtime = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.hrtime) {}", e)) + de::Error::custom(format!("(deno.permissions.hrtime) {e}")) })?; } else if key == "net" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.net = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.net) {}", e)) + de::Error::custom(format!("(deno.permissions.net) {e}")) })?; } else if key == "ffi" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.ffi = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.ffi) {}", e)) + de::Error::custom(format!("(deno.permissions.ffi) {e}")) })?; } else if key == "read" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.read = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.read) {}", e)) + de::Error::custom(format!("(deno.permissions.read) {e}")) })?; } else if key == "run" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.run = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.run) {}", e)) + de::Error::custom(format!("(deno.permissions.run) {e}")) })?; } else if key == "sys" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.sys = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.sys) {}", e)) + de::Error::custom(format!("(deno.permissions.sys) {e}")) })?; } else if key == "write" { let arg = serde_json::from_value::<ChildUnaryPermissionArg>(value); child_permissions_arg.write = arg.map_err(|e| { - de::Error::custom(format!("(deno.permissions.write) {}", e)) + de::Error::custom(format!("(deno.permissions.write) {e}")) })?; } else { return Err(de::Error::custom("unknown permission name")); diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index ae07e004c..e311bc978 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -182,13 +182,13 @@ impl PermissionPrompter for TtyPrompter { // Clear n-lines in terminal and move cursor to the beginning of the line. fn clear_n_lines(n: usize) { - eprint!("\x1B[{}A\x1B[0J", n); + eprint!("\x1B[{n}A\x1B[0J"); } // For security reasons we must consume everything in stdin so that previously // buffered data cannot effect the prompt. if let Err(err) = clear_stdin() { - eprintln!("Error clearing stdin for permission prompt. {:#}", err); + eprintln!("Error clearing stdin for permission prompt. {err:#}"); return PromptResponse::Deny; // don't grant permission if this fails } @@ -199,17 +199,17 @@ impl PermissionPrompter for TtyPrompter { // print to stderr so that if stdout is piped this is still displayed. const OPTS: &str = "[y/n] (y = yes, allow; n = no, deny)"; - eprint!("{} ┌ ", PERMISSION_EMOJI); + eprint!("{PERMISSION_EMOJI} ┌ "); eprint!("{}", colors::bold("Deno requests ")); eprint!("{}", colors::bold(message)); eprintln!("{}", colors::bold(".")); if let Some(api_name) = api_name { - eprintln!(" ├ Requested by `{}` API", api_name); + eprintln!(" ├ Requested by `{api_name}` API"); } - let msg = format!("Run again with --allow-{} to bypass this prompt.", name); + let msg = format!("Run again with --allow-{name} to bypass this prompt."); eprintln!(" ├ {}", colors::italic(&msg)); eprint!(" └ {}", colors::bold("Allow?")); - eprint!(" {} > ", OPTS); + eprint!(" {OPTS} > "); let value = loop { let mut input = String::new(); let stdin = std::io::stdin(); @@ -224,13 +224,13 @@ impl PermissionPrompter for TtyPrompter { match ch.to_ascii_lowercase() { 'y' => { clear_n_lines(if api_name.is_some() { 4 } else { 3 }); - let msg = format!("Granted {}.", message); + let msg = format!("Granted {message}."); eprintln!("✅ {}", colors::bold(&msg)); break PromptResponse::Allow; } 'n' => { clear_n_lines(if api_name.is_some() { 4 } else { 3 }); - let msg = format!("Denied {}.", message); + let msg = format!("Denied {message}."); eprintln!("❌ {}", colors::bold(&msg)); break PromptResponse::Deny; } @@ -238,7 +238,7 @@ impl PermissionPrompter for TtyPrompter { // If we don't get a recognized option try again. clear_n_lines(1); eprint!(" └ {}", colors::bold("Unrecognized option. Allow?")); - eprint!(" {} > ", OPTS); + eprint!(" {OPTS} > "); } }; }; |
