Skip to content

Commit 9b9d750

Browse files
committed
cargo fmt
Signed-off-by: itowlson <[email protected]>
1 parent d5a2548 commit 9b9d750

File tree

16 files changed

+550
-243
lines changed

16 files changed

+550
-243
lines changed

crates/blobstore-azure/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ mod store;
33
use serde::Deserialize;
44
use spin_factor_blobstore::runtime_config::spin::MakeBlobStore;
55
use store::{
6-
AzureContainerManager,
76
auth::{AzureBlobAuthOptions, AzureKeyAuth},
7+
AzureContainerManager,
88
};
99

1010
/// A key-value store that uses Azure Cosmos as the backend.
@@ -41,7 +41,10 @@ impl MakeBlobStore for AzureBlobStoreBuilder {
4141
runtime_config: Self::RuntimeConfig,
4242
) -> anyhow::Result<Self::ContainerManager> {
4343
let auth = match &runtime_config.key {
44-
Some(key) => AzureBlobAuthOptions::AccountKey(AzureKeyAuth::new(runtime_config.account.clone(), key.clone())),
44+
Some(key) => AzureBlobAuthOptions::AccountKey(AzureKeyAuth::new(
45+
runtime_config.account.clone(),
46+
key.clone(),
47+
)),
4548
None => AzureBlobAuthOptions::Environmental,
4649
};
4750

crates/blobstore-azure/src/store.rs

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::sync::Arc;
33
use anyhow::Result;
44
use azure_storage_blobs::prelude::{BlobServiceClient, ContainerClient};
55
use spin_core::async_trait;
6-
use spin_factor_blobstore::{Error, Container, ContainerManager};
6+
use spin_factor_blobstore::{Container, ContainerManager, Error};
77

88
pub mod auth;
99
mod incoming_data;
@@ -18,21 +18,25 @@ pub struct AzureContainerManager {
1818
}
1919

2020
impl AzureContainerManager {
21-
pub fn new(
22-
auth_options: AzureBlobAuthOptions,
23-
) -> Result<Self> {
21+
pub fn new(auth_options: AzureBlobAuthOptions) -> Result<Self> {
2422
let (account, credentials) = match auth_options {
25-
AzureBlobAuthOptions::AccountKey(config) => {
26-
(config.account.clone(), azure_storage::StorageCredentials::access_key(&config.account, config.key.clone()))
27-
},
23+
AzureBlobAuthOptions::AccountKey(config) => (
24+
config.account.clone(),
25+
azure_storage::StorageCredentials::access_key(&config.account, config.key.clone()),
26+
),
2827
AzureBlobAuthOptions::Environmental => {
2928
let account = std::env::var("STORAGE_ACCOUNT").expect("missing STORAGE_ACCOUNT");
30-
let access_key = std::env::var("STORAGE_ACCESS_KEY").expect("missing STORAGE_ACCOUNT_KEY");
31-
(account.clone(), azure_storage::StorageCredentials::access_key(account, access_key))
32-
},
29+
let access_key =
30+
std::env::var("STORAGE_ACCESS_KEY").expect("missing STORAGE_ACCOUNT_KEY");
31+
(
32+
account.clone(),
33+
azure_storage::StorageCredentials::access_key(account, access_key),
34+
)
35+
}
3336
};
3437

35-
let client = azure_storage_blobs::prelude::ClientBuilder::new(account, credentials).blob_service_client();
38+
let client = azure_storage_blobs::prelude::ClientBuilder::new(account, credentials)
39+
.blob_service_client();
3640
Ok(Self { client })
3741
}
3842
}
@@ -51,7 +55,10 @@ impl ContainerManager for AzureContainerManager {
5155
}
5256

5357
fn summary(&self, _store_name: &str) -> Option<String> {
54-
Some(format!("Azure blob storage account {}", self.client.account()))
58+
Some(format!(
59+
"Azure blob storage account {}",
60+
self.client.account()
61+
))
5562
}
5663
}
5764

@@ -101,17 +108,31 @@ impl Container for AzureContainer {
101108
Ok(self.client.blob_client(name).exists().await?)
102109
}
103110

104-
async fn object_info(&self, name: &str) -> anyhow::Result<spin_factor_blobstore::ObjectMetadata> {
111+
async fn object_info(
112+
&self,
113+
name: &str,
114+
) -> anyhow::Result<spin_factor_blobstore::ObjectMetadata> {
105115
let response = self.client.blob_client(name).get_properties().await?;
106116
Ok(spin_factor_blobstore::ObjectMetadata {
107117
name: name.to_string(),
108118
container: self.client.container_name().to_string(),
109-
created_at: response.blob.properties.creation_time.unix_timestamp().try_into().unwrap(),
119+
created_at: response
120+
.blob
121+
.properties
122+
.creation_time
123+
.unix_timestamp()
124+
.try_into()
125+
.unwrap(),
110126
size: response.blob.properties.content_length,
111127
})
112128
}
113129

114-
async fn get_data(&self, name: &str, start: u64, end: u64) -> anyhow::Result<Box<dyn spin_factor_blobstore::IncomingData>> {
130+
async fn get_data(
131+
&self,
132+
name: &str,
133+
start: u64,
134+
end: u64,
135+
) -> anyhow::Result<Box<dyn spin_factor_blobstore::IncomingData>> {
115136
// We can't use a Rust range because the Azure type does not accept inclusive ranges,
116137
// and we don't want to add 1 to `end` if it's already at MAX!
117138
let range = if end == u64::MAX {
@@ -123,12 +144,20 @@ impl Container for AzureContainer {
123144
Ok(Box::new(AzureIncomingData::new(client, range)))
124145
}
125146

126-
async fn connect_stm(&self, name: &str, stm: tokio::io::ReadHalf<tokio::io::SimplexStream>, finished_tx: tokio::sync::mpsc::Sender<anyhow::Result<()>>) -> anyhow::Result<()> {
147+
async fn connect_stm(
148+
&self,
149+
name: &str,
150+
stm: tokio::io::ReadHalf<tokio::io::SimplexStream>,
151+
finished_tx: tokio::sync::mpsc::Sender<anyhow::Result<()>>,
152+
) -> anyhow::Result<()> {
127153
let client = self.client.blob_client(name);
128154

129155
tokio::spawn(async move {
130156
let result = Self::connect_stm_core(stm, client).await;
131-
finished_tx.send(result).await.expect("should sent finish tx");
157+
finished_tx
158+
.send(result)
159+
.await
160+
.expect("should sent finish tx");
132161
});
133162

134163
Ok(())
@@ -141,7 +170,10 @@ impl Container for AzureContainer {
141170
}
142171

143172
impl AzureContainer {
144-
async fn connect_stm_core(mut stm: tokio::io::ReadHalf<tokio::io::SimplexStream>, client: azure_storage_blobs::prelude::BlobClient) -> anyhow::Result<()> {
173+
async fn connect_stm_core(
174+
mut stm: tokio::io::ReadHalf<tokio::io::SimplexStream>,
175+
client: azure_storage_blobs::prelude::BlobClient,
176+
) -> anyhow::Result<()> {
145177
use tokio::io::AsyncReadExt;
146178

147179
// Azure limits us to 50k blocks per blob. At 2MB/block that allows 100GB, which will be
@@ -162,22 +194,24 @@ impl AzureContainer {
162194
let id_bytes = uuid::Uuid::new_v4().as_bytes().to_vec();
163195
let block_id = azure_storage_blobs::prelude::BlockId::new(id_bytes);
164196
client.put_block(block_id.clone(), bytes).await?;
165-
blocks.push(azure_storage_blobs::blob::BlobBlockType::Uncommitted(block_id));
197+
blocks.push(azure_storage_blobs::blob::BlobBlockType::Uncommitted(
198+
block_id,
199+
));
166200
break 'put_blocks;
167201
}
168202
if len >= BLOCK_SIZE {
169203
let id_bytes = uuid::Uuid::new_v4().as_bytes().to_vec();
170204
let block_id = azure_storage_blobs::prelude::BlockId::new(id_bytes);
171205
client.put_block(block_id.clone(), bytes).await?;
172-
blocks.push(azure_storage_blobs::blob::BlobBlockType::Uncommitted(block_id));
206+
blocks.push(azure_storage_blobs::blob::BlobBlockType::Uncommitted(
207+
block_id,
208+
));
173209
break;
174210
}
175211
}
176212
}
177213

178-
let block_list = azure_storage_blobs::blob::BlockList {
179-
blocks
180-
};
214+
let block_list = azure_storage_blobs::blob::BlockList { blocks };
181215
client.put_block_list(block_list).await?;
182216

183217
Ok(())

crates/blobstore-azure/src/store/auth.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub enum AzureBlobAuthOptions {
1818
AccountKey(AzureKeyAuth),
1919
/// Spin should use the environment variables of the process to
2020
/// create the StorageCredentials for the storage client. For now this uses old school credentials:
21-
///
21+
///
2222
/// STORAGE_ACCOUNT
2323
/// STORAGE_ACCESS_KEY
24-
///
24+
///
2525
/// TODO: Thorsten pls make this proper with *hand waving* managed identity and stuff!
2626
Environmental,
2727
}

crates/blobstore-azure/src/store/incoming_data.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
use tokio::sync::Mutex;
21
use anyhow::Result;
3-
use futures::StreamExt;
4-
use spin_core::async_trait;
52
use azure_core::Pageable;
63
use azure_storage_blobs::blob::operations::GetBlobResponse;
74
use azure_storage_blobs::prelude::BlobClient;
5+
use futures::StreamExt;
6+
use spin_core::async_trait;
7+
use tokio::sync::Mutex;
88

99
pub struct AzureIncomingData {
1010
// The Mutex is used to make it Send
11-
stm: Mutex<Option<
12-
Pageable<
13-
GetBlobResponse,
14-
azure_core::error::Error
15-
>
16-
>>,
11+
stm: Mutex<Option<Pageable<GetBlobResponse, azure_core::error::Error>>>,
1712
client: BlobClient,
1813
}
1914

@@ -35,14 +30,18 @@ impl AzureIncomingData {
3530
wasmtime_wasi::pipe::AsyncReadStream::new(arr)
3631
}
3732

38-
fn consume_as_stream(&mut self) -> impl futures::stream::Stream<Item = Result<Vec<u8>, std::io::Error>> {
33+
fn consume_as_stream(
34+
&mut self,
35+
) -> impl futures::stream::Stream<Item = Result<Vec<u8>, std::io::Error>> {
3936
let opt_stm = self.stm.get_mut();
4037
let stm = opt_stm.take().unwrap();
4138
stm.flat_map(|chunk| streamify_chunk(chunk.unwrap().data))
4239
}
4340
}
4441

45-
fn streamify_chunk(chunk: azure_core::ResponseBody) -> impl futures::stream::Stream<Item = Result<Vec<u8>, std::io::Error>> {
42+
fn streamify_chunk(
43+
chunk: azure_core::ResponseBody,
44+
) -> impl futures::stream::Stream<Item = Result<Vec<u8>, std::io::Error>> {
4645
chunk.map(|c| Ok(c.unwrap().to_vec()))
4746
}
4847

@@ -76,6 +75,12 @@ impl spin_factor_blobstore::IncomingData for AzureIncomingData {
7675
// we do the first read. So that would force us to either pre-fetch the
7776
// first chunk or to issue a properties request *just in case* size() was
7877
// called. So I'm making it fallible for now.
79-
Ok(self.client.get_properties().await?.blob.properties.content_length)
78+
Ok(self
79+
.client
80+
.get_properties()
81+
.await?
82+
.blob
83+
.properties
84+
.content_length)
8085
}
8186
}

crates/blobstore-azure/src/store/object_names.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,21 @@ use spin_core::async_trait;
66

77
pub struct AzureObjectNames {
88
// The Mutex is used to make it Send
9-
stm: Mutex<
10-
Pageable<
11-
ListBlobsResponse,
12-
azure_core::error::Error
13-
>
14-
>,
9+
stm: Mutex<Pageable<ListBlobsResponse, azure_core::error::Error>>,
1510
read_but_not_yet_returned: Vec<String>,
1611
end_stm_after_read_but_not_yet_returned: bool,
1712
}
1813

1914
impl AzureObjectNames {
20-
pub fn new(stm: Pageable<
21-
ListBlobsResponse,
22-
azure_core::error::Error
23-
>) -> Self {
15+
pub fn new(stm: Pageable<ListBlobsResponse, azure_core::error::Error>) -> Self {
2416
Self {
2517
stm: Mutex::new(stm),
2618
read_but_not_yet_returned: Default::default(),
2719
end_stm_after_read_but_not_yet_returned: false,
2820
}
2921
}
3022

31-
async fn read_impl(&mut self, len: u64) -> anyhow::Result<(Vec<String>,bool)> {
23+
async fn read_impl(&mut self, len: u64) -> anyhow::Result<(Vec<String>, bool)> {
3224
use futures::StreamExt;
3325

3426
let len: usize = len.try_into().unwrap();
@@ -78,7 +70,7 @@ impl AzureObjectNames {
7870
#[async_trait]
7971
impl spin_factor_blobstore::ObjectNames for AzureObjectNames {
8072
async fn read(&mut self, len: u64) -> anyhow::Result<(Vec<String>, bool)> {
81-
self.read_impl(len).await // Separate function because rust-analyser gives better intellisense when async_trait isn't in the picture!
73+
self.read_impl(len).await // Separate function because rust-analyser gives better intellisense when async_trait isn't in the picture!
8274
}
8375

8476
async fn skip(&mut self, num: u64) -> anyhow::Result<(u64, bool)> {

0 commit comments

Comments
 (0)