Skip to content
This repository has been archived by the owner on Nov 6, 2023. It is now read-only.

Commit

Permalink
fix(claims): safely parse null versions as empty string
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <brooks@cosmonic.com>
  • Loading branch information
brooksmtownsend committed Jul 27, 2023
1 parent 710ab08 commit 0ec90cd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "wasmcloud-control-interface"
version = "0.28.0"
version = "0.28.1"
authors = ["wasmCloud Team"]
edition = "2021"
homepage = "https://wasmcloud.com"
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ impl Client {
debug!("get_claims:request {}", &subject);
match self.request_timeout(subject, vec![], self.timeout).await {
Ok(msg) => {
let list: GetClaimsResponse = json_deserialize(&msg.payload)?;
Ok(list)
let list: SafeClaimsResponse = json_deserialize(&msg.payload)?;
Ok(list.into())
}
Err(e) => Err(format!("Did not receive claims from lattice: {}", e).into()),
}
Expand Down
25 changes: 25 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,31 @@ pub struct GetClaimsResponse {
pub claims: CtlKVList,
}

/// A safety type that can handle claims values that are set to Null. This is
/// only used internally for compatibility, we will still send out [GetClaimsResponse]
/// as the response type.
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub(crate) struct SafeClaimsResponse {
pub claims: Vec<HashMap<String, Option<String>>>,
}

impl Into<GetClaimsResponse> for SafeClaimsResponse {
fn into(self) -> GetClaimsResponse {
GetClaimsResponse {
claims: self
.claims
.into_iter()
.map(|claim| {
claim
.into_iter()
.map(|(k, v)| (k, v.unwrap_or_default()))
.collect()
})
.collect(),
}
}
}

/// A summary representation of a host
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct Host {
Expand Down

0 comments on commit 0ec90cd

Please sign in to comment.