cedros_data/store/
contracts.rs1use crate::contracts::{infer_contract, verify_contract_change};
2use crate::error::{CedrosDataError, Result};
3use crate::models::{ContractVerificationReport, VerifyContractRequest};
4
5use super::CedrosData;
6
7impl CedrosData {
8 pub async fn verify_contract(
9 &self,
10 request: VerifyContractRequest,
11 ) -> Result<ContractVerificationReport> {
12 if request.samples.is_empty() {
13 return Err(CedrosDataError::InvalidRequest(
14 "verify_contract requires at least one sample".to_string(),
15 ));
16 }
17
18 self.ensure_site_exists().await?;
19 let collection = self.find_collection(&request.collection_name).await?;
20 let incoming_contract = infer_contract(&request.samples)?;
21
22 let latest_contract = self.latest_contract(&collection.collection_name).await?;
23 let reference = collection
24 .strict_contract
25 .as_ref()
26 .or(latest_contract.as_ref());
27
28 Ok(verify_contract_change(reference, &incoming_contract))
29 }
30}