Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/read host id from config #11

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ target/

# Added by cargo

/config
/target
.cargo
55 changes: 48 additions & 7 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::process::Command;
use std::{fmt, str::FromStr, time::Duration};

use anyhow::{anyhow, Result};
Expand Down Expand Up @@ -205,13 +206,53 @@ pub struct HappAndHost {

impl HappAndHost {
pub async fn init(happ_id: &str, ws: &mut Ws) -> Result<Self> {
// 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://<holoport_id>.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 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 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://<holoport_id>.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
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.");

config_id
.stdout
.take()
.expect("Failed to read stdout from `hpos-config-into-base36-id` command");

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(&output.stdout);

println!(
" >>>>>>>>>>>>> holoport_id stout : holoport_id >>>>>>>>>>>>> : {:?} ",
holoport_id
);

holoport_id.to_string()
}
};

Ok(HappAndHost {
happ_id: ActionHashB64::from_b64_str(happ_id)?,
Expand Down
1 change: 1 addition & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading