spin_key_value_aws/
lib.rs1mod store;
2
3use serde::Deserialize;
4use spin_factor_key_value::runtime_config::spin::MakeKeyValueStore;
5use store::{
6 KeyValueAwsDynamo, KeyValueAwsDynamoAuthOptions, KeyValueAwsDynamoRuntimeConfigOptions,
7};
8
9#[derive(Default)]
11pub struct AwsDynamoKeyValueStore {
12 _priv: (),
13}
14
15impl AwsDynamoKeyValueStore {
16 pub fn new() -> Self {
18 Self::default()
19 }
20}
21
22#[derive(Deserialize)]
24pub struct AwsDynamoKeyValueRuntimeConfig {
25 access_key: Option<String>,
27 secret_key: Option<String>,
29 token: Option<String>,
31 region: String,
33 consistent_read: Option<bool>,
36 table: String,
38}
39
40impl MakeKeyValueStore for AwsDynamoKeyValueStore {
41 const RUNTIME_CONFIG_TYPE: &'static str = "aws_dynamo";
42
43 type RuntimeConfig = AwsDynamoKeyValueRuntimeConfig;
44
45 type StoreManager = KeyValueAwsDynamo;
46
47 fn make_store(
48 &self,
49 runtime_config: Self::RuntimeConfig,
50 ) -> anyhow::Result<Self::StoreManager> {
51 let AwsDynamoKeyValueRuntimeConfig {
52 access_key,
53 secret_key,
54 token,
55 region,
56 consistent_read,
57 table,
58 } = runtime_config;
59 let auth_options = match (access_key, secret_key) {
60 (Some(access_key), Some(secret_key)) => {
61 KeyValueAwsDynamoAuthOptions::RuntimeConfigValues(
62 KeyValueAwsDynamoRuntimeConfigOptions::new(access_key, secret_key, token),
63 )
64 }
65 _ => KeyValueAwsDynamoAuthOptions::Environmental,
66 };
67 KeyValueAwsDynamo::new(
68 region,
69 consistent_read.unwrap_or(false),
70 table,
71 auth_options,
72 )
73 }
74}