Skip to content

Commit

Permalink
fix: don't prompt to write files to project dir when using `--allow-w…
Browse files Browse the repository at this point in the history
…rite` flag (#981)

* pass `--allow-write` config through test runner

* pass `--allow-read` config through test runner

* remove errant todo

* reorg lines to get nice spacing - important stuff

* add `--allow-run` and `--allow-env` options
  • Loading branch information
MicaiahReid authored Apr 27, 2023
1 parent f9b5595 commit d5c654e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
17 changes: 14 additions & 3 deletions components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,18 @@ struct Run {
/// Allow access to wallets
#[clap(long = "allow-wallets")]
pub allow_wallets: bool,
/// Allow write access to disk
/// Allow write access to project directory
#[clap(long = "allow-write")]
pub allow_disk_write: bool,
/// Allow read access to disk
/// Allow read access to project directory
#[clap(long = "allow-read")]
#[allow(dead_code)]
pub allow_disk_read: bool,
/// Allows running a specified list of subprocesses. Use the flag multiple times to allow multiple subprocesses
#[clap(long = "allow-run")]
pub allow_run: Option<Vec<String>>,
/// Allows access to a specified list of environment variables. Use the flag multiple times to allow access to multiple variables
#[clap(long = "allow-env")]
pub allow_env: Option<Vec<String>>,
/// If specified, use this deployment file
#[clap(long = "deployment-plan-path", short = 'p')]
pub deployment_plan_path: Option<String>,
Expand Down Expand Up @@ -1222,6 +1227,9 @@ pub fn main() {
cmd.watch,
true,
false,
false,
None,
None,
&manifest,
cache,
deployment_plan_path,
Expand Down Expand Up @@ -1266,7 +1274,10 @@ pub fn main() {
false,
false,
cmd.allow_wallets,
cmd.allow_disk_read,
cmd.allow_disk_write,
cmd.allow_run,
cmd.allow_env,
&manifest,
cache,
cmd.deployment_plan_path,
Expand Down
22 changes: 17 additions & 5 deletions components/clarinet-cli/src/runner/deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub async fn do_run_scripts(
display_costs_report: bool,
watch: bool,
allow_wallets: bool,
_allow_disk_write: bool,
allow_disk_read: bool,
allow_disk_write: bool,
allow_run: Option<Vec<String>>,
allow_env: Option<Vec<String>>,
manifest: &ProjectManifest,
cache: DeploymentCache,
_deployment_plan_path: Option<String>,
Expand Down Expand Up @@ -95,6 +98,15 @@ pub async fn do_run_scripts(
} else {
None
};

let allow_read_path = match allow_disk_read {
true => Some(vec![cwd.clone()]),
false => None,
};
let allow_write_path = match allow_disk_write {
true => Some(vec![cwd.clone()]),
false => None,
};
let test_flags = TestFlags {
ignore: vec![], // todo(lgalabru)
trace_ops: true, // todo(lgalabru)
Expand All @@ -112,7 +124,7 @@ pub async fn do_run_scripts(
argv: vec![],
subcommand: DenoSubcommand::Test(test_flags.clone()),
allow_all: false,
allow_env: None,
allow_env,
allow_hrtime: false,
allow_net: if allow_net {
Some(vec!["deno.land".into()])
Expand All @@ -123,9 +135,9 @@ pub async fn do_run_scripts(
watch: watched,
import_map_path: import_map,
allow_ffi: None,
allow_read: None, // todo(lgalabru)
allow_run: None, // todo(lgalabru)
allow_write: None, // todo(lgalabru)
allow_read: allow_read_path,
allow_write: allow_write_path,
allow_run,
cache_blocklist: vec![], // todo(lgalabru)
cached_only: false, // todo(lgalabru)
ignore: vec![], // todo(lgalabru)
Expand Down
6 changes: 6 additions & 0 deletions components/clarinet-cli/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ pub fn run_scripts(
include_costs_report: bool,
watch: bool,
allow_wallets: bool,
allow_disk_read: bool,
allow_disk_write: bool,
allow_run: Option<Vec<String>>,
allow_env: Option<Vec<String>>,
manifest: &ProjectManifest,
cache: DeploymentCache,
deployment_plan_path: Option<String>,
Expand All @@ -125,7 +128,10 @@ pub fn run_scripts(
include_costs_report,
watch,
allow_wallets,
allow_disk_read,
allow_disk_write,
allow_run,
allow_env,
manifest,
cache,
deployment_plan_path,
Expand Down

0 comments on commit d5c654e

Please sign in to comment.