diff --git a/implementations/rust/ockam/ockam_command/src/node/create/config.rs b/implementations/rust/ockam/ockam_command/src/node/create/config.rs index e83c7f81d0f..a12d367cbd4 100644 --- a/implementations/rust/ockam/ockam_command/src/node/create/config.rs +++ b/implementations/rust/ockam/ockam_command/src/node/create/config.rs @@ -218,9 +218,31 @@ impl NodeConfig { identity_name: &String, ) -> miette::Result<()> { debug!("Running node config"); - for section in self.parse_commands(node_name, identity_name)? { + + // Run `project enroll` first + if let Some(cmd) = self + .project_enroll + .clone() + .into_parsed_commands(Some(identity_name))? + .into_iter() + .next() + { + cmd.run(ctx, opts).await?; + + // Newline before the `node create` command + opts.terminal.write_line("")?; + debug!("project enroll command finished"); + + // Unset the `ENROLLMENT_TICKET` env var, so that the `node create` command + // doesn't try to use it again + std::env::remove_var("ENROLLMENT_TICKET"); + } + + // Run the rest of the commands + for section in self.parse_commands(node_name)? { section.run(ctx, opts).await? } + Ok(()) } @@ -251,6 +273,11 @@ impl NodeConfig { } // Newline before the `node create` command opts.terminal.write_line("")?; + debug!("project enroll command finished"); + + // Unset the `ENROLLMENT_TICKET` env var, so that the `node create` command + // doesn't try to use it again + std::env::remove_var("ENROLLMENT_TICKET"); } // Next, run the 'node create' command @@ -299,17 +326,9 @@ impl NodeConfig { } /// Build commands and return validation errors if any - fn parse_commands( - self, - node_name: &String, - identity_name: &String, - ) -> miette::Result> { + fn parse_commands(self, node_name: &String) -> miette::Result> { let node_name = Some(node_name); - let identity_name = Some(identity_name); Ok(vec![ - self.project_enroll - .into_parsed_commands(identity_name)? - .into(), self.node.into_parsed_commands()?.into(), self.policies.into_parsed_commands()?.into(), self.relays.into_parsed_commands(node_name)?.into(), diff --git a/implementations/rust/ockam/ockam_command/src/run/config.rs b/implementations/rust/ockam/ockam_command/src/run/config.rs index 15952eeba1d..400c59a2093 100644 --- a/implementations/rust/ockam/ockam_command/src/run/config.rs +++ b/implementations/rust/ockam/ockam_command/src/run/config.rs @@ -1,6 +1,6 @@ -use serde::{Deserialize, Serialize}; - use ockam_node::Context; +use serde::{Deserialize, Serialize}; +use tracing::debug; use crate::run::parser::config::ConfigParser; use crate::run::parser::resource::*; @@ -54,18 +54,35 @@ impl Config { /// For more details about the parsing, see the [parser](crate::run::parser) module. /// You can also check examples of valid configuration files in the demo folder of this module. pub async fn run(self, ctx: &Context, opts: &CommandGlobalOpts) -> miette::Result<()> { - for cmd in self.parse_commands()? { + // Pre-enroll commands + let cmds: Vec = vec![ + self.vaults.into_parsed_commands()?.into(), + self.identities.into_parsed_commands()?.into(), + ]; + for cmd in cmds { cmd.run(ctx, opts).await? } - Ok(()) - } - // Build commands and return validation errors - fn parse_commands(self) -> miette::Result> { - Ok(vec![ - self.vaults.into_parsed_commands()?.into(), - self.identities.into_parsed_commands()?.into(), - self.project_enroll.into_parsed_commands(None)?.into(), + // Project enroll + if let Some(cmd) = self + .project_enroll + .into_parsed_commands(None)? + .into_iter() + .next() + { + cmd.run(ctx, opts).await?; + + // Newline before the next command + opts.terminal.write_line("")?; + debug!("project enroll command finished"); + + // Unset the `ENROLLMENT_TICKET` env var, so that the `node create` command + // doesn't try to use it again + std::env::remove_var("ENROLLMENT_TICKET"); + } + + // Post-enroll commands + let cmds: Vec = vec![ self.nodes.into_parsed_commands()?.into(), self.relays.into_parsed_commands(None)?.into(), self.policies.into_parsed_commands()?.into(), @@ -73,7 +90,12 @@ impl Config { self.tcp_inlets.into_parsed_commands(None)?.into(), self.kafka_inlet.into_parsed_commands(None)?.into(), self.kafka_outlet.into_parsed_commands(None)?.into(), - ]) + ]; + for cmd in cmds { + cmd.run(ctx, opts).await? + } + + Ok(()) } pub async fn parse_and_run(