wasmcloud_provider_blobstore_azure/
config.rs

1//! Configuration for blobstore-azblob capability provider
2//!
3//! See README.md for configuration options using environment variables, aws credentials files,
4//! and EC2 IAM authorizations.
5//!
6
7use anyhow::Result;
8use serde::Deserialize;
9use tracing::warn;
10
11use azure_storage::StorageCredentials;
12use wasmcloud_provider_sdk::core::secrets::SecretValue;
13use wasmcloud_provider_sdk::LinkConfig;
14
15/// Configuration for connecting to Azblob.
16#[derive(Clone, Default, Deserialize)]
17pub struct StorageConfig {
18    /// STORAGE_ACCOUNT, can be specified from environment
19    pub storage_account: String,
20
21    /// STORAGE_ACCESS_KEY, can be in environment
22    pub storage_access_key: String,
23}
24
25impl StorageConfig {
26    /// Build a [`StorageConfig`] from a link configuration
27    pub fn from_link_config(
28        LinkConfig {
29            config, secrets, ..
30        }: &LinkConfig,
31    ) -> Result<StorageConfig> {
32        // To support old workflows, accept but warn when getting the storage access key
33        // is not in secrets
34        if secrets.get("storage_access_key").is_none() {
35            warn!("secret [storage_access_key] was not found, checking for [STORAGE_ACCESS_KEY] in configuration. Please prefer using secrets for sensitive values.");
36        }
37        match (
38            config.get("STORAGE_ACCOUNT"),
39            secrets
40                .get("storage_access_key")
41                .and_then(SecretValue::as_string)
42                .or_else(|| config.get("STORAGE_ACCESS_KEY").map(String::as_str)),
43        ) {
44            (Some(account), Some(access_key)) => Ok(StorageConfig {
45                storage_account: account.to_string(),
46                storage_access_key: access_key.to_string(),
47            }),
48            _ => Err(anyhow::anyhow!(
49                "STORAGE_ACCOUNT and STORAGE_ACCESS_KEY must be set"
50            )),
51        }
52    }
53
54    /// Build an access key with the stored storage account and access key
55    pub fn access_key(self) -> StorageCredentials {
56        StorageCredentials::access_key(self.storage_account, self.storage_access_key)
57    }
58}