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

Add missing conditional headers to blob and container operations #1280

Merged
merged 1 commit into from
May 15, 2023
Merged

Add missing conditional headers to blob and container operations #1280

merged 1 commit into from
May 15, 2023

Conversation

JWT95
Copy link
Contributor

@JWT95 JWT95 commented May 15, 2023

Overview

Fix #1276 and add the remaining conditional headers missing from blob and container operations as per the REST API documentation.

Testing

I tested the use case I care about, support for preventing duplicate blob writes, with the following code.

use azure_core::request_options::IfMatchCondition;
use azure_storage::prelude::StorageCredentials;
use azure_storage_blobs::prelude::BlobServiceClient;

#[tokio::main]
async fn main() {
    let token_credential = azure_identity::AzureCliCredential::default();
    let storage_credentials =
        StorageCredentials::token_credential(std::sync::Arc::new(token_credential));

    let blob_client = BlobServiceClient::new("<redacted>".to_string(), storage_credentials)
        .container_client("<redacted>")
        .blob_client("<redacted>");

    // Write blob
    let file = "Message One".as_bytes();
    blob_client
        .put_block_blob(file)
        .if_match(IfMatchCondition::NotMatch("*".into()))
        .await
        .expect("Failed to write message one");

    // Try to overwrite blob
    let file = "Message Two".as_bytes();
    blob_client
        .put_block_blob(file)
        .if_match(IfMatchCondition::NotMatch("*".into()))
        .await
        .expect("Failed to write message two");
}

The output was as expected:

thread 'main' panicked at 'Failed to write message two: Error { context: Full(Custom { kind: HttpResponse { status: Conflict, error_code: Some("BlobAlreadyExists") }, error: HttpError { status: Conflict, details: ErrorDetails { code: Some("BlobAlreadyExists"), message: None }...

@JWT95
Copy link
Contributor Author

JWT95 commented May 15, 2023

@microsoft-github-policy-service agree

@demoray
Copy link
Contributor

demoray commented May 15, 2023

Thank you for the contributions!

@demoray demoray merged commit 9ba8eaf into Azure:main May 15, 2023
8 checks passed
@JWT95 JWT95 deleted the put-block-blob-conditional-updates branch May 15, 2023 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PutBlockBlobBuilder doesn’t support conditional updates
2 participants