Skip to content

Commit

Permalink
factors: Update AzureCosmosKeyValueRuntimeConfig
Browse files Browse the repository at this point in the history
Signed-off-by: Lann Martin <[email protected]>
  • Loading branch information
lann committed Jul 26, 2024
1 parent c387dfb commit b7af6d9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions crates/factor-key-value-azure/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use serde::Deserialize;
use spin_factor_key_value::MakeKeyValueStore;
use spin_key_value_azure::KeyValueAzureCosmos;
use spin_key_value_azure::{
KeyValueAzureCosmos, KeyValueAzureCosmosAuthOptions, KeyValueAzureCosmosRuntimeConfigOptions,
};

/// A key-value store that uses Azure Cosmos as the backend.
pub struct AzureKeyValueStore;
Expand All @@ -9,7 +11,7 @@ pub struct AzureKeyValueStore;
#[derive(Deserialize)]
pub struct AzureCosmosKeyValueRuntimeConfig {
/// The authorization token for the Azure Cosmos DB account.
key: String,
key: Option<String>,
/// The Azure Cosmos DB account name.
account: String,
/// The Azure Cosmos DB database.
Expand All @@ -30,11 +32,17 @@ impl MakeKeyValueStore for AzureKeyValueStore {
&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.key,
runtime_config.account,
runtime_config.database,
runtime_config.container,
auth_options,
)
}
}

0 comments on commit b7af6d9

Please sign in to comment.