Skip to main content

09_multi_cloud_user_sync/
09_multi_cloud_user_sync.rs

1//! Multi-Cloud User Sync
2//!
3//! This example demonstrates:
4//! - Creating the same logical user across multiple cloud providers
5//! - Different ARN formats per provider (AWS, GCP, Azure)
6//! - Storing provider-specific metadata
7//!
8//! Scenario: alice@company.com needs identities in AWS, GCP, and Azure.
9//!
10//! Run with: `cargo run --example 09_multi_cloud_user_sync`
11
12use std::sync::Arc;
13use tokio::sync::RwLock;
14use wami::arn::{TenantPath, WamiArn};
15use wami::context::WamiContext;
16use wami::service::UserService;
17use wami::store::memory::InMemoryWamiStore;
18use wami::wami::identity::user::requests::CreateUserRequest;
19
20#[tokio::main]
21async fn main() -> Result<(), Box<dyn std::error::Error>> {
22    println!("=== Multi-Cloud User Sync ===\n");
23
24    let store = Arc::new(RwLock::new(InMemoryWamiStore::default()));
25
26    // Create context for operations
27    let context = WamiContext::builder()
28        .instance_id("123456789012")
29        .tenant_path(TenantPath::single(0))
30        .caller_arn(
31            WamiArn::builder()
32                .service(wami::arn::Service::Iam)
33                .tenant_path(TenantPath::single(0))
34                .wami_instance("123456789012")
35                .resource("user", "admin")
36                .build()?,
37        )
38        .is_root(false)
39        .build()?;
40
41    println!("āœ“ Using unified context for all operations");
42
43    // === CREATE USER ===
44    println!("\n\nStep 1: Creating alice user...\n");
45
46    let user_service = UserService::new(store.clone());
47
48    let user_req = CreateUserRequest {
49        user_name: "alice".to_string(),
50        path: Some("/cloud-sync/".to_string()),
51        permissions_boundary: None,
52        tags: Some(vec![
53            wami::types::Tag {
54                key: "Email".to_string(),
55                value: "alice@company.com".to_string(),
56            },
57            wami::types::Tag {
58                key: "MultiCloud".to_string(),
59                value: "true".to_string(),
60            },
61        ]),
62    };
63
64    let user = user_service.create_user(&context, user_req).await?;
65    println!("āœ“ Created alice:");
66    println!("  - ARN: {}", user.arn);
67    println!("  - User ID: {}", user.user_id);
68    println!("  - WAMI ARN: {}", user.wami_arn);
69
70    // === COMPARE ARN FORMATS ===
71    println!("\n\nStep 2: Understanding WAMI ARN format...\n");
72
73    println!("WAMI unified ARN:");
74    println!("  {}", user.wami_arn);
75    println!("\nThis ARN can be transformed to provider-specific formats:");
76    println!("  - AWS ARN format for AWS API calls");
77    println!("  - GCP resource name format for GCP API calls");
78    println!("  - Azure resource ID format for Azure API calls");
79
80    // === DEMONSTRATE PROVIDER METADATA ===
81    println!("\n\nStep 3: Understanding WAMI architecture...\n");
82
83    println!("WAMI provides:");
84    println!("- Unified WAMI ARN format (for internal operations)");
85    println!("- Provider-specific ARN transformation when needed");
86    println!("- Consistent resource identification across clouds");
87    println!("- Tags for categorization and metadata");
88
89    println!("\nBenefits:");
90    println!("- Unified identity management across clouds");
91    println!("- Provider-agnostic operations with context");
92    println!("- Cross-cloud audit trails with WAMI ARNs");
93    println!("- Multi-cloud resource tracking");
94
95    println!("\nāœ… Example completed successfully!");
96    println!("Key takeaways:");
97    println!("- WAMI uses a unified ARN format internally");
98    println!("- Provider-specific ARNs can be generated when needed");
99    println!("- Context-based operations work across all providers");
100    println!("- Use tags to track cross-cloud relationships");
101
102    Ok(())
103}