From a833eb5404f406ee241680640428021f0484490e Mon Sep 17 00:00:00 2001 From: Jetttech Date: Thu, 25 Jan 2024 16:15:04 -0600 Subject: [PATCH 1/2] read from config --- .gitignore | 1 + src/types.rs | 52 ++++++++++++++++++++++++++++++++++++++------ tests/integration.rs | 1 + 3 files changed, 47 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 3e85dfe..0adf251 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,6 @@ target/ # Added by cargo +/config /target .cargo \ No newline at end of file diff --git a/src/types.rs b/src/types.rs index 9126507..9098de3 100644 --- a/src/types.rs +++ b/src/types.rs @@ -1,3 +1,4 @@ +use std::process::Command; use std::{fmt, str::FromStr, time::Duration}; use anyhow::{anyhow, Result}; @@ -205,13 +206,50 @@ pub struct HappAndHost { impl HappAndHost { pub async fn init(happ_id: &str, ws: &mut Ws) -> Result { - // AgentKey used for installation of hha is a HoloHash created from Holoport owner's public key. - // This public key encoded in base36 is also holoport's id in `https://.holohost.net` - let (_, pub_key) = ws.get_cell(ws.core_app_id.clone(), "core-app").await?; - - let a = pub_key.get_raw_32(); - - let holoport_id = base36::encode(a); + let holoport_id = match std::env::var("TEST") { + Ok(is_test) => { + // Test: + // In test env, we can assume the agent pubkey will equal the host id + let (_, pub_key) = ws.get_cell(ws.core_app_id.clone(), "core-app").await?; + let id = pub_key.get_raw_32(); + base36::encode(id) + } + Err(_) => { + // Production: + // In real hpos env, we will have the hpos-config file present and need to rely on it as the source of truth + let device_seed_pw = std::env::var("DEVICE_SEED_PASSWORD") + .expect("Failed to read DEVICE_SEED_PASSWORD."); + + // Fetch the holoport id from the hpos-init config file + // NB: In non-develop envs, the AgentKey used for installation of hha is a HoloHash created from Holoport owner's public key. + // This public key encoded in base36 is also the host's holoport id in `https://.holohost.net` and is stored + // in the hpos-init config file. + let mut config_id = Command::new("hpos-config-into-base36-id") + .arg("--config-path") + .arg("/run/hpos-init/hp-*.json") + .arg("--password") + .arg(device_seed_pw) + .stdout(std::process::Stdio::piped()) + .spawn() + .expect("Failed to open hp- config file."); + + let mut std_output = config_id + .stdout + .take() + .expect("Failed to read output from `hpos-config-into-base36-id` command"); + + let r = config_id.wait_with_output().expect("Failed to read stdout"); + + let holoport_id = String::from_utf8_lossy(&r.stdout); + + println!( + " >>>>>>>>>>>>> holoport_id stout : holoport_id >>>>>>>>>>>>> : {:?} ", + holoport_id + ); + + holoport_id.to_string() + } + }; Ok(HappAndHost { happ_id: ActionHashB64::from_b64_str(happ_id)?, diff --git a/tests/integration.rs b/tests/integration.rs index 754fd6a..3f61456 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -17,6 +17,7 @@ use utils::{to_cell, HappInput}; #[tokio::test] async fn install_components() { env_logger::init(); + std::env::set_var("TEST", "true"); let mut test = Test::init().await; From 7f26a959b395969f30bce852e005e43bb7dcb0f8 Mon Sep 17 00:00:00 2001 From: Jetttech Date: Thu, 25 Jan 2024 16:23:08 -0600 Subject: [PATCH 2/2] edit comment --- src/types.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/types.rs b/src/types.rs index 9098de3..3b49c8c 100644 --- a/src/types.rs +++ b/src/types.rs @@ -209,21 +209,22 @@ impl HappAndHost { let holoport_id = match std::env::var("TEST") { Ok(is_test) => { // Test: - // In test env, we can assume the agent pubkey will equal the host id + // In test env, we assume the agent pubkey equals the host id (with base36 encoding) let (_, pub_key) = ws.get_cell(ws.core_app_id.clone(), "core-app").await?; let id = pub_key.get_raw_32(); base36::encode(id) } Err(_) => { // Production: - // In real hpos env, we will have the hpos-config file present and need to rely on it as the source of truth + // In real hpos env, we have the hpos-config file present and should rely on it as the source of truth. + // NB: In develop envs, the host agent pubkey will not equal the host id (with base36 encoding). + // In non-develop envs, the host AgentKey used for installation of hha is a HoloHash created from Holoport owner's public key. + // This public key encoded in base36 is also the host's holoport id in `https://.holohost.net` and is stored + // in the hpos-init config file. let device_seed_pw = std::env::var("DEVICE_SEED_PASSWORD") .expect("Failed to read DEVICE_SEED_PASSWORD."); // Fetch the holoport id from the hpos-init config file - // NB: In non-develop envs, the AgentKey used for installation of hha is a HoloHash created from Holoport owner's public key. - // This public key encoded in base36 is also the host's holoport id in `https://.holohost.net` and is stored - // in the hpos-init config file. let mut config_id = Command::new("hpos-config-into-base36-id") .arg("--config-path") .arg("/run/hpos-init/hp-*.json") @@ -233,14 +234,16 @@ impl HappAndHost { .spawn() .expect("Failed to open hp- config file."); - let mut std_output = config_id + config_id .stdout .take() - .expect("Failed to read output from `hpos-config-into-base36-id` command"); + .expect("Failed to read stdout from `hpos-config-into-base36-id` command"); - let r = config_id.wait_with_output().expect("Failed to read stdout"); + let output = config_id + .wait_with_output() + .expect("Failed to read output from `hpos-config-into-base36-id` command"); - let holoport_id = String::from_utf8_lossy(&r.stdout); + let holoport_id = String::from_utf8_lossy(&output.stdout); println!( " >>>>>>>>>>>>> holoport_id stout : holoport_id >>>>>>>>>>>>> : {:?} ",