vantage_aws/models/dynamodb/table.rs
1use serde::{Deserialize, Serialize};
2use vantage_table::table::Table;
3
4use crate::{AwsAccount, eq};
5
6/// One DynamoDB table from `ListTables`. The list-side response is
7/// minimal — just an array of strings — so v0 surfaces the name only.
8/// `DescribeTable` (single-record, richer metadata) is a v0+ feature.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct DynamoDbTable {
11 #[serde(rename = "TableName")]
12 pub table_name: String,
13}
14
15/// `ListTables` table — every DynamoDB table in the account/region.
16/// Use `eq("Limit", N)` if you need to cap the page; pagination via
17/// `ExclusiveStartTableName` isn't surfaced in v0.
18///
19/// ```no_run
20/// # use vantage_aws::AwsAccount;
21/// # use vantage_aws::models::dynamodb::tables_table;
22/// # async fn run() -> vantage_core::Result<()> {
23/// # let aws = AwsAccount::from_default()?;
24/// let tables = tables_table(aws);
25/// # Ok(()) }
26/// ```
27pub fn tables_table(aws: AwsAccount) -> Table<AwsAccount, DynamoDbTable> {
28 Table::new(
29 "json10/TableNames:dynamodb/DynamoDB_20120810.ListTables",
30 aws,
31 )
32 .with_id_column("TableName")
33}
34
35impl DynamoDbTable {
36 /// Build a [`tables_table`] narrowed to the table named in `arn`.
37 /// Accepts ARNs of the shape
38 /// `arn:aws:dynamodb:<region>:<account>:table/<name>`.
39 ///
40 /// `ListTables` doesn't take a name filter, so the narrowing
41 /// happens post-hoc client-side via the standard
42 /// `impls::table_source` retain pass.
43 pub fn from_arn(arn: &str, aws: AwsAccount) -> Option<Table<AwsAccount, DynamoDbTable>> {
44 let after = arn.split(":table/").nth(1)?;
45 let name = after.split('/').next().unwrap_or(after);
46 if name.is_empty() {
47 return None;
48 }
49 let mut t = tables_table(aws);
50 t.add_condition(eq("TableName", name.to_string()));
51 Some(t)
52 }
53}