Skip to content

Commit

Permalink
add enable happ for host (#176)
Browse files Browse the repository at this point in the history
Co-authored-by: Joel Ulahanna <joelulahanna@gmail.com>
  • Loading branch information
JettTech and zo-el committed Jan 22, 2024
1 parent 564b585 commit c0575a5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
37 changes: 37 additions & 0 deletions crates/core_app_cli/src/actions/enable_happ_for_host.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use anyhow::Result;
use holochain_types::prelude::{ActionHash, ActionHashB64};
use holochain_types::prelude::{ExternIO, FunctionName, ZomeName};
use hpos_hc_connect::{hha_types::HappAndHost, CoreAppAgent, CoreAppRoleName};

pub async fn get(happ_id: String, host_id: String) -> Result<()> {
let mut agent = CoreAppAgent::connect().await?;

let holo_hash = ActionHashB64::from_b64_str(&happ_id.clone())
.expect("Failed to serialize string into ActionHashB4");

let payload = HappAndHost {
happ_id: holo_hash,
holoport_id: host_id.clone(),
};

let result = agent
.zome_call(
CoreAppRoleName::HHA,
ZomeName::from("hha"),
FunctionName::from("enable_happ"),
ExternIO::encode(payload)?,
)
.await;

if result.is_ok() {
println!("===================");
println!("Enabled Happ ID {} for Host {}: ", happ_id, host_id);
println!("Fetching happ preference hash...");

crate::get_happ_pref_for_host::get(happ_id, host_id).await?;

println!("===================");
}

Ok(())
}
5 changes: 4 additions & 1 deletion crates/core_app_cli/src/actions/get_happ_pref_for_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub async fn get(happ_id: String, host_id: String) -> Result<()> {

if let Some(d) = found {
if let Some(p) = d.preferences_hash {
println!("{:#?}", p)
// Please do not change this print and if you do see that the nightly tests that depend on this print are updated as well
println!("===================");
println!("Happ Preference Hash: {:#?}", p);
println!("===================");
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/core_app_cli/src/actions/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod enable_happ_for_host;
pub mod get_happ_hosts;
pub mod get_happ_pref_for_host;
pub mod get_specific_happ_prefs;
Expand Down
14 changes: 10 additions & 4 deletions crates/core_app_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ pub enum Opt {
/// List all hosts for a happ by `happ_id``
#[structopt(name = "hosts")]
Hosts { happ_id: String },
/// Fetch the happ preferences associated with a `pref_hash`
/// Enable hosting for a specific happ
#[structopt(name = "enable-happ")]
EnableHappForHost { happ_id: String, host_id: String },
/// Fetch the happ preferences associated with a happ preference hash
#[structopt(name = "prefs")]
GetPreferenceByHash { pref_hash: String },
/// Fetch the happ preferences for a specific host for a specific happ
/// Fetch the happ preference hash for a specific host for a specific happ
#[structopt(name = "host-prefs")]
GetHappPrefForHost { happ_id: String, host_id: String },
GetHappPrefHashForHost { happ_id: String, host_id: String },
/// Set new happ preferences
#[structopt(name = "set-prefs")]
SetHappPreferences {
Expand Down Expand Up @@ -59,7 +62,10 @@ impl Opt {
Opt::GetPreferenceByHash { pref_hash } => {
core_app_cli::get_specific_happ_prefs::get(pref_hash).await?
}
Opt::GetHappPrefForHost { happ_id, host_id } => {
Opt::EnableHappForHost { happ_id, host_id } => {
core_app_cli::enable_happ_for_host::get(happ_id, host_id).await?
}
Opt::GetHappPrefHashForHost { happ_id, host_id } => {
core_app_cli::get_happ_pref_for_host::get(happ_id, host_id).await?
}
Opt::SetHappPreferences {
Expand Down

0 comments on commit c0575a5

Please sign in to comment.