Skip to content

Commit ae61e0e

Browse files
authored
Add if-match condition to PutAppendBlob (Azure#1658)
* Add if-match condition to PutAppendBlob * Add if-modified-since
1 parent 1e5aabe commit ae61e0e

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Diff for: sdk/storage_blobs/src/blob/operations/put_append_blob.rs

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ operation! {
1111
?content_disposition: BlobContentDisposition,
1212
?metadata: Metadata,
1313
?tags: Tags,
14+
?if_modified_since: IfModifiedSinceCondition,
15+
?if_match: IfMatchCondition,
1416
?lease_id: LeaseId
1517
}
1618

@@ -31,6 +33,8 @@ impl PutAppendBlobBuilder {
3133
headers.add(m);
3234
}
3335
}
36+
headers.add(self.if_modified_since);
37+
headers.add(self.if_match);
3438
headers.add(self.lease_id);
3539

3640
let mut request =

Diff for: sdk/storage_blobs/tests/append_blob.rs

+59
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,62 @@ async fn put_append_blob() {
6161
assert_eq!(resp.metadata.get("second"), Some(Bytes::from("something")));
6262
assert_eq!(resp.metadata.get("not_found"), None);
6363
}
64+
65+
#[tokio::test]
66+
async fn put_append_blob_if_match() {
67+
let account =
68+
std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!");
69+
let access_key =
70+
std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");
71+
72+
let blob_name: &'static str = "create_once.txt";
73+
let container_name: &'static str = "rust-if-match";
74+
75+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
76+
let blob_service = BlobServiceClient::new(account, storage_credentials);
77+
let container = blob_service.container_client(container_name);
78+
let blob = container.blob_client(blob_name);
79+
80+
if !blob_service
81+
.list_containers()
82+
.into_stream()
83+
.next()
84+
.await
85+
.unwrap()
86+
.unwrap()
87+
.containers
88+
.iter()
89+
.any(|x| x.name == container_name)
90+
{
91+
container
92+
.create()
93+
.public_access(PublicAccess::None)
94+
.await
95+
.unwrap();
96+
}
97+
98+
let _ = blob.delete().await;
99+
100+
blob.put_append_blob()
101+
.content_type("text/plain")
102+
.if_match(IfMatchCondition::NotMatch("*".into()))
103+
.await
104+
.unwrap();
105+
106+
trace!("created {:?}", blob_name);
107+
108+
let result = blob
109+
.put_append_blob()
110+
.content_type("text/plain")
111+
.if_match(IfMatchCondition::NotMatch("*".into()))
112+
.await
113+
.unwrap_err();
114+
115+
assert_eq!(
116+
result.kind(),
117+
&azure_core::error::ErrorKind::HttpResponse {
118+
status: azure_core::StatusCode::Conflict,
119+
error_code: Some("BlobAlreadyExists".into())
120+
}
121+
);
122+
}

0 commit comments

Comments
 (0)