wami-core 0.16.0

Core primitives for wami: ARNs, contexts, errors and shared types
Documentation
//! ARN (Amazon Resource Name) module for WAMI's multi-tenant, multi-cloud architecture.
//!
//! This module provides a comprehensive ARN system that supports:
//! - Multi-tenant hierarchies (e.g., `t1/t2/t3`)
//! - Multi-cloud provider mapping (AWS, GCP, Azure, Scaleway)
//! - Resource identification by stable IDs (not names)
//! - Bidirectional transformation between WAMI and provider-specific formats
//!
//! # ARN Format
//!
//! ## WAMI Native (no cloud sync):
//! ```text
//! arn:wami:{service}:{tenant_path}:wami:{wami_instance_id}:{resource_type}/{resource_id}
//! Example: arn:wami:iam:12345678/87654321/99999999:wami:999888777:user/77557755
//! ```
//!
//! ## Cloud-Synced Resources:
//! ```text
//! arn:wami:{service}:{tenant_path}:wami:{wami_instance_id}:{provider}:{provider_account_id}:{resource_type}/{resource_id}
//! Examples:
//! - arn:wami:iam:12345678/87654321/99999999:wami:999888777:aws:223344556677:user/77557755
//! - arn:wami:iam:12345678/87654321/99999999:wami:999888777:gcp:554433221:user/77557755
//! ```
//!
//! # Usage
//!
//! ## Building ARNs
//!
//! Use the fluent builder API:
//!
//! ```
//! use wami_core::arn::{WamiArn, Service};
//!
//! // WAMI native ARN
//! let arn = WamiArn::builder()
//!     .service(Service::Iam)
//!     .tenant_hierarchy(vec![12345678, 87654321, 99999999])
//!     .wami_instance("999888777")
//!     .resource("user", "77557755")
//!     .build()
//!     .unwrap();
//!
//! assert_eq!(
//!     arn.to_string(),
//!     "arn:wami:iam:12345678/87654321/99999999:wami:999888777:user/77557755"
//! );
//!
//! // Cloud-synced ARN
//! let arn = WamiArn::builder()
//!     .service(Service::Iam)
//!     .tenant(12345678)
//!     .wami_instance("999888777")
//!     .cloud_provider("aws", "223344556677")
//!     .resource("user", "77557755")
//!     .build()
//!     .unwrap();
//!
//! assert!(arn.is_cloud_synced());
//! ```
//!
//! ## Parsing ARNs
//!
//! ```
//! use wami_core::arn::WamiArn;
//! use std::str::FromStr;
//!
//! let arn = WamiArn::from_str("arn:wami:iam:12345678:wami:999888777:user/77557755").unwrap();
//! assert_eq!(arn.resource_type(), "user");
//! assert_eq!(arn.primary_tenant(), Some("12345678".to_string()));
//! ```
//!
//! ## Transforming to Provider Formats
//!
//! Requires the `aws` feature; provider translations are off by default.
//!
//! ```
//! # #[cfg(feature = "aws")] {
//! use wami_core::arn::{WamiArn, Service, AwsArnTransformer, ArnTransformer};
//!
//! let arn = WamiArn::builder()
//!     .service(Service::Iam)
//!     .tenant(12345678)
//!     .wami_instance("999888777")
//!     .cloud_provider("aws", "223344556677")
//!     .resource("user", "77557755")
//!     .build()
//!     .unwrap();
//!
//! let transformer = AwsArnTransformer;
//! let aws_arn = transformer.to_provider_arn(&arn).unwrap();
//! assert_eq!(aws_arn, "arn:aws:iam::223344556677:user/77557755");
//! # }
//! ```

pub mod builder;
pub mod matching;
pub mod parser;
pub mod transformer;
pub mod types;

// Re-export key types and functions
pub use builder::ArnBuilder;
pub use matching::{glob_match, matches_arn_pattern, MatchContext};
pub use parser::{parse_arn, ArnParseError};
pub use transformer::{available_providers, get_transformer, ArnTransformer, ProviderArnInfo};
// Each translation is behind its provider's feature, off by default: a
// deployment that syncs with no cloud should not compile any of them.
#[cfg(feature = "aws")]
pub use transformer::AwsArnTransformer;
#[cfg(feature = "azure")]
pub use transformer::AzureArnTransformer;
#[cfg(feature = "gcp")]
pub use transformer::GcpArnTransformer;
#[cfg(feature = "scaleway")]
pub use transformer::ScalewayArnTransformer;
pub use types::{
    CloudMapping, Resource, Service, TenantPath, WamiArn, ROOT_TENANT_ID, ROOT_USER_NAME,
};