Skip to content

Commit

Permalink
Merge pull request #154 from Holo-Host/crates/06-11
Browse files Browse the repository at this point in the history
split up into crates
  • Loading branch information
zo-el committed Aug 1, 2023
2 parents 2e853bd + b2cdde4 commit d81f2eb
Show file tree
Hide file tree
Showing 34 changed files with 1,403 additions and 1,056 deletions.
1,424 changes: 593 additions & 831 deletions Cargo.lock

Large diffs are not rendered by default.

64 changes: 11 additions & 53 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,56 +1,14 @@
[package]
name = "configure-holochain"
version = "0.4.0"
authors = ["Oleksii Filonenko <[email protected]>", "zo-el <[email protected]>"]
edition = "2021"
[workspace]

[dependencies]
again = "0.1"
anyhow = "1.0"
futures = "0.3.24"
isahc = "1.7.2"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9.11"
serde_json = "1.0.60"
structopt = "0.3"
tempfile = "3.1"
tokio = { version = "1", features = ["full"] }
tracing = { version = "0.1", features = ["attributes"] }
tracing-futures = "0.2"
tracing-subscriber = "0.2"
rmp-serde = "1.1.0"
url = "2.2"
observability = "0.1.3"
base64 = "0.13.0"
reqwest = { version = "0.11", features = ["json"]}
spinning_top = "0.2.4"
holochain_conductor_api = "0.2.0"
holochain_types = "0.2.0"
holochain_websocket = "0.2.0"
holochain_zome_types = "0.2.0"
mr_bundle = "0.2.0"
lazy_static = "1"
ed25519-dalek = { version = "1.0.1", features = ["serde"] }
thiserror = "1.0"
members = [
"crates/configure-holochain",
"crates/hpos_connect_hc",
"crates/holo_happ_manager",
"crates/test_utils"
]

[dependencies.hpos-config-core]
git = "https://github.com/Holo-Host/hpos-config"
rev = "bfaced6044ae570bf20d4528fa9aaafcc43ddeec"
[profile.dev]
opt-level = "z"

[dependencies.hpos-config-seed-bundle-explorer]
git = "https://github.com/Holo-Host/hpos-config"
rev = "bfaced6044ae570bf20d4528fa9aaafcc43ddeec"

[dev-dependencies.cargo-husky]
version = "1"
features = ["run-cargo-fmt", "run-cargo-clippy"]

[target.'cfg(unix)'.dependencies]
nix = "0.26.2"

[dev-dependencies]
lair_keystore_api = "0.2.3"
snafu = "0.7.1"
chrono = "0.4.22"
test-case = "2.2.2"
serial_test = { version = "0.9.0", features = ["async"] }
[profile.release]
opt-level = "z"
30 changes: 30 additions & 0 deletions crates/configure-holochain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "configure-holochain"
version = "0.5.0"
authors = ["Oleksii Filonenko <[email protected]>", "zo-el <[email protected]>"]
edition = "2021"

[dependencies]
anyhow = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_yaml = "0.9.11"
tokio = { version = "1", features = ["full"] }
tracing = { version = "0.1", features = ["attributes"] }
tracing-subscriber = "0.2"
url = "2.2"
# observability = "0.1.3"
holochain_types = "0.2.0"
thiserror = "1.0"
hpos_hc_connect = { version = "0.1.0", path = "../hpos_connect_hc" }

[dependencies.hpos-config-core]
git = "https://github.com/Holo-Host/hpos-config"
rev = "bfaced6044ae570bf20d4528fa9aaafcc43ddeec"

[target.'cfg(unix)'.dependencies]
nix = "0.26.2"

[dev-dependencies]
test-case = "2.2.2"
serial_test = { version = "0.9.0", features = ["async"] }
test_utils = { path = "../test_utils" }
File renamed without changes.
36 changes: 17 additions & 19 deletions src/lib.rs → crates/configure-holochain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
mod config;
pub use config::{Config, Happ, HappsFile, MembraneProofFile, ProofPayload};
pub mod agent;
mod websocket;
use agent::Agent;
use anyhow::{Context, Result};
pub use hpos_hc_connect::{
holo_config::{Config, Happ, HappsFile, MembraneProofFile, ProofPayload},
utils::{download_file, extract_zip},
};
use hpos_hc_connect::{hpos_agent::Agent, hpos_membrane_proof};
pub use hpos_hc_connect::{AdminWebsocket, AppWebsocket};
use std::sync::Arc;
use tracing::{debug, info, instrument, warn};
pub use websocket::{AdminWebsocket, AppWebsocket};
pub mod membrane_proof;
mod utils;

#[instrument(err, skip(config))]
pub async fn run(config: Config) -> Result<()> {
debug!("Starting...");
debug!("Starting configure holochain...");
let happ_file = HappsFile::load_happ_file(&config.happs_file_path)
.context("failed to load hApps YAML config")?;
install_happs(&happ_file, &config).await?;
Expand Down Expand Up @@ -53,11 +52,9 @@ pub async fn install_happs(happ_file: &HappsFile, config: &Config) -> Result<()>
info!("App {} already installed, just downloading UI", &happ.id());
} else {
info!("Installing app {}", &happ.id());
let mem_proof_vec = crate::membrane_proof::create_vec_for_happ(
&happ.id(),
agent.membrane_proof.clone(),
)
.await?;
let mem_proof_vec =
hpos_membrane_proof::create_vec_for_happ(happ, agent.membrane_proof.clone())
.await?;

if let Err(err) = admin_websocket
.install_and_activate_happ(happ, mem_proof_vec, agent.clone())
Expand All @@ -82,7 +79,7 @@ pub async fn install_happs(happ_file: &HappsFile, config: &Config) -> Result<()>
.await
.context("failed to connect to holochain's app interface")?;

let happs_to_keep: utils::HappIds = happs_to_install.iter().map(|happ| happ.id()).collect();
let happs_to_keep: Vec<String> = happs_to_install.iter().map(|happ| happ.id()).collect();

for app in &*active_happs {
if let Some(app_info) = app_websocket.get_app_info(app.to_string()).await {
Expand All @@ -109,14 +106,15 @@ async fn install_ui(happ: &Happ, config: &Config) -> Result<()> {
debug!("ui_url == None, skipping UI installation for {}", happ.id());
return Ok(());
}
utils::download_file(happ.ui_url.as_ref().unwrap())
download_file(happ.ui_url.as_ref().unwrap())
.await
.context("failed to download UI archive")?
}
};

let unpack_path = config.ui_store_folder.join(happ.ui_name());
utils::extract_zip(&source_path, &unpack_path).context("failed to extract UI archive")?;
debug!("installed UI: {}", happ.id());
if let Some(ui_home) = config.ui_store_folder.clone() {
let unpack_path = ui_home.join(happ.ui_name());
extract_zip(&source_path, &unpack_path).context("failed to extract UI archive")?;
debug!("installed UI: {}", happ.id());
}
Ok(())
}
File renamed without changes.
23 changes: 23 additions & 0 deletions crates/configure-holochain/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Returns true if app should be kept active in holochain
pub fn keep_app_active(installed_app_id: &str, happs_to_keep: Vec<String>) -> bool {
happs_to_keep.contains(&installed_app_id.to_string()) || installed_app_id.contains("uhCkk")
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn verify_keep_app_active() {
let happs_to_keep = vec!["elemental-chat:2".to_string(), "hha:1".to_string()];
let app_1 = "elemental-chat:1";
let app_2 = "elemental-chat:2";
let app_3 = "uhCkkcF0X1dpwHFeIPI6-7rzM6ma9IgyiqD-othxgENSkL1So1Slt::servicelogger";
let app_4 = "other-app";

assert_eq!(keep_app_active(app_1, happs_to_keep.clone()), false);
assert_eq!(keep_app_active(app_2, happs_to_keep.clone()), true); // because it is in config
assert_eq!(keep_app_active(app_3, happs_to_keep.clone()), true); // because it is hosted
assert_eq!(keep_app_active(app_4, happs_to_keep.clone()), false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{
'bundle_url': 'https://github.com/Holo-Host/dummy-dna/releases/download/v0.6.1/test-skip-proof.happ',
'ui_url': 'https://github.com/holochain/elemental-chat-ui/releases/download/v0.0.1-alpha40/elemental-chat-ui.zip',
"agent_bundle_override" : "../test_utils/config/hp-primary-bzywj.json",
},
],
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
mod setup;
use anyhow::Context;
use configure_holochain;
use configure_holochain::agent::get_hpos_config;
use configure_holochain::membrane_proof::delete_mem_proof_file;
use hpos_config_core::Config;
use hpos_hc_connect::hpos_agent::get_hpos_config;
use hpos_hc_connect::hpos_membrane_proof::delete_mem_proof_file;
use serial_test::serial;
use std::env::set_var;
use std::path::PathBuf;
Expand Down Expand Up @@ -32,7 +31,7 @@ use test_case::test_case;
/// MEM_PROOF_SERVER_URL - HBS server url
///
/// Note about MEM_PROOF_SERVER_URL:
/// this integration test is downlading memproof from an external server. It is not possible to
/// this integration test is downloading memproof from an external server. It is not possible to
/// mock this interaction, because memproof server signs payload with its own private key
/// So this test will pass only as long as version of core-app in config/config.yaml
/// will match settings on HBS server. If you start getting an error of a type
Expand All @@ -55,10 +54,13 @@ use test_case::test_case;

async fn run_configure_holochain(f_r_a_k: &str, r_o_m_p: &str) {
// Point HPOS_CONFIG_PATH to test config file
set_var("HPOS_CONFIG_PATH", "./tests/config/hp-primary-bzywj.json");
set_var(
"HPOS_CONFIG_PATH",
"../test_utils/config/hp-primary-bzywj.json",
);

let tmp_dir = setup::holochain::create_tmp_dir();
let log_dir = setup::holochain::create_log_dir();
let tmp_dir = test_utils::holochain::create_tmp_dir();
let log_dir = test_utils::holochain::create_log_dir();

// Set HOST_PUBKEY_PATH in a writable temp location
set_var("HOST_PUBKEY_PATH", &tmp_dir.clone().join("agent.key"));
Expand Down Expand Up @@ -89,17 +91,18 @@ async fn run_configure_holochain(f_r_a_k: &str, r_o_m_p: &str) {
// spin up lair
println!("Starting lair-keystore");
let (_lair, lair_config) =
setup::lair::spawn(&tmp_dir, &log_dir, &device_bundle, None).unwrap();
test_utils::lair::spawn(&tmp_dir, &log_dir, &device_bundle, None).unwrap();

println!("Spinning up holochain");
let _holochain = setup::holochain::spawn_holochain(&tmp_dir, &log_dir, lair_config);
let _holochain = test_utils::holochain::spawn_holochain(&tmp_dir, &log_dir, lair_config);

let happs_file_path: PathBuf = "./tests/config/config.yaml".into();
let config = configure_holochain::Config {
let happs_file_path: PathBuf = "./tests/config.yaml".into();
let config = hpos_hc_connect::holo_config::Config {
admin_port: 4444,
happ_port: 42233,
ui_store_folder: "./tmp".into(),
ui_store_folder: Some("./tmp".into()),
happs_file_path: happs_file_path.clone(),
lair_url: None,
};
println!("Test running with config: {:?}", &config);

Expand Down
30 changes: 30 additions & 0 deletions crates/holo_happ_manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "holo_happ_manager"
version = "0.1.0"
authors = ["zo-el <[email protected]>"]
edition = "2021"

[dependencies]
anyhow = "1.0"
hpos_hc_connect = { version = "0.1.0", path = "../hpos_connect_hc" }
holochain_conductor_api = "0.2.0"
holochain_types = "0.2.0"
holochain_keystore = "0.2.0"
getrandom = "0.2.10"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.96"
sodoken = "0.0.9"
rmp-serde = "1.1.1"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
tokio = "1.28.2"
url2 = "0.0.6"

[dev-dependencies]
configure-holochain = { version = "0.5.0", path = "../configure-holochain"}
serial_test = { version = "0.9.0", features = ["async"] }
test_utils = { version = "0.1.0", path = "../test_utils" }

[dev-dependencies.hpos-config-core]
git = "https://github.com/Holo-Host/hpos-config"
rev = "bfaced6044ae570bf20d4528fa9aaafcc43ddeec"
37 changes: 37 additions & 0 deletions crates/holo_happ_manager/src/get_my_apps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use super::hha::HHAAgent;
use anyhow::{anyhow, Result};
use holochain_conductor_api::AppResponse;
use holochain_types::prelude::ActionHashB64;
use holochain_types::prelude::{zome_io::ExternIO, FunctionName, ZomeName};
use hpos_hc_connect::holo_config::{Config, Happ};
use serde::Deserialize;
use tracing::debug;

#[derive(Deserialize, Debug, Clone)]
pub struct PresentedHappBundle {
pub id: ActionHashB64,
pub bundle_url: String,
}

pub async fn published(core_happ: &Happ, config: &Config) -> Result<Vec<PresentedHappBundle>> {
let mut agent = HHAAgent::spawn(core_happ, config).await?;
let response = agent
.zome_call(
ZomeName::from("hha"),
FunctionName::from("get_my_happs"),
ExternIO::encode(())?,
)
.await?;

match response {
// This is the happs list that is returned from the hha DNA
// https://github.com/Holo-Host/holo-hosting-app-rsm/blob/develop/zomes/hha/src/lib.rs#L54
// return Vec of happ_list.happ_id
AppResponse::ZomeCalled(r) => {
let happ_bundles: Vec<PresentedHappBundle> = rmp_serde::from_slice(r.as_bytes())?;
debug!("got happ bundles {:?}", happ_bundles);
Ok(happ_bundles)
}
_ => Err(anyhow!("unexpected response: {:?}", response)),
}
}
Loading

0 comments on commit d81f2eb

Please sign in to comment.