Skip to content

Commit

Permalink
feat(admin): add agent info call (#106)
Browse files Browse the repository at this point in the history
* Add agent info

* Fixed build

* build: add fixt dep

* fix formatting

* fix test & bump deps

* restore cargo toml

---------

Co-authored-by: Jost Schulte <[email protected]>
  • Loading branch information
guillemcordoba and jost-s authored Aug 30, 2024
1 parent f9e3a6c commit ef96641
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ holochain_nonce = "0.4.0-dev.6"
holochain_zome_types = { workspace = true }

lair_keystore_api = { version = "0.4.5", optional = true }
kitsune_p2p_types = "0.4.0-dev.12"

tokio = { version = "1.36", features = ["rt"] }

[dev-dependencies]
arbitrary = "1.2"
fixt = "0.4.0-dev.3"
holochain = { version = "0.4.0-dev.20", features = ["test_utils"] }
rand = "0.8"
kitsune_p2p_types = "0.4.0-dev.12"

[features]
default = ["lair_signing"]
Expand Down
25 changes: 25 additions & 0 deletions src/admin_websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use holochain_zome_types::{
capability::GrantedFunctions,
prelude::{DnaDef, GrantZomeCallCapabilityPayload, Record},
};
use kitsune_p2p_types::agent_info::AgentInfoSigned;
use serde::{Deserialize, Serialize};
use std::{net::ToSocketAddrs, sync::Arc};
use tokio::task::JoinHandle;
Expand Down Expand Up @@ -319,6 +320,30 @@ impl AdminWebsocket {
}
}

pub async fn agent_info(
&self,
cell_id: Option<CellId>,
) -> ConductorApiResult<Vec<AgentInfoSigned>> {
let msg = AdminRequest::AgentInfo { cell_id };
let response = self.send(msg).await?;
match response {
AdminResponse::AgentInfo(agent_info) => Ok(agent_info),
_ => unreachable!("Unexpected response {:?}", response),
}
}

pub async fn add_agent_info(
&self,
agent_infos: Vec<AgentInfoSigned>,
) -> ConductorApiResult<()> {
let msg = AdminRequest::AddAgentInfo { agent_infos };
let response = self.send(msg).await?;
match response {
AdminResponse::AgentInfoAdded => Ok(()),
_ => unreachable!("Unexpected response {:?}", response),
}
}

pub async fn authorize_signing_credentials(
&self,
request: AuthorizeSigningCredentialsPayload,
Expand Down
39 changes: 39 additions & 0 deletions tests/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use holochain_client::{
use holochain_conductor_api::{CellInfo, StorageBlob};
use holochain_types::websocket::AllowedOrigins;
use holochain_zome_types::prelude::ExternIO;
use kitsune_p2p_types::fixt::AgentInfoSignedFixturator;
use std::collections::BTreeSet;
use std::net::Ipv4Addr;
use std::{collections::HashMap, path::PathBuf};
Expand Down Expand Up @@ -257,3 +258,41 @@ async fn revoke_agent_key() {
};
assert!(matches!(&response[0], (cell, error) if *cell == cell_id && error.contains("invalid")));
}

#[tokio::test(flavor = "multi_thread")]
async fn agent_info() {
let conductor = SweetConductor::from_standard_config().await;
let admin_port = conductor.get_arbitrary_admin_websocket_port().unwrap();
let admin_ws = AdminWebsocket::connect(format!("127.0.0.1:{}", admin_port))
.await
.unwrap();
let app_id: InstalledAppId = "test-app".into();
let agent_key = admin_ws.generate_agent_pub_key().await.unwrap();
admin_ws
.install_app(InstallAppPayload {
agent_key: Some(agent_key.clone()),
installed_app_id: Some(app_id.clone()),
existing_cells: HashMap::new(),
membrane_proofs: Some(HashMap::new()),
network_seed: None,
source: AppBundleSource::Path(PathBuf::from("./fixture/test.happ")),
ignore_genesis_failure: false,
})
.await
.unwrap();
admin_ws.enable_app(app_id.clone()).await.unwrap();

let agent_infos = admin_ws.agent_info(None).await.unwrap();
// 2 agent infos expected, 1 app agent and 1 DPKI agent.
assert_eq!(agent_infos.len(), 2);

let other_agent = fixt::fixt!(AgentInfoSigned);
admin_ws
.add_agent_info(vec![other_agent.clone()])
.await
.unwrap();

let agent_infos = admin_ws.agent_info(None).await.unwrap();
assert_eq!(agent_infos.len(), 3);
assert!(agent_infos.contains(&other_agent));
}

0 comments on commit ef96641

Please sign in to comment.