pub fn calculate_record_hash<T: Serialize>(data: &T) -> StringExpand description
Calculate SHA-256 hash of a record’s data fields.
This function serializes the record’s spec to JSON and calculates a SHA-256 hash. The hash is used to detect actual data changes and avoid unnecessary DNS updates.
§Arguments
record- The record to hash (must implement Serialize)
§Returns
A hexadecimal string representation of the SHA-256 hash.
§Example
use bindy::ddns::calculate_record_hash;
use bindy::crd::{ARecord, ARecordSpec};
use k8s_openapi::apimachinery::pkg::apis::meta::v1::ObjectMeta;
let record = ARecord {
metadata: ObjectMeta::default(),
spec: ARecordSpec {
name: "www".to_string(),
ipv4_addresses: vec!["192.0.2.1".to_string()],
ttl: Some(300),
},
status: None,
};
let hash = calculate_record_hash(&record.spec);
assert_eq!(hash.len(), 64); // SHA-256 produces 64 hex chars