Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion services/azure-storage/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::collections::HashMap;
use std::env;

use anyhow::Result;

use crate::{connection_string, Service};

/// Config carries all the configuration for Azure Storage services.
#[derive(Clone, Default)]
#[cfg_attr(test, derive(Debug))]
#[cfg_attr(test, derive(Debug, PartialEq))]
pub struct Config {
/// `account_name` will be loaded from
///
Expand Down Expand Up @@ -86,6 +90,9 @@ const AZURE_PUBLIC_CLOUD: &str = "https://login.microsoftonline.com";

impl Config {
/// Load config from env.
///
/// Note that some values looked at by this method are specific to Azure
/// Blob Storage.
pub fn from_env(mut self) -> Self {
let envs = env::vars().collect::<HashMap<_, _>>();

Expand Down Expand Up @@ -126,4 +133,25 @@ impl Config {

self
}

/// Parses an [Azure connection string][1] into a configuration object.
///
/// The connection string doesn't have to specify all required parameters
/// because the user is still allowed to set them later directly on the object.
///
/// The function takes a Service parameter because it determines the fields used
/// to parse the endpoint.
///
/// An example of a connection string looks like:
///
/// ```txt
/// AccountName=mystorageaccount;
/// AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
/// BlobEndpoint=https://mystorageaccount.blob.core.windows.net
/// ```
///
/// [1]: https://learn.microsoft.com/en-us/azure/storage/common/storage-configure-connection-string
pub fn try_from_connection_string(conn_str: &str, service: &Service) -> Result<Self> {
connection_string::parse(conn_str, service)
}
}
Loading