Skip to main content

wami_core/arn/
mod.rs

1//! ARN (Amazon Resource Name) module for WAMI's multi-tenant, multi-cloud architecture.
2//!
3//! This module provides a comprehensive ARN system that supports:
4//! - Multi-tenant hierarchies (e.g., `t1/t2/t3`)
5//! - Multi-cloud provider mapping (AWS, GCP, Azure, Scaleway)
6//! - Resource identification by stable IDs (not names)
7//! - Bidirectional transformation between WAMI and provider-specific formats
8//!
9//! # ARN Format
10//!
11//! ## WAMI Native (no cloud sync):
12//! ```text
13//! arn:wami:{service}:{tenant_path}:wami:{wami_instance_id}:{resource_type}/{resource_id}
14//! Example: arn:wami:iam:12345678/87654321/99999999:wami:999888777:user/77557755
15//! ```
16//!
17//! ## Cloud-Synced Resources:
18//! ```text
19//! arn:wami:{service}:{tenant_path}:wami:{wami_instance_id}:{provider}:{provider_account_id}:{resource_type}/{resource_id}
20//! Examples:
21//! - arn:wami:iam:12345678/87654321/99999999:wami:999888777:aws:223344556677:user/77557755
22//! - arn:wami:iam:12345678/87654321/99999999:wami:999888777:gcp:554433221:user/77557755
23//! ```
24//!
25//! # Usage
26//!
27//! ## Building ARNs
28//!
29//! Use the fluent builder API:
30//!
31//! ```
32//! use wami_core::arn::{WamiArn, Service};
33//!
34//! // WAMI native ARN
35//! let arn = WamiArn::builder()
36//!     .service(Service::Iam)
37//!     .tenant_hierarchy(vec![12345678, 87654321, 99999999])
38//!     .wami_instance("999888777")
39//!     .resource("user", "77557755")
40//!     .build()
41//!     .unwrap();
42//!
43//! assert_eq!(
44//!     arn.to_string(),
45//!     "arn:wami:iam:12345678/87654321/99999999:wami:999888777:user/77557755"
46//! );
47//!
48//! // Cloud-synced ARN
49//! let arn = WamiArn::builder()
50//!     .service(Service::Iam)
51//!     .tenant(12345678)
52//!     .wami_instance("999888777")
53//!     .cloud_provider("aws", "223344556677")
54//!     .resource("user", "77557755")
55//!     .build()
56//!     .unwrap();
57//!
58//! assert!(arn.is_cloud_synced());
59//! ```
60//!
61//! ## Parsing ARNs
62//!
63//! ```
64//! use wami_core::arn::WamiArn;
65//! use std::str::FromStr;
66//!
67//! let arn = WamiArn::from_str("arn:wami:iam:12345678:wami:999888777:user/77557755").unwrap();
68//! assert_eq!(arn.resource_type(), "user");
69//! assert_eq!(arn.primary_tenant(), Some("12345678".to_string()));
70//! ```
71//!
72//! ## Transforming to Provider Formats
73//!
74//! Requires the `aws` feature; provider translations are off by default.
75//!
76//! ```
77//! # #[cfg(feature = "aws")] {
78//! use wami_core::arn::{WamiArn, Service, AwsArnTransformer, ArnTransformer};
79//!
80//! let arn = WamiArn::builder()
81//!     .service(Service::Iam)
82//!     .tenant(12345678)
83//!     .wami_instance("999888777")
84//!     .cloud_provider("aws", "223344556677")
85//!     .resource("user", "77557755")
86//!     .build()
87//!     .unwrap();
88//!
89//! let transformer = AwsArnTransformer;
90//! let aws_arn = transformer.to_provider_arn(&arn).unwrap();
91//! assert_eq!(aws_arn, "arn:aws:iam::223344556677:user/77557755");
92//! # }
93//! ```
94
95pub mod builder;
96pub mod matching;
97pub mod parser;
98pub mod transformer;
99pub mod types;
100
101// Re-export key types and functions
102pub use builder::ArnBuilder;
103pub use matching::{glob_match, matches_arn_pattern, MatchContext};
104pub use parser::{parse_arn, ArnParseError};
105pub use transformer::{available_providers, get_transformer, ArnTransformer, ProviderArnInfo};
106// Each translation is behind its provider's feature, off by default: a
107// deployment that syncs with no cloud should not compile any of them.
108#[cfg(feature = "aws")]
109pub use transformer::AwsArnTransformer;
110#[cfg(feature = "azure")]
111pub use transformer::AzureArnTransformer;
112#[cfg(feature = "gcp")]
113pub use transformer::GcpArnTransformer;
114#[cfg(feature = "scaleway")]
115pub use transformer::ScalewayArnTransformer;
116pub use types::{
117    CloudMapping, Resource, Service, TenantPath, WamiArn, ROOT_TENANT_ID, ROOT_USER_NAME,
118};