Skip to content

Commit 14c0e0f

Browse files
author
Alexander Weber
committed
removed prompt shell trust
1 parent 420ba5c commit 14c0e0f

4 files changed

Lines changed: 27 additions & 56 deletions

File tree

src/args/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ pub struct RenderArguments {
7575
#[derive(Debug, Eq, PartialEq)]
7676
pub enum ShellTrust {
7777
None,
78-
Prompt,
7978
Ultimate,
8079
}
8180

@@ -134,7 +133,7 @@ impl ClapArgumentLoader {
134133
.long("shell-trust")
135134
.value_name("SHELL_TRUST")
136135
.help("Enables the shell mode. This is potentially insecure and should only be done for trustworthy sources.")
137-
.possible_values(&["none", "prompt", "ultimate"])
136+
.possible_values(&["none", "ultimate"])
138137
.multiple(false)
139138
.required(false)
140139
.default_value("none")
@@ -209,7 +208,6 @@ impl ClapArgumentLoader {
209208
let shell_trust = match x.value_of("shell-trust") {
210209
Some(x) => match x {
211210
"none" => ShellTrust::None,
212-
"prompt" => ShellTrust::Prompt,
213211
"ultimate" => ShellTrust::Ultimate,
214212
_ => ShellTrust::None,
215213
},

src/render/cli.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::UserInput;
22
use async_trait::async_trait;
3-
use std::result::Result;
3+
use std::{collections::HashMap, result::Result};
44

55
pub struct CLIBackend<'a> {
66
shell_trust: &'a super::ShellTrust,
@@ -18,14 +18,11 @@ impl<'a> UserInput for CLIBackend<'a> {
1818
match dialoguer::Input::new()
1919
.allow_empty(true)
2020
.with_prompt(text)
21-
.interact() {
22-
Ok(res) => Ok(res),
23-
Err(_) => Err(Box::new(crate::error::Failed::default()))
24-
}
25-
}
26-
27-
async fn shell(&self, command: &str, shell_trust: &super::ShellTrust) -> Result<String, Box<dyn std::error::Error>> {
28-
super::shell(command, shell_trust, &super::Backend::CLI).await
21+
.interact()
22+
{
23+
Ok(res) => Ok(res),
24+
Err(_) => Err(Box::new(crate::error::Failed::default())),
25+
}
2926
}
3027

3128
async fn select(
@@ -47,7 +44,9 @@ impl<'a> UserInput for CLIBackend<'a> {
4744
.interact()?;
4845
match &options[&keys[result_idx]].value {
4946
super::OptionValue::Static(x) => Ok(x.to_owned()),
50-
super::OptionValue::Shell(cmd) => self.shell(cmd, &self.shell_trust).await,
47+
super::OptionValue::Shell(cmd) => {
48+
super::shell(cmd, &HashMap::new(), &self.shell_trust).await
49+
}
5150
}
5251
}
5352

@@ -77,7 +76,7 @@ impl<'a> UserInput for CLIBackend<'a> {
7776
let v = match &options[&keys[i]].value {
7877
super::OptionValue::Static(x) => x.to_owned(),
7978
super::OptionValue::Shell(cmd) => {
80-
self.shell(&cmd, &self.shell_trust).await?
79+
super::shell(&cmd, &HashMap::new(), &self.shell_trust).await?
8180
}
8281
};
8382
d.push_str(&v);

src/render/mod.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::args::{Backend, ShellTrust};
22
use crate::config::{Config, Content, Option, OptionValue, Template, VariableDefinition};
33
use async_trait::async_trait;
4-
use std::collections::BTreeMap;
4+
use std::collections::{BTreeMap, HashMap};
55
use std::env;
66
use std::result::Result;
77

@@ -165,11 +165,6 @@ pub trait Resolve {
165165
#[async_trait]
166166
pub trait UserInput: Send + Sync {
167167
async fn prompt(&self, text: &str) -> Result<String, Box<dyn std::error::Error>>;
168-
async fn shell(
169-
&self,
170-
command: &str,
171-
shell_trust: &ShellTrust,
172-
) -> Result<String, Box<dyn std::error::Error>>;
173168
async fn select(
174169
&self,
175170
prompt: &str,
@@ -210,7 +205,7 @@ impl Resolve for VariableDefinition {
210205
VariableDefinition::Env(v) => Ok(env::var(v)?),
211206
VariableDefinition::Static(v) => Ok(v.to_owned()),
212207
VariableDefinition::Prompt(v) => backend_impl.prompt(v).await,
213-
VariableDefinition::Shell(cmd) => backend_impl.shell(cmd, shell_trust).await,
208+
VariableDefinition::Shell(cmd) => shell(cmd, &HashMap::new(), shell_trust).await,
214209
VariableDefinition::Select { text, options } => {
215210
backend_impl.select(text, options).await
216211
}
@@ -225,41 +220,18 @@ impl Resolve for VariableDefinition {
225220

226221
async fn shell(
227222
command: &str,
223+
env: &HashMap<String, String>,
228224
shell_trust: &ShellTrust,
229-
backend: &Backend,
230225
) -> Result<String, Box<dyn std::error::Error>> {
231226
match shell_trust {
232227
ShellTrust::None => return Err(Box::new(crate::error::NoShellTrust::default())),
233-
ShellTrust::Prompt => {
234-
let be = backend.to_input(shell_trust)?;
235-
let mut yesno = BTreeMap::new();
236-
yesno.insert(
237-
"0".to_owned(),
238-
Option {
239-
display: "yes".to_owned(),
240-
value: OptionValue::Static("yes".to_owned()),
241-
},
242-
);
243-
yesno.insert(
244-
"1".to_owned(),
245-
Option {
246-
display: "no".to_owned(),
247-
value: OptionValue::Static("no".to_owned()),
248-
},
249-
);
250-
251-
let sel = be.select(&format!("You are about to run a shell command. The command is:\n{}\nDo you confirm the execution?", command), &yesno).await;
252-
if sel.unwrap_or_default() == "yes" {
253-
} else {
254-
return Err(Box::new(crate::error::UserAbort::default()));
255-
}
256-
}
257228
ShellTrust::Ultimate => {}
258229
}
259230

260231
let output = std::process::Command::new("sh")
261232
.arg("-c")
262233
.arg(command)
234+
.envs(env)
263235
.output()?;
264236
if output.status.code().unwrap() != 0 {
265237
return Err(Box::new(crate::error::Failed::default()));

src/render/ui.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use super::UserInput;
22
use async_trait::async_trait;
33
use cursive::traits::*;
44
use cursive::views::Dialog;
5-
use std::collections::HashSet;
6-
use std::result::Result;
5+
use std::collections::{HashMap, HashSet};
76
use std::ops::Deref;
7+
use std::result::Result;
88

99
pub struct UIBackend<'a> {
1010
shell_trust: &'a super::ShellTrust,
@@ -27,7 +27,9 @@ impl<'a> UserInput for UIBackend<'a> {
2727
let form = fui::form::FormView::new()
2828
.field(fui::fields::Text::new(text))
2929
.on_submit(move |s, x| {
30-
vx.set(Some(x.get(key.deref()).unwrap().as_str().unwrap().to_owned()));
30+
vx.set(Some(
31+
x.get(key.deref()).unwrap().as_str().unwrap().to_owned(),
32+
));
3133
s.quit()
3234
});
3335

@@ -36,14 +38,10 @@ impl<'a> UserInput for UIBackend<'a> {
3638

3739
match v.take() {
3840
Some(x) => Ok(x),
39-
None => Err(Box::new(crate::error::UserAbort::default()))
41+
None => Err(Box::new(crate::error::UserAbort::default())),
4042
}
4143
}
4244

43-
async fn shell(&self, command: &str, shell_trust: &super::ShellTrust) -> Result<String, Box<dyn std::error::Error>> {
44-
super::shell(command, shell_trust, &super::Backend::UI).await
45-
}
46-
4745
async fn select(
4846
&self,
4947
prompt: &str,
@@ -91,7 +89,9 @@ impl<'a> UserInput for UIBackend<'a> {
9189
let selection = &options[&keys[display_vals.iter().position(|x| *x == sel_value).unwrap()]];
9290
match &selection.value {
9391
super::OptionValue::Static(x) => Ok(x.to_owned()),
94-
super::OptionValue::Shell(cmd) => self.shell(cmd, &self.shell_trust).await,
92+
super::OptionValue::Shell(cmd) => {
93+
super::shell(cmd, &HashMap::new(), &self.shell_trust).await
94+
}
9595
}
9696
}
9797

@@ -157,7 +157,9 @@ impl<'a> UserInput for UIBackend<'a> {
157157
data.push(match opt {
158158
super::OptionValue::Static(x) => x.to_owned(),
159159
super::OptionValue::Shell(cmd) => {
160-
self.shell(&cmd, &self.shell_trust).await.unwrap()
160+
super::shell(&cmd, &HashMap::new(), &self.shell_trust)
161+
.await
162+
.unwrap()
161163
}
162164
});
163165
}

0 commit comments

Comments
 (0)