azure_storage_blob/models/method_options.rs
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4use std::{collections::HashMap, num::NonZero};
5
6use azure_core::{
7 fmt::SafeDebug,
8 http::{ClientMethodOptions, Etag},
9};
10use time::OffsetDateTime;
11
12use crate::models::{
13 AccessTier, BlobClientDownloadInternalOptions, EncryptionAlgorithmType, HttpRange,
14 ImmutabilityPolicyMode,
15};
16
17/// Options to be passed to `BlobClient::download()`
18#[derive(Clone, Default, SafeDebug)]
19pub struct BlobClientDownloadOptions<'a> {
20 /// The algorithm used to produce the encryption key hash. Must be provided if the encryption key is provided.
21 pub encryption_algorithm: Option<EncryptionAlgorithmType>,
22
23 /// Specifies the encryption key to use to encrypt the data provided in the request.
24 pub encryption_key: Option<String>,
25
26 /// The SHA-256 hash of the provided encryption key. Must be provided if the encryption key is provided.
27 pub encryption_key_sha256: Option<String>,
28
29 /// Specify this value to operate only on a blob with a matching Etag value.
30 pub if_match: Option<Etag>,
31
32 /// Specify this value to operate only on a blob if it has been modified since the specified date-time.
33 pub if_modified_since: Option<OffsetDateTime>,
34
35 /// Specify this value to operate only on a blob with a non-matching Etag value.
36 pub if_none_match: Option<Etag>,
37
38 /// Specifies a SQL-like where clause on blob tags to operate only on a blob with matching tags.
39 pub if_tags: Option<String>,
40
41 /// Specify this value to operate only on a blob if it has not been modified since the specified date-time.
42 pub if_unmodified_since: Option<OffsetDateTime>,
43
44 /// If specified, the operation only succeeds if the resource's lease is active and matches this ID.
45 pub lease_id: Option<String>,
46
47 /// Allows customization of the method call.
48 pub method_options: ClientMethodOptions<'a>,
49
50 /// Optional. Number of concurrent network transfers to maintain for this operation.
51 /// A default value will be chosen if none is provided.
52 pub parallel: Option<NonZero<usize>>,
53
54 /// Optional. Size to partition data into.
55 /// A default value will be chosen if none is provided.
56 pub partition_size: Option<NonZero<usize>>,
57
58 /// Optional range of the blob to download.
59 ///
60 /// Accepts an [`HttpRange`] value. You can convert from standard Rust range types
61 /// using `.into()`, for example `(0..100u64).into()` or `(100u64..).into()`.
62 ///
63 /// When set to `None`, the entire blob will be downloaded.
64 pub range: Option<HttpRange>,
65
66 /// When set to true and the request includes a Range header, the service returns the CRC64 hash for the range, as long as
67 /// the range is less than or equal to 4 MiB in size.
68 pub range_get_content_crc64: Option<bool>,
69
70 /// When set to true and specified together with the `Range` header, the service returns the MD5 hash for the range, as long
71 /// as the range is less than or equal to 4 MiB in size.
72 pub range_get_content_md5: Option<bool>,
73
74 /// Specifies the snapshot of the blob.
75 pub snapshot: Option<String>,
76
77 /// The timeout parameter is expressed in seconds. For more information, see [Setting Timeouts for Blob Service Operations.](https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations)
78 pub timeout: Option<i32>,
79
80 /// Specifies the version ID of the blob.
81 pub version_id: Option<String>,
82}
83
84impl<'a> From<BlobClientDownloadOptions<'a>> for BlobClientDownloadInternalOptions<'_> {
85 fn from(value: BlobClientDownloadOptions) -> Self {
86 // Construct exhaustively to catch new options.
87 Self {
88 encryption_algorithm: value.encryption_algorithm,
89 encryption_key: value.encryption_key,
90 encryption_key_sha256: value.encryption_key_sha256,
91 if_match: value.if_match,
92 if_modified_since: value.if_modified_since,
93 if_none_match: value.if_none_match,
94 if_tags: value.if_tags,
95 if_unmodified_since: value.if_unmodified_since,
96 lease_id: value.lease_id,
97 // requires into_owned due to BlobClientDownloadBehavior w/ 'static Behavior
98 method_options: ClientMethodOptions {
99 context: value.method_options.context.into_owned(),
100 },
101 range: None,
102 range_get_content_crc64: value.range_get_content_crc64,
103 range_get_content_md5: value.range_get_content_md5,
104 snapshot: value.snapshot,
105 structured_body_type: None,
106 timeout: value.timeout,
107 version_id: value.version_id,
108 }
109 }
110}
111
112/// Options to be passed to `BlockBlobClient::upload()`
113#[derive(Clone, Default, SafeDebug)]
114pub struct BlockBlobClientUploadOptions<'a> {
115 /// Specifies the blob's Cache-Control. If specified, this property is stored with the blob and returned with a read request.
116 pub blob_cache_control: Option<String>,
117
118 /// Specifies the blob's Content-Disposition. If specified, this property is stored with the blob and returned with a read
119 /// request.
120 pub blob_content_disposition: Option<String>,
121
122 /// Specifies the blob's Content-Encoding. If specified, this property is stored with the blob and returned with a read request.
123 pub blob_content_encoding: Option<String>,
124
125 /// Specifies the blob's Content-Language. If specified, this property is stored with the blob and returned with a read request.
126 pub blob_content_language: Option<String>,
127
128 /// The MD5 hash of the blob content that is stored as a property on the blob. Note: This hash is not validated.
129 pub blob_content_md5: Option<Vec<u8>>,
130
131 /// Specifies the blob's Content-Type. If specified, this property is stored with the blob and returned with a read request.
132 pub blob_content_type: Option<String>,
133
134 /// The blob tags.
135 ///
136 /// This is the percent-encoded `x-ms-tags` header value (`key=value&key2=value2`).
137 /// Use [`Self::with_tags`] to set this from a `HashMap<String, String>` or `BlobTags`.
138 pub blob_tags_string: Option<String>,
139
140 /// The algorithm used to produce the encryption key hash. Must be provided if the encryption key is provided.
141 pub encryption_algorithm: Option<EncryptionAlgorithmType>,
142
143 /// Specifies the encryption key to use to encrypt the data provided in the request.
144 pub encryption_key: Option<String>,
145
146 /// The SHA-256 hash of the provided encryption key. Must be provided if the encryption key is provided.
147 pub encryption_key_sha256: Option<String>,
148
149 /// Specifies the encryption scope used to encrypt the data.
150 pub encryption_scope: Option<String>,
151
152 /// The date-time that indicates the time at which the blob immutability policy will expire.
153 pub immutability_policy_expiry: Option<OffsetDateTime>,
154
155 /// Indicates the immutability policy mode of the blob.
156 pub immutability_policy_mode: Option<ImmutabilityPolicyMode>,
157
158 /// Specify this value to operate only on a blob with a matching Etag value.
159 pub if_match: Option<Etag>,
160
161 /// Specify this value to operate only on a blob if it has been modified since the specified date-time.
162 pub if_modified_since: Option<OffsetDateTime>,
163
164 /// Specify this value to operate only on a blob with a non-matching Etag value.
165 pub if_none_match: Option<Etag>,
166
167 /// Specifies a SQL-like where clause on blob tags to operate only on a blob with matching tags.
168 pub if_tags: Option<String>,
169
170 /// Specify this value to operate only on a blob if it has not been modified since the specified date-time.
171 pub if_unmodified_since: Option<OffsetDateTime>,
172
173 /// If specified, the operation only succeeds if the resource's lease is active and matches this ID.
174 pub lease_id: Option<String>,
175
176 /// Indicates whether the blob has a legal hold.
177 pub legal_hold: Option<bool>,
178
179 /// The metadata headers.
180 pub metadata: Option<HashMap<String, String>>,
181
182 /// Allows customization of the method call.
183 pub method_options: ClientMethodOptions<'a>,
184
185 /// Optional. Number of concurrent network transfers to maintain for this operation.
186 /// A default value will be chosen if none is provided.
187 pub parallel: Option<NonZero<usize>>,
188
189 /// Optional. Size to partition data into.
190 /// A default value will be chosen if none is provided.
191 pub partition_size: Option<NonZero<u64>>,
192
193 /// Optional. The server-side timeout to apply on each individual request. This is not a timeout for the whole operation.
194 /// The timeout parameter is expressed in seconds. For more information, see
195 /// [Setting Timeouts for Blob Service Operations.](https://docs.microsoft.com/rest/api/storageservices/fileservices/setting-timeouts-for-blob-service-operations)
196 pub per_request_timeout: Option<i32>,
197
198 /// The tier to be set on the blob.
199 pub tier: Option<AccessTier>,
200}