Skip to content

Commit

Permalink
Create new response struct for AppendBlock, exposing ETag, blob_appen…
Browse files Browse the repository at this point in the history
…d_offset and blob_committed_block_count (#1965)

* Create bespoke response struct for AppendBlock operation exposing ETag

* Expose blob_append_offset and blob_commited_block_count

* Cargo fmt
  • Loading branch information
LeonHartley authored Jan 10, 2025
1 parent f66078b commit dce289d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions sdk/core/src/headers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ pub const WWW_AUTHENTICATE: HeaderName = HeaderName::from_static("www-authentica
pub const ENCRYPTION_ALGORITHM: HeaderName = HeaderName::from_static("x-ms-encryption-algorithm");
pub const ENCRYPTION_KEY: HeaderName = HeaderName::from_static("x-ms-encryption-key");
pub const ENCRYPTION_KEY_SHA256: HeaderName = HeaderName::from_static("x-ms-encryption-key-sha256");
pub const BLOB_APPEND_OFFSET: HeaderName = HeaderName::from_static("x-ms-blob-append-offset");
pub const BLOB_COMMITTED_BLOCK_COUNT: HeaderName =
HeaderName::from_static("x-ms-blob-committed-block-count");
pub const AZURE_ASYNCOPERATION: HeaderName = HeaderName::from_static("azure-asyncoperation");
Expand Down
44 changes: 40 additions & 4 deletions sdk/storage_blobs/src/blob/operations/append_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::{blob::operations::put_block::PutBlockResponse, prelude::*};
use azure_core::{headers::*, prelude::*, Body};
use crate::prelude::*;
use azure_core::{headers::*, prelude::*, Body, RequestId};
use azure_storage::headers::consistency_from_headers;
use azure_storage::{ConsistencyCRC64, ConsistencyMD5};
use time::OffsetDateTime;

operation! {
AppendBlock,
Expand Down Expand Up @@ -39,9 +42,42 @@ impl AppendBlockBuilder {

let response = self.client.send(&mut self.context, &mut request).await?;

PutBlockResponse::from_headers(response.headers())
AppendBlockResponse::from_headers(response.headers())
})
}
}

type AppendBlockResponse = PutBlockResponse;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AppendBlockResponse {
pub etag: String,
pub content_md5: Option<ConsistencyMD5>,
pub content_crc64: Option<ConsistencyCRC64>,
pub request_id: RequestId,
pub date: OffsetDateTime,
pub request_server_encrypted: bool,
pub blob_append_offset: u64,
pub blob_committed_block_count: u64,
}

impl AppendBlockResponse {
pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<AppendBlockResponse> {
let etag = etag_from_headers(headers)?;
let (content_md5, content_crc64) = consistency_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
let request_server_encrypted = request_server_encrypted_from_headers(headers)?;
let blob_append_offset = headers.get_as(&BLOB_APPEND_OFFSET)?;
let blob_committed_block_count = headers.get_as(&BLOB_COMMITTED_BLOCK_COUNT)?;

Ok(AppendBlockResponse {
etag,
content_md5,
content_crc64,
request_id,
date,
request_server_encrypted,
blob_append_offset,
blob_committed_block_count,
})
}
}

0 comments on commit dce289d

Please sign in to comment.