01_hello_wami/
01_hello_wami.rs1use wami::arn::{TenantPath, WamiArn};
13use wami::context::WamiContext;
14use wami::store::memory::InMemoryWamiStore;
15use wami::store::traits::UserStore;
16use wami::wami::identity::user::builder::build_user;
17
18#[tokio::main]
19async fn main() -> Result<(), Box<dyn std::error::Error>> {
20 println!("=== Hello WAMI ===\n");
21
22 println!("Step 1: Initializing in-memory store...");
24 let mut store = InMemoryWamiStore::default();
25 println!("✓ Store initialized");
26
27 println!("\nStep 2: Creating WAMI context...");
29 let context = WamiContext::builder()
30 .instance_id("123456789012")
31 .tenant_path(TenantPath::single(0)) .caller_arn(
33 WamiArn::builder()
34 .service(wami::arn::Service::Iam)
35 .tenant_path(TenantPath::single(0))
36 .wami_instance("123456789012")
37 .resource("user", "admin")
38 .build()?,
39 )
40 .is_root(false)
41 .build()?;
42 println!("✓ Context created");
43
44 println!("\nStep 3: Building user 'alice'...");
46 let user = build_user("alice".to_string(), Some("/".to_string()), &context)?;
47 println!("✓ User built with ARN: {}", user.wami_arn);
48
49 println!("\nStep 4: Storing user in the store...");
51 let created_user = store.create_user(user).await?;
52 println!("✓ User stored successfully");
53 println!(" - Name: {}", created_user.user_name);
54 println!(" - User ID: {}", created_user.user_id);
55 println!(" - ARN: {}", created_user.wami_arn);
56
57 println!("\nStep 5: Retrieving user from store...");
59 let retrieved = store.get_user("alice").await?;
60 match retrieved {
61 Some(user) => {
62 println!("✓ User retrieved successfully");
63 println!(" - Name: {}", user.user_name);
64 println!(" - Path: {}", user.path);
65 }
66 None => println!("✗ User not found"),
67 }
68
69 println!("\n✅ Example completed successfully!");
70 println!("Key takeaways:");
71 println!("- InMemoryWamiStore provides a simple storage backend");
72 println!("- Providers (AWS, GCP, Azure) handle platform-specific details");
73 println!("- Pure functions create domain objects without side effects");
74
75 Ok(())
76}