spin_key_value_azure/
lib.rs1mod store;
2
3use serde::Deserialize;
4use spin_factor_key_value::runtime_config::spin::MakeKeyValueStore;
5
6pub use store::{
7 KeyValueAzureCosmos, KeyValueAzureCosmosAuthOptions, KeyValueAzureCosmosRuntimeConfigOptions,
8};
9
10pub struct AzureKeyValueStore {
12 app_id: Option<String>,
13}
14
15impl AzureKeyValueStore {
16 pub fn new(app_id: Option<String>) -> Self {
21 Self { app_id }
22 }
23}
24
25#[derive(Deserialize)]
27pub struct AzureCosmosKeyValueRuntimeConfig {
28 key: Option<String>,
30 account: String,
32 database: String,
34 container: String,
37}
38
39impl MakeKeyValueStore for AzureKeyValueStore {
40 const RUNTIME_CONFIG_TYPE: &'static str = "azure_cosmos";
41
42 type RuntimeConfig = AzureCosmosKeyValueRuntimeConfig;
43
44 type StoreManager = KeyValueAzureCosmos;
45
46 fn make_store(
47 &self,
48 runtime_config: Self::RuntimeConfig,
49 ) -> anyhow::Result<Self::StoreManager> {
50 let auth_options = match runtime_config.key {
51 Some(key) => KeyValueAzureCosmosAuthOptions::RuntimeConfigValues(
52 KeyValueAzureCosmosRuntimeConfigOptions::new(key),
53 ),
54 None => KeyValueAzureCosmosAuthOptions::Environmental,
55 };
56 KeyValueAzureCosmos::new(
57 runtime_config.account,
58 runtime_config.database,
59 runtime_config.container,
60 auth_options,
61 self.app_id.clone(),
62 )
63 }
64}