Skip to content

Commit

Permalink
fix(rust): use node identity in project enroll
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbenavides committed Aug 6, 2024
1 parent 6d16b50 commit ac1e168
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use ockam_api::terminal::notification::NotificationHandler;
use ockam_core::{AsyncTryClone, OpenTelemetryContext};
use ockam_node::Context;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use tracing::{debug, instrument, Span};

#[derive(Clone, Debug, Args, Default)]
Expand Down Expand Up @@ -217,7 +218,7 @@ impl NodeConfig {
ctx: &Context,
opts: &CommandGlobalOpts,
node_name: &String,
identity_name: &String,
identity_name: &str,
) -> miette::Result<()> {
debug!("Running node config in foreground mode");
// First, run the `project enroll` commands to prepare the identity and project data
Expand All @@ -226,7 +227,9 @@ impl NodeConfig {
.project_enroll
.run_in_subprocess(
&opts.global_args,
vec![format!("--identity {identity_name}")],
vec![("identity".to_string(), ArgValue::from(identity_name))]
.into_iter()
.collect(),
)?
.wait()
.await
Expand All @@ -237,7 +240,9 @@ impl NodeConfig {
}

// Next, run the 'node create' command
let child = self.node.run_in_subprocess(&opts.global_args, vec![])?;
let child = self
.node
.run_in_subprocess(&opts.global_args, BTreeMap::default())?;

// Wait for the node to be up
let is_up = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::BTreeMap;
use std::process::Stdio;

use async_trait::async_trait;
Expand All @@ -7,6 +8,7 @@ use ockam_node::Context;
use tokio::process::{Child, Command as ProcessCommand};
use tracing::debug;

use crate::run::parser::building_blocks::{as_command_args, ArgKey, ArgValue};
use crate::run::parser::resource::utils::{binary_path, subprocess_stdio};
use crate::{Command, CommandGlobalOpts, GlobalArgs};

Expand All @@ -23,10 +25,10 @@ pub trait Resource<C: ParsedCommand>: Sized + Send + Sync + 'static {
fn run_in_subprocess(
self,
global_args: &GlobalArgs,
mut extra_args: Vec<String>,
extra_args: BTreeMap<ArgKey, ArgValue>,
) -> Result<Child> {
let mut args = self.args();
args.append(&mut extra_args);
args.append(as_command_args(extra_args).as_mut());
if global_args.quiet {
args.push("--quiet".to_string());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,22 @@ EOF
--enrollment-ticket "127.0.0.1:$PYTHON_SERVER_PORT/$ticket_relative_path"
run_success "$OCKAM" message send --timeout 5 hello --to "/node/n1/secure/api/service/echo"
}

@test "nodes - create with config, using the specified identity" {
# Create enrollment ticket that can be reused a few times
export RELAY_NAME=$(random_str)
$OCKAM project ticket --relay "$RELAY_NAME" >"$OCKAM_HOME/enrollment.ticket"

cat <<EOF >"$OCKAM_HOME/config.yaml"
name: n1
identity: i1
relay: $RELAY_NAME
EOF

# The identity will be created and enrolled
run_success "$OCKAM" node create "$OCKAM_HOME/config.yaml" \
--enrollment-ticket "$OCKAM_HOME/enrollment.ticket"

# Use the identity to send a message
$OCKAM message send hi --identity i1 --to "/project/default/service/forward_to_$RELAY_NAME/secure/api/service/echo"
}

0 comments on commit ac1e168

Please sign in to comment.