Skip to content

Commit

Permalink
fix(cli): Do not supply auth args to ic-admin get commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa-tomic authored and Luka-DFINITY committed Mar 17, 2023
1 parent 6122c80 commit c4a1705
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions rs/cli/src/ic_admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl Cli {
]
.concat()
.as_slice(),
true,
)
};

Expand All @@ -200,14 +201,15 @@ impl Cli {
exec(self, cmd, opts, false)
}

fn _run_ic_admin_with_args(&self, ic_admin_args: &[String]) -> anyhow::Result<()> {
fn _run_ic_admin_with_args(&self, ic_admin_args: &[String], with_auth: bool) -> anyhow::Result<()> {
let ic_admin_path = self.ic_admin.clone().unwrap_or_else(|| "ic-admin".to_string());
let mut cmd = Command::new(ic_admin_path);
let root_options = [
self.neuron.as_ref().map(|n| n.auth.as_arg_vec()).unwrap_or_default(),
vec!["--nns-url".to_string(), self.nns_url.to_string()],
]
.concat();
let auth_options = if with_auth {
self.neuron.as_ref().map(|n| n.auth.as_arg_vec()).unwrap_or_default()
} else {
vec![]
};
let root_options = [auth_options, vec!["--nns-url".to_string(), self.nns_url.to_string()]].concat();
let cmd = cmd.args([&root_options, ic_admin_args].concat());

self.print_ic_admin_command_line(cmd);
Expand All @@ -230,9 +232,9 @@ impl Cli {
}
}

pub(crate) fn run(&self, command: &str, args: &[String]) -> anyhow::Result<()> {
pub(crate) fn run(&self, command: &str, args: &[String], with_auth: bool) -> anyhow::Result<()> {
let ic_admin_args = [&[command.to_string()], args].concat();
self._run_ic_admin_with_args(&ic_admin_args)
self._run_ic_admin_with_args(&ic_admin_args, with_auth)
}

/// Run ic-admin and parse sub-commands that it lists with "--help",
Expand Down Expand Up @@ -292,7 +294,7 @@ impl Cli {
args_with_get_prefix
};

self.run(&args[0], &args.iter().skip(1).cloned().collect::<Vec<_>>())
self.run(&args[0], &args.iter().skip(1).cloned().collect::<Vec<_>>(), false)
}

/// Run an `ic-admin propose-to-*` command directly
Expand Down Expand Up @@ -835,7 +837,7 @@ oSMDIQBa2NLmSmaqjDXej4rrJEuEhKIz7/pGXpxztViWhB+X9Q==
.concat()
.to_vec();
let out = with_ic_admin(Default::default(), async {
cli.run(&cmd.get_command_name(), &vector)
cli.run(&cmd.get_command_name(), &vector, true)
.map_err(|e| anyhow::anyhow!(e))
})
.await;
Expand Down

0 comments on commit c4a1705

Please sign in to comment.