wami 0.10.0

Who Am I - Multicloud Identity, IAM, STS, and SSO operations library for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
# API Reference

Complete API documentation for WAMI.

## Overview

WAMI's API is organized into two main layers:

1. **Domain Layer** (`wami::*`) - Pure functions and models
2. **Storage Layer** (`store::*`) - Persistence traits and implementations

---

## Domain Layer (wami::*)

### Identity Module (`wami::identity`)

#### User (`wami::identity::user`)

**Model**:
```rust
pub struct User {
    pub user_name: String,
    pub user_id: String,
    pub arn: String,
    pub path: Option<String>,
    pub created_at: DateTime<Utc>,
    pub wami_arn: String,
    pub providers: Vec<ProviderConfig>,
    pub tenant_id: Option<TenantId>,
}
```

**Builder**:
```rust
pub fn build_user(
    user_name: String,
    path: Option<String>,
    provider: &dyn CloudProvider,
    account_id: &str,
) -> User
```

#### Group (`wami::identity::group`)

**Model**:
```rust
pub struct Group {
    pub group_name: String,
    pub group_id: String,
    pub arn: String,
    pub path: Option<String>,
    pub created_at: DateTime<Utc>,
    // ...
}
```

**Builder**:
```rust
pub fn build_group(
    group_name: String,
    path: Option<String>,
    provider: &dyn CloudProvider,
    account_id: &str,
) -> Group
```

#### Role (`wami::identity::role`)

**Model**:
```rust
pub struct Role {
    pub role_name: String,
    pub role_id: String,
    pub arn: String,
    pub assume_role_policy_document: String,
    pub path: Option<String>,
    pub description: Option<String>,
    // ...
}
```

**Builder**:
```rust
pub fn build_role(
    role_name: String,
    assume_role_policy_document: String,
    path: Option<String>,
    description: Option<String>,
    tags: Option<Vec<Tag>>,
    provider: &dyn CloudProvider,
    account_id: &str,
) -> Role
```

### Credentials Module (`wami::credentials`)

#### Access Key (`wami::credentials::access_key`)

**Model**:
```rust
pub struct AccessKey {
    pub user_name: String,
    pub access_key_id: String,
    pub secret_access_key: String,
    pub status: AccessKeyStatus,
    pub created_at: DateTime<Utc>,
    // ...
}

pub enum AccessKeyStatus {
    Active,
    Inactive,
}
```

**Builder**:
```rust
pub fn build_access_key(
    user_name: String,
    provider: &dyn CloudProvider,
    account_id: &str,
) -> AccessKey
```

#### MFA Device (`wami::credentials::mfa_device`)

**Model**:
```rust
pub struct MfaDevice {
    pub serial_number: String,
    pub user_name: String,
    pub enable_date: DateTime<Utc>,
    pub arn: String,
    // ...
}
```

#### Login Profile (`wami::credentials::login_profile`)

**Model**:
```rust
pub struct LoginProfile {
    pub user_name: String,
    pub created_at: DateTime<Utc>,
    pub password_reset_required: bool,
    // ...
}
```

### STS Module (`wami::sts`)

#### Session (`wami::sts::session`)

**Model**:
```rust
pub struct StsSession {
    pub session_token: String,
    pub access_key_id: String,
    pub secret_access_key: String,
    pub expiration: DateTime<Utc>,
    pub status: SessionStatus,
    pub assumed_role_arn: Option<String>,
    // ...
}

pub enum SessionStatus {
    Active,
    Expired,
    Revoked,
}
```

**Builder**:
```rust
pub fn build_session(
    session_token: String,
    access_key_id: String,
    secret_access_key: String,
    duration_seconds: i64,
    assumed_role_arn: Option<String>,
    provider: &dyn CloudProvider,
    account_id: &str,
) -> StsSession
```

#### Caller Identity (`wami::sts::identity`)

**Model**:
```rust
pub struct CallerIdentity {
    pub user_id: String,
    pub account: String,
    pub arn: String,
    pub wami_arn: String,
    pub providers: Vec<ProviderConfig>,
}
```

### Tenant Module (`wami::tenant`)

**Model**:
```rust
pub struct Tenant {
    pub id: TenantId,
    pub name: String,
    pub parent_id: Option<TenantId>,
    pub organization: Option<String>,
    pub tenant_type: TenantType,
    pub status: TenantStatus,
    pub quotas: TenantQuotas,
    // ...
}

pub struct TenantId(String);

impl TenantId {
    pub fn root(name: &str) -> Self;
    pub fn child(&self, name: &str) -> Self;
    pub fn parent(&self) -> Option<Self>;
    pub fn depth(&self) -> usize;
    pub fn ancestors(&self) -> Vec<TenantId>;
    pub fn is_descendant_of(&self, other: &TenantId) -> bool;
}

pub enum TenantType {
    Root,
    Enterprise,
    Department,
    Team,
    Project,
    Custom(String),
}

pub enum TenantStatus {
    Active,
    Suspended,
    Pending,
    Deleted,
}
```

---

## Storage Layer (store::*)

### Store Traits

#### WamiStore Composite Trait

```rust
pub trait WamiStore: 
    UserStore + 
    GroupStore + 
    RoleStore + 
    AccessKeyStore + 
    MfaDeviceStore + 
    LoginProfileStore + 
    PolicyStore + 
    ServerCertificateStore + 
    SigningCertificateStore + 
    ServiceCredentialStore + 
    ServiceLinkedRoleStore + 
    CredentialReportStore +
    Send + Sync 
{}
```

#### UserStore

```rust
#[async_trait]
pub trait UserStore: Send + Sync {
    async fn create_user(&mut self, user: User) -> Result<User>;
    async fn get_user(&self, user_name: &str) -> Result<Option<User>>;
    async fn update_user(&mut self, user: User) -> Result<User>;
    async fn delete_user(&mut self, user_name: &str) -> Result<()>;
    async fn list_users(
        &self,
        path_prefix: Option<&str>,
        pagination: Option<&PaginationParams>,
    ) -> Result<(Vec<User>, bool, Option<String>)>;
    async fn tag_user(&mut self, user_name: &str, tags: Vec<Tag>) -> Result<()>;
    async fn list_user_tags(&self, user_name: &str) -> Result<Vec<Tag>>;
    async fn untag_user(&mut self, user_name: &str, tag_keys: Vec<String>) -> Result<()>;
}
```

#### GroupStore

```rust
#[async_trait]
pub trait GroupStore: Send + Sync {
    async fn create_group(&mut self, group: Group) -> Result<Group>;
    async fn get_group(&self, group_name: &str) -> Result<Option<Group>>;
    async fn update_group(&mut self, group: Group) -> Result<Group>;
    async fn delete_group(&mut self, group_name: &str) -> Result<()>;
    async fn list_groups(
        &self,
        path_prefix: Option<&str>,
        pagination: Option<&PaginationParams>,
    ) -> Result<(Vec<Group>, bool, Option<String>)>;
    async fn add_user_to_group(&mut self, group_name: &str, user_name: &str) -> Result<()>;
    async fn remove_user_from_group(&mut self, group_name: &str, user_name: &str) -> Result<()>;
    async fn list_groups_for_user(&self, user_name: &str) -> Result<Vec<Group>>;
}
```

#### RoleStore

```rust
#[async_trait]
pub trait RoleStore: Send + Sync {
    async fn create_role(&mut self, role: Role) -> Result<Role>;
    async fn get_role(&self, role_name: &str) -> Result<Option<Role>>;
    async fn update_role(&mut self, role: Role) -> Result<Role>;
    async fn delete_role(&mut self, role_name: &str) -> Result<()>;
    async fn list_roles(
        &self,
        path_prefix: Option<&str>,
        pagination: Option<&PaginationParams>,
    ) -> Result<(Vec<Role>, bool, Option<String>)>;
    async fn tag_role(&mut self, role_name: &str, tags: Vec<Tag>) -> Result<()>;
    async fn list_role_tags(&self, role_name: &str) -> Result<Vec<Tag>>;
    async fn untag_role(&mut self, role_name: &str, tag_keys: Vec<String>) -> Result<()>;
}
```

#### AccessKeyStore

```rust
#[async_trait]
pub trait AccessKeyStore: Send + Sync {
    async fn create_access_key(&mut self, access_key: AccessKey) -> Result<AccessKey>;
    async fn get_access_key(&self, access_key_id: &str) -> Result<Option<AccessKey>>;
    async fn update_access_key(&mut self, access_key: AccessKey) -> Result<AccessKey>;
    async fn delete_access_key(&mut self, access_key_id: &str) -> Result<()>;
    async fn list_access_keys(&self, user_name: &str) -> Result<Vec<AccessKey>>;
}
```

#### StsStore Composite Trait

```rust
pub trait StsStore: SessionStore + IdentityStore + Send + Sync {}
```

#### SessionStore

```rust
#[async_trait]
pub trait SessionStore: Send + Sync {
    async fn create_session(&mut self, session: StsSession) -> Result<StsSession>;
    async fn get_session(&self, session_token: &str) -> Result<Option<StsSession>>;
    async fn delete_session(&mut self, session_token: &str) -> Result<()>;
    async fn list_sessions(&self, user_id: Option<&str>) -> Result<Vec<StsSession>>;
}
```

#### TenantStore

```rust
#[async_trait]
pub trait TenantStore: Send + Sync {
    async fn create_tenant(&mut self, tenant: Tenant) -> Result<Tenant>;
    async fn get_tenant(&self, tenant_id: &TenantId) -> Result<Option<Tenant>>;
    async fn update_tenant(&mut self, tenant: Tenant) -> Result<Tenant>;
    async fn delete_tenant(&mut self, tenant_id: &TenantId) -> Result<()>;
    async fn list_tenants(&self) -> Result<Vec<Tenant>>;
    async fn list_child_tenants(&self, parent_id: &TenantId) -> Result<Vec<Tenant>>;
    async fn get_ancestors(&self, tenant_id: &TenantId) -> Result<Vec<Tenant>>;
    async fn get_descendants(&self, tenant_id: &TenantId) -> Result<Vec<TenantId>>;
    async fn get_effective_quotas(&self, tenant_id: &TenantId) -> Result<TenantQuotas>;
    async fn get_tenant_usage(&self, tenant_id: &TenantId) -> Result<TenantUsage>;
}
```

### In-Memory Store Implementations

#### InMemoryWamiStore

```rust
pub struct InMemoryWamiStore {
    // Internal HashMap-based storage
    // Thread-safe with Arc<RwLock<T>>
}

impl InMemoryWamiStore {
    pub fn new() -> Self;
}

// Automatically implements all WamiStore sub-traits
```

#### InMemoryStsStore

```rust
pub struct InMemoryStsStore {
    // Internal HashMap-based storage
}

impl InMemoryStsStore {
    pub fn new() -> Self;
}

// Implements SessionStore and IdentityStore
```

#### InMemoryTenantStore

```rust
pub struct InMemoryTenantStore {
    // Internal HashMap-based storage
}

impl InMemoryTenantStore {
    pub fn new() -> Self;
}

// Implements TenantStore
```

---

## Provider Layer (provider::*)

### CloudProvider Trait

```rust
pub trait CloudProvider: Send + Sync {
    fn name(&self) -> &str;
    fn generate_arn(&self, resource_type: &str, resource_name: &str, account_id: &str) -> String;
    fn generate_id(&self, prefix: &str) -> String;
}
```

### Built-in Providers

#### AwsProvider

```rust
pub struct AwsProvider;

impl AwsProvider {
    pub fn new() -> Self;
}

// Generates ARNs like: arn:aws:iam::123456789012:user/alice
```

#### GcpProvider

```rust
pub struct GcpProvider;

impl GcpProvider {
    pub fn new() -> Self;
}

// Generates resource names in GCP format
```

#### AzureProvider

```rust
pub struct AzureProvider;

impl AzureProvider {
    pub fn new() -> Self;
}

// Generates resource IDs in Azure format
```

---

## Error Handling

### AmiError

```rust
pub enum AmiError {
    ValidationError(String),
    ResourceNotFound { resource: String },
    ResourceExists { resource: String },
    AccessDenied { message: String },
    InternalError(String),
    AwsSdk(aws_sdk_iam::Error),
    StsSdk(aws_sdk_sts::Error),
    SsoAdminSdk(aws_sdk_ssoadmin::Error),
}

impl std::error::Error for AmiError {}
impl std::fmt::Display for AmiError {}
```

---

## Common Types

### PaginationParams

```rust
pub struct PaginationParams {
    pub max_items: Option<usize>,
    pub marker: Option<String>,
}
```

### Tag

```rust
pub struct Tag {
    pub key: String,
    pub value: String,
}
```

### ProviderConfig

```rust
pub struct ProviderConfig {
    pub provider_name: String,
    pub account_id: String,
    pub native_arn: String,
    pub synced_at: DateTime<Utc>,
    pub tenant_id: Option<TenantId>,
}
```

---

## See Also

- **[Getting Started]GETTING_STARTED.md** - Quick start guide
- **[Architecture]ARCHITECTURE.md** - Design and components
- **[Examples]EXAMPLES.md** - Working code examples
- **[Store Implementation]STORE_IMPLEMENTATION.md** - Create custom stores

---

For detailed examples and usage patterns, see the [Getting Started Guide](GETTING_STARTED.md).