Skip to content

Commit

Permalink
Merge pull request #35 from wasmCloud/fix/invocation
Browse files Browse the repository at this point in the history
fix invocation.host_id and claims subject fields; bump crate to 0.4.0
  • Loading branch information
stevelr authored Sep 16, 2021
2 parents 68231c3 + b55e389 commit 69d2e22
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion rpc-rs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasmbus-rpc"
version = "0.3.12"
version = "0.4.0"
edition = "2018"
authors = [ "wasmcloud Team" ]
license = "Apache-2.0"
Expand Down
8 changes: 6 additions & 2 deletions rpc-rs/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ impl HostBridge {
wascap::prelude::KeyPair::from_seed(&host_data.invocation_seed)
.map_err(|e| RpcError::NotInitialized(format!("key failure: {}", e)))?
};
let rpc_client =
crate::rpc_client::RpcClient::new(nats, &host_data.lattice_rpc_prefix, key);
let rpc_client = crate::rpc_client::RpcClient::new(
nats,
&host_data.lattice_rpc_prefix,
key,
host_data.host_id.clone(),
);

Ok(HostBridge {
inner: Arc::new(HostBridgeInner {
Expand Down
19 changes: 14 additions & 5 deletions rpc-rs/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ pub struct RpcClient {
lattice_prefix: String,
/// secrets for signing invocations
key: Arc<wascap::prelude::KeyPair>,
/// host id for invocations
host_id: String,
}

#[derive(Clone)]
Expand Down Expand Up @@ -69,16 +71,18 @@ pub fn rpc_topic(entity: &WasmCloudEntity, lattice_prefix: &str) -> String {
impl RpcClient {
/// Constructs a new RpcClient for the async nats connection.
/// parameters: async nats client, lattice rpc prefix (usually "default"),
/// and secret key for signing messages
/// secret key for signing messages, and host_id
pub fn new(
nats: Arc<crate::provider::NatsClient>,
lattice_prefix: &str,
key: wascap::prelude::KeyPair,
host_id: String,
) -> Self {
RpcClient {
client: NatsClientType::Async(nats),
lattice_prefix: lattice_prefix.to_string(),
key: Arc::new(key),
host_id,
}
}

Expand All @@ -89,11 +93,13 @@ impl RpcClient {
nats: nats::asynk::Connection,
lattice_prefix: &str,
key: wascap::prelude::KeyPair,
host_id: String,
) -> Self {
RpcClient {
client: NatsClientType::Asynk(nats),
lattice_prefix: lattice_prefix.to_string(),
key: Arc::new(key),
host_id,
}
}

Expand All @@ -104,11 +110,13 @@ impl RpcClient {
nats: nats::Connection,
lattice_prefix: &str,
key: wascap::prelude::KeyPair,
host_id: String,
) -> Self {
RpcClient {
client: NatsClientType::Sync(nats),
lattice_prefix: lattice_prefix.to_string(),
key: Arc::new(key),
host_id,
}
}

Expand Down Expand Up @@ -227,7 +235,7 @@ impl RpcClient {
debug!("rpc_client sending to {}", &target_url);
let claims = wascap::prelude::Claims::<wascap::prelude::Invocation>::new(
issuer.clone(),
subject,
subject.clone(),
&target_url,
&origin_url,
&invocation_hash(&target_url, &origin_url, &message),
Expand All @@ -240,9 +248,9 @@ impl RpcClient {
target,
operation: method.clone(),
msg: message.arg.into_owned(),
id: make_uuid(),
id: subject,
encoded_claims: claims.encode(&self.key).unwrap(),
host_id: String::new(),
host_id: self.host_id.clone(),
};
trace!("rpc send {}", &target_url);

Expand Down Expand Up @@ -399,9 +407,10 @@ impl RpcClientSync {
nats: nats::Connection,
lattice_prefix: &str,
key: wascap::prelude::KeyPair,
host_id: String,
) -> Self {
RpcClientSync {
inner: RpcClient::new_sync(nats, lattice_prefix, key),
inner: RpcClient::new_sync(nats, lattice_prefix, key, host_id),
}
}

Expand Down

0 comments on commit 69d2e22

Please sign in to comment.