azure_storage_blobs/options/
blob_expiry.rs

1use azure_core::{date, headers::Headers};
2use time::OffsetDateTime;
3
4const EXPIRY_TIME: &str = "x-ms-expiry-time";
5const EXPIRY_OPTION: &str = "x-ms-expiry-option";
6
7#[derive(Debug, Clone)]
8pub enum BlobExpiry {
9    RelativeToCreation(u64),
10    RelativeToNow(u64),
11    Absolute(OffsetDateTime),
12    NeverExpire,
13}
14
15impl BlobExpiry {
16    pub fn to_headers(&self) -> Headers {
17        let mut headers = Headers::new();
18        match self {
19            BlobExpiry::RelativeToCreation(duration) => {
20                headers.insert(EXPIRY_OPTION, "RelativeToCreation");
21                headers.insert(EXPIRY_TIME, duration.to_string());
22            }
23            BlobExpiry::RelativeToNow(duration) => {
24                headers.insert(EXPIRY_OPTION, "RelativeToNow");
25                headers.insert(EXPIRY_TIME, duration.to_string());
26            }
27            BlobExpiry::Absolute(date) => {
28                headers.insert(EXPIRY_OPTION, "Absolute");
29                headers.insert(EXPIRY_TIME, date::to_rfc1123(date));
30            }
31            BlobExpiry::NeverExpire => {
32                headers.insert(EXPIRY_OPTION, "NeverExpire");
33            }
34        }
35        headers
36    }
37}