Skip to main content

ingest_api_visibility_observation

Function ingest_api_visibility_observation 

Source
pub fn ingest_api_visibility_observation(
    observation: ApiVisibilityObservation,
    expected_resource: &EntityId,
    knowledge: &KnowledgeBase,
    rules: &RuleEngine,
) -> Result<ApiObservationReceipt, ApiObservationError>
Expand description

Accepts one host-paired visibility observation and applies installed rules.

The expected resource is checked before any write. Evidence and its sole api.visibility.resource-scope relation are then inserted atomically, and rules are applied to the isolated comparison subject. If reasoning fails, the observation pair remains committed and the error carries its receipt; callers must not infer rollback from a failed return value. The host remains responsible for persistence beyond this in-memory store.

This boundary validates scope and canonical storage shape, not producer identity or truth. Predicate names and deterministic digests are public and are not signatures. The host must authenticate the producer, authorize the comparison, and keep raw credentials and response values outside this API.

ยงExamples

use termivar_core::{
    ApiSurfaceKind, ApiVisibilityComparison, ApiVisibilityDimension,
    ApiVisibilityPairKind, ApiVisibilityResult, ConfidenceScore, EntityId,
};
use termivar_scanner::{
    KnowledgeBase, RuleEngine, StandardApiReasoning,
    ingest_api_visibility_observation,
};

let resource = EntityId::new("resource:account-42")?;
let observation = ApiVisibilityComparison::new(
    "comparison-17",
    ApiSurfaceKind::JsonHttp,
    ApiVisibilityPairKind::AuthorizationContext,
    ApiVisibilityResult::Different,
    ApiVisibilityDimension::Fields,
    "anonymous-view",
    "member-view",
    resource.as_str(),
)?
.with_observed_at_ms(1_800_000_000_000)
.to_observation("host.api-comparator", ConfidenceScore::MAX)?;
let knowledge = KnowledgeBase::new();
let mut rules = RuleEngine::new();
StandardApiReasoning::new()?.install(&knowledge, &mut rules)?;

let receipt = ingest_api_visibility_observation(
    observation,
    &resource,
    &knowledge,
    &rules,
)?;
assert_eq!(receipt.commit().resource_scope(), &resource);