strike48-connector 0.3.7

Rust SDK for the Strike48 Connector Framework
Documentation
//! Per-request execution context surfaced via [`crate::BaseConnector::execute_with_context`].
//!
//! The Matrix server populates [`crate::types::ExecuteRequest::context`] with caller
//! identity and request-scoped metadata. Connectors that need to read these keys
//! should use the constants in [`keys`] instead of hardcoding strings.
//!
//! ## Example
//!
//! ```no_run
//! use std::collections::HashMap;
//! use strike48_connector::context::keys;
//!
//! fn handle(context: &HashMap<String, String>) -> &str {
//!     context.get(keys::TENANT_ID).map(String::as_str).unwrap_or("default")
//! }
//! ```

/// Well-known [`crate::types::ExecuteRequest::context`] keys produced by the
/// Matrix server. Connectors that read identity off context should reference
/// these constants so a future server-side rename is a one-line SDK change.
pub mod keys {
    /// Caller tenant identifier in multi-tenant deployments.
    /// Used by downstream consumers to scope storage / KV / spool isolation.
    pub const TENANT_ID: &str = "strike48.tenant_id";

    /// Caller subject (e.g. K8s service-account, OIDC sub claim).
    /// Used primarily for audit logging.
    pub const SUBJECT: &str = "strike48.subject";

    /// Prefix for arbitrary per-caller attributes. Keys flow through as
    /// `strike48.attrs.<name>` (e.g. `strike48.attrs.k8s_namespace`).
    pub const ATTR_PREFIX: &str = "strike48.attrs.";
}

#[cfg(test)]
mod tests {
    use super::keys;

    #[test]
    fn well_known_keys_have_strike48_prefix() {
        assert!(keys::TENANT_ID.starts_with("strike48."));
        assert!(keys::SUBJECT.starts_with("strike48."));
        assert!(keys::ATTR_PREFIX.starts_with("strike48."));
    }

    #[test]
    fn keys_are_distinct() {
        assert_ne!(keys::TENANT_ID, keys::SUBJECT);
        assert_ne!(keys::TENANT_ID, keys::ATTR_PREFIX);
        assert_ne!(keys::SUBJECT, keys::ATTR_PREFIX);
    }

    #[test]
    fn attr_prefix_terminates_with_dot() {
        assert!(
            keys::ATTR_PREFIX.ends_with('.'),
            "ATTR_PREFIX must end with '.' so callers can concatenate: {}",
            keys::ATTR_PREFIX
        );
    }
}