Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create new response struct for AppendBlock, exposing ETag, blob_append_offset and blob_committed_block_count #1965

Open
wants to merge 3 commits into
base: legacy
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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,
})
}
}