azure_storage_blobs/blob/operations/
snapshot_blob.rs

1use crate::prelude::*;
2use azure_core::headers::etag_from_headers;
3use azure_core::{
4    headers::{date_from_headers, last_modified_from_headers, request_id_from_headers, Headers},
5    prelude::*,
6    Method::Put,
7    RequestId,
8};
9use time::OffsetDateTime;
10
11operation! {
12    SnapshotBlob,
13    client: BlobClient,
14    ?metadata: Metadata,
15    ?if_modified_since: IfModifiedSinceCondition,
16    ?if_match: IfMatchCondition,
17    ?if_tags: IfTags,
18    ?lease_id: LeaseId
19}
20
21impl SnapshotBlobBuilder {
22    pub fn into_future(mut self) -> SnapshotBlob {
23        Box::pin(async move {
24            let mut url = self.client.url()?;
25
26            url.query_pairs_mut().append_pair("comp", "snapshot");
27
28            let mut headers = Headers::new();
29            headers.add(self.lease_id);
30            headers.add(self.if_modified_since);
31            headers.add(self.if_match);
32            headers.add(self.if_tags);
33            if let Some(metadata) = &self.metadata {
34                for m in metadata.iter() {
35                    headers.add(m);
36                }
37            }
38
39            let mut request = BlobClient::finalize_request(url, Put, headers, None)?;
40
41            let response = self.client.send(&mut self.context, &mut request).await?;
42            response.headers().try_into()
43        })
44    }
45}
46
47#[derive(Debug, Clone)]
48pub struct SnapshotBlobResponse {
49    pub request_id: RequestId,
50    pub etag: String,
51    pub date: OffsetDateTime,
52    pub snapshot: Snapshot,
53    pub last_modified: OffsetDateTime,
54}
55
56impl TryFrom<&Headers> for SnapshotBlobResponse {
57    type Error = azure_core::Error;
58
59    fn try_from(headers: &Headers) -> Result<Self, Self::Error> {
60        Ok(SnapshotBlobResponse {
61            request_id: request_id_from_headers(headers)?,
62            etag: etag_from_headers(headers)?,
63            date: date_from_headers(headers)?,
64            snapshot: Snapshot::new(headers.get_str(&SNAPSHOT)?.to_string()),
65            last_modified: last_modified_from_headers(headers)?,
66        })
67    }
68}