spin_key_value_azure/
lib.rsmod store;
use serde::Deserialize;
use spin_factor_key_value::runtime_config::spin::MakeKeyValueStore;
use store::{
KeyValueAzureCosmos, KeyValueAzureCosmosAuthOptions, KeyValueAzureCosmosRuntimeConfigOptions,
};
#[derive(Default)]
pub struct AzureKeyValueStore {
_priv: (),
}
impl AzureKeyValueStore {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Deserialize)]
pub struct AzureCosmosKeyValueRuntimeConfig {
key: Option<String>,
account: String,
database: String,
container: String,
}
impl MakeKeyValueStore for AzureKeyValueStore {
const RUNTIME_CONFIG_TYPE: &'static str = "azure_cosmos";
type RuntimeConfig = AzureCosmosKeyValueRuntimeConfig;
type StoreManager = KeyValueAzureCosmos;
fn make_store(
&self,
runtime_config: Self::RuntimeConfig,
) -> anyhow::Result<Self::StoreManager> {
let auth_options = match runtime_config.key {
Some(key) => KeyValueAzureCosmosAuthOptions::RuntimeConfigValues(
KeyValueAzureCosmosRuntimeConfigOptions::new(key),
),
None => KeyValueAzureCosmosAuthOptions::Environmental,
};
KeyValueAzureCosmos::new(
runtime_config.account,
runtime_config.database,
runtime_config.container,
auth_options,
)
}
}