Skip to content

Commit 2c6bee8

Browse files
committed
Make SecretRuleMatchValidationHttpV2::provides an Option
1 parent 8cb066c commit 2c6bee8

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

crates/cli/src/model/datadog_api.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,9 @@ mod tests {
942942
Some(SecretRuleMatchValidation::CustomHttpV2(_))
943943
));
944944
if let Some(SecretRuleMatchValidation::CustomHttpV2(config)) = rule.match_validation {
945-
assert_eq!(config.provides[0].kind, "some_vendor");
946-
assert_eq!(config.provides[0].name, "client_id");
945+
let provides = config.provides.expect("expected paired validator config");
946+
assert_eq!(provides[0].kind, "some_vendor");
947+
assert_eq!(provides[0].name, "client_id");
947948
} else {
948949
panic!("Expected CustomHttpV2 variant");
949950
}

crates/secrets/src/model/secret_rule.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,20 @@ impl TryFrom<&SecretRuleMatchValidation> for MatchValidationType {
269269
.collect();
270270

271271
// Convert provides
272-
let provides: Vec<PairedValidatorConfig> = custom_http_v2
273-
.provides
274-
.iter()
275-
.map(|p| PairedValidatorConfig {
276-
kind: p.kind.clone(),
277-
name: p.name.clone(),
278-
})
279-
.collect();
272+
let provides = custom_http_v2.provides.as_ref().map(|provides| {
273+
provides
274+
.iter()
275+
.map(|p| PairedValidatorConfig {
276+
kind: p.kind.clone(),
277+
name: p.name.clone(),
278+
})
279+
.collect()
280+
});
280281

281282
Ok(MatchValidationType::CustomHttpV2(CustomHttpConfigV2 {
282283
match_pairing,
283284
calls,
284-
provides: Some(provides),
285+
provides,
285286
}))
286287
}
287288
}
@@ -306,7 +307,8 @@ pub struct SecretRuleMatchValidationHttpV2 {
306307
#[serde(skip_serializing_if = "Option::is_none")]
307308
pub match_pairing: Option<SecretRuleMatchPairingConfig>,
308309
pub calls: Vec<SecretRuleHttpCallConfig>,
309-
pub provides: Vec<SecretRulePairedValidatorConfig>,
310+
#[serde(skip_serializing_if = "Option::is_none")]
311+
pub provides: Option<Vec<SecretRulePairedValidatorConfig>>,
310312
}
311313

312314
#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
@@ -688,7 +690,7 @@ mod tests {
688690
],
689691
},
690692
}],
691-
provides: vec![
693+
provides: Some(vec![
692694
SecretRulePairedValidatorConfig {
693695
kind: "datadog".to_string(),
694696
name: "api_key".to_string(),
@@ -697,7 +699,7 @@ mod tests {
697699
kind: "datadog".to_string(),
698700
name: "app_key".to_string(),
699701
},
700-
],
702+
]),
701703
};
702704

703705
let validation = SecretRuleMatchValidation::CustomHttpV2(http_v2_config);
@@ -893,7 +895,7 @@ mod tests {
893895
],
894896
},
895897
}],
896-
provides: vec![
898+
provides: Some(vec![
897899
SecretRulePairedValidatorConfig {
898900
kind: "datadog".to_string(),
899901
name: "api_key".to_string(),
@@ -902,7 +904,7 @@ mod tests {
902904
kind: "datadog".to_string(),
903905
name: "app_key".to_string(),
904906
},
905-
],
907+
]),
906908
});
907909
}
908910
}

0 commit comments

Comments
 (0)