Skip to content

Commit

Permalink
fix: write out policy data in a secret config correctly
Browse files Browse the repository at this point in the history
In wasmCloud#307 we introduced secrets support, which works by storing secrets
references as config in NATS KV. This fixes a bug in the way that we
were serializing the configuration as JSON where we were overwriting the
policy field which is required.
  • Loading branch information
protochron committed Jul 19, 2024
1 parent 737aa82 commit e964109
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions crates/wadm/src/scaler/secretscaler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl<S: SecretSource + Send + Sync + Clone> Scaler for SecretScaler<S> {
(Ok(_config), scaler_config) => {
debug!(self.secret_name, "Putting secret");

let cfg = merge_policy_config(&self.policy, &scaler_config)?;
let cfg = merge_policy_properties(&self.policy, &scaler_config)?;

*self.status.write().await = StatusInfo::reconciling("Secret out of sync");
Ok(vec![Command::PutConfig(PutConfig {
Expand All @@ -131,21 +131,21 @@ impl<S: SecretSource + Send + Sync + Clone> Scaler for SecretScaler<S> {
}
}

fn merge_policy_config(
fn merge_policy_properties(
policy: &Policy,
reference: &SecretSourceProperty,
) -> anyhow::Result<HashMap<String, String>> {
let mut cfg: HashMap<String, String> = reference.clone().try_into()?;
let mut p = policy.properties.clone();
p.insert("type".to_string(), policy.policy_type.clone());
let policy_json = serde_json::to_string(&p)?;
cfg.insert("policy".to_string(), policy_json);
cfg.insert("policy_properties".to_string(), policy_json);
Ok(cfg)
}

#[cfg(test)]
mod test {
use super::merge_policy_config;
use super::merge_policy_properties;

use crate::{
commands::{Command, PutConfig},
Expand Down Expand Up @@ -192,7 +192,7 @@ mod test {
StatusType::Reconciling
);

let cfg = merge_policy_config(&policy, &secret.source).expect("failed to merge policy");
let cfg = merge_policy_properties(&policy, &secret.source).expect("failed to merge policy");

assert_eq!(
secret_scaler
Expand Down

0 comments on commit e964109

Please sign in to comment.