google_cloud_storage/http/objects/
mod.rs

1use std::collections::HashMap;
2
3use reqwest_middleware::RequestBuilder;
4
5use time::OffsetDateTime;
6
7use crate::http::object_access_controls::ObjectAccessControl;
8
9pub mod compose;
10pub mod copy;
11pub mod delete;
12pub mod download;
13pub mod get;
14pub mod list;
15
16pub mod r#move;
17pub mod patch;
18pub mod rewrite;
19pub mod upload;
20pub mod watch_all;
21
22/// An object.
23#[derive(Clone, PartialEq, Eq, Default, serde::Deserialize, serde::Serialize, Debug)]
24#[serde(rename_all = "camelCase")]
25pub struct Object {
26    /// The link to this object.
27    #[serde(skip_serializing_if = "String::is_empty")]
28    pub self_link: String,
29    /// The media link to this object.
30    #[serde(skip_serializing_if = "String::is_empty")]
31    pub media_link: String,
32    /// Content-Encoding of the object data, matching
33    /// \[<https://tools.ietf.org/html/rfc7231#section-3.1.2.2\][RFC> 7231 §3.1.2.2]
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub content_encoding: Option<String>,
36    /// Content-Disposition of the object data, matching
37    /// \[<https://tools.ietf.org/html/rfc6266\][RFC> 6266].
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub content_disposition: Option<String>,
40    /// Cache-Control directive for the object data, matching
41    /// \[<https://tools.ietf.org/html/rfc7234#section-5.2"\][RFC> 7234 §5.2].
42    /// If omitted, and the object is accessible to all anonymous users, the
43    /// default will be `public, max-age=3600`.
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub cache_control: Option<String>,
46    /// Access controls on the object.
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub acl: Option<Vec<ObjectAccessControl>>,
49    /// Content-Language of the object data, matching
50    /// \[<https://tools.ietf.org/html/rfc7231#section-3.1.3.2\][RFC> 7231 §3.1.3.2].
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub content_language: Option<String>,
53    /// The version of the metadata for this object at this generation. Used for
54    /// preconditions and for detecting changes in metadata. A metageneration
55    /// number is only meaningful in the context of a particular generation of a
56    /// particular object.
57    /// Attempting to set or update this field will result in a
58    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
59    #[serde(skip_serializing_if = "crate::http::is_i64_zero")]
60    #[serde(deserialize_with = "crate::http::from_str")]
61    pub metageneration: i64,
62    /// The deletion time of the object. Will be returned if and only if this
63    /// version of the object has been deleted.
64    /// Attempting to set or update this field will result in a
65    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
66    #[serde(skip_serializing_if = "Option::is_none")]
67    #[serde(default, with = "time::serde::rfc3339::option")]
68    pub time_deleted: Option<OffsetDateTime>,
69    /// Content-Type of the object data, matching
70    /// \[<https://tools.ietf.org/html/rfc7231#section-3.1.1.5\][RFC> 7231 §3.1.1.5].
71    /// If an object is stored without a Content-Type, it is served as
72    /// `application/octet-stream`.
73    #[serde(skip_serializing_if = "Option::is_none")]
74    pub content_type: Option<String>,
75    /// Content-Length of the object data in bytes, matching
76    /// \[<https://tools.ietf.org/html/rfc7230#section-3.3.2\][RFC> 7230 §3.3.2].
77    /// Attempting to set or update this field will result in a
78    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
79    #[serde(skip_serializing_if = "crate::http::is_i64_zero")]
80    #[serde(deserialize_with = "crate::http::from_str")]
81    #[serde(default)]
82    pub size: i64,
83    /// The creation time of the object.
84    /// Attempting to set or update this field will result in a
85    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
86    #[serde(skip_serializing_if = "Option::is_none")]
87    #[serde(default, with = "time::serde::rfc3339::option")]
88    pub time_created: Option<OffsetDateTime>,
89    /// CRC32c checksum. For more information about using the CRC32c
90    /// checksum, see
91    /// \[<https://cloud.google.com/storage/docs/hashes-etags#json-api\][Hashes> and
92    /// ETags: Best Practices]. This is a server determined value and should not be
93    /// supplied by the user when sending an Object. The server will ignore any
94    /// value provided. Users should instead use the object_checksums field on the
95    /// InsertObjectRequest when uploading an object.
96    #[serde(skip_serializing_if = "Option::is_none")]
97    pub crc32c: Option<String>,
98    /// MD5 hash of the data; encoded using base64 as per
99    /// \[<https://tools.ietf.org/html/rfc4648#section-4\][RFC> 4648 §4]. For more
100    /// information about using the MD5 hash, see
101    /// \[<https://cloud.google.com/storage/docs/hashes-etags#json-api\][Hashes> and
102    /// ETags: Best Practices]. This is a server determined value and should not be
103    /// supplied by the user when sending an Object. The server will ignore any
104    /// value provided. Users should instead use the object_checksums field on the
105    /// InsertObjectRequest when uploading an object.
106    #[serde(skip_serializing_if = "Option::is_none")]
107    pub md5_hash: Option<String>,
108    /// HTTP 1.1 Entity tag for the object. See
109    /// \[<https://tools.ietf.org/html/rfc7232#section-2.3\][RFC> 7232 §2.3].
110    /// Attempting to set or update this field will result in a
111    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
112    #[serde(skip_serializing_if = "String::is_empty")]
113    #[serde(default)]
114    pub etag: String,
115    /// The modification time of the object metadata.
116    /// Attempting to set or update this field will result in a
117    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
118    #[serde(skip_serializing_if = "Option::is_none")]
119    #[serde(default, with = "time::serde::rfc3339::option")]
120    pub updated: Option<OffsetDateTime>,
121    /// Storage class of the object.
122    #[serde(skip_serializing_if = "Option::is_none")]
123    pub storage_class: Option<String>,
124    /// Cloud KMS Key used to encrypt this object, if the object is encrypted by
125    /// such a key.
126    #[serde(skip_serializing_if = "Option::is_none")]
127    pub kms_key_name: Option<String>,
128    /// The time at which the object's storage class was last changed. When the
129    /// object is initially created, it will be set to time_created.
130    /// Attempting to set or update this field will result in a
131    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
132    #[serde(skip_serializing_if = "Option::is_none")]
133    #[serde(default, with = "time::serde::rfc3339::option")]
134    pub time_storage_class_updated: Option<OffsetDateTime>,
135    /// Whether an object is under temporary hold. While this flag is set to true,
136    /// the object is protected against deletion and overwrites.  A common use case
137    /// of this flag is regulatory investigations where objects need to be retained
138    /// while the investigation is ongoing. Note that unlike event-based hold,
139    /// temporary hold does not impact retention expiration time of an object.
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub temporary_hold: Option<bool>,
142    /// A server-determined value that specifies the earliest time that the
143    /// object's retention period expires. This value is in
144    /// \[<https://tools.ietf.org/html/rfc3339\][RFC> 3339] format.
145    /// Note 1: This field is not provided for objects with an active event-based
146    /// hold, since retention expiration is unknown until the hold is removed.
147    /// Note 2: This value can be provided even when temporary hold is set (so that
148    /// the user can reason about policy without having to first unset the
149    /// temporary hold).
150    #[serde(skip_serializing_if = "Option::is_none")]
151    #[serde(default, with = "time::serde::rfc3339::option")]
152    pub retention_expiration_time: Option<OffsetDateTime>,
153    /// User-provided metadata, in key/value pairs.
154    #[serde(skip_serializing_if = "Option::is_none")]
155    pub metadata: Option<HashMap<String, String>>,
156    /// Whether an object is under event-based hold. Event-based hold is a way to
157    /// retain objects until an event occurs, which is signified by the
158    /// hold's release (i.e. this value is set to false). After being released (set
159    /// to false), such objects will be subject to bucket-level retention (if any).
160    /// One sample use case of this flag is for banks to hold loan documents for at
161    /// least 3 years after loan is paid in full. Here, bucket-level retention is 3
162    /// years and the event is the loan being paid in full. In this example, these
163    /// objects will be held intact for any number of years until the event has
164    /// occurred (event-based hold on the object is released) and then 3 more years
165    /// after that. That means retention duration of the objects begins from the
166    /// moment event-based hold transitioned from true to false.
167    #[serde(skip_serializing_if = "Option::is_none")]
168    pub event_based_hold: Option<bool>,
169    /// The name of the object.
170    /// Attempting to update this field after the object is created will result in
171    /// an error.
172    #[serde(skip_serializing_if = "String::is_empty")]
173    pub name: String,
174    /// The ID of the object, including the bucket name, object name, and
175    /// generation number.
176    /// Attempting to update this field after the object is created will result in
177    /// an error.
178    #[serde(skip_serializing_if = "String::is_empty")]
179    pub id: String,
180    /// The name of the bucket containing this object.
181    /// Attempting to update this field after the object is created will result in
182    /// an error.
183    #[serde(skip_serializing_if = "String::is_empty")]
184    pub bucket: String,
185    /// The content generation of this object. Used for object versioning.
186    /// Attempting to set or update this field will result in a
187    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
188    #[serde(skip_serializing_if = "crate::http::is_i64_zero")]
189    #[serde(deserialize_with = "crate::http::from_str")]
190    pub generation: i64,
191    /// The owner of the object. This will always be the uploader of the object.
192    /// Attempting to set or update this field will result in a
193    /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
194    #[serde(skip_serializing_if = "Option::is_none")]
195    pub owner: Option<Owner>,
196    /// Metadata of customer-supplied encryption key, if the object is encrypted by
197    /// such a key.
198    #[serde(skip_serializing_if = "Option::is_none")]
199    pub customer_encryption: Option<CustomerEncryption>,
200    /// A user-specified timestamp set on an object.
201    #[serde(skip_serializing_if = "Option::is_none")]
202    #[serde(default, with = "time::serde::rfc3339::option")]
203    pub custom_time: Option<OffsetDateTime>,
204}
205
206/// Describes the customer-specified mechanism used to store the data at rest.
207#[derive(Clone, PartialEq, Eq, Default, serde::Deserialize, serde::Serialize, Debug)]
208#[serde(rename_all = "camelCase")]
209pub struct CustomerEncryption {
210    /// The encryption algorithm.
211    pub encryption_algorithm: String,
212    /// SHA256 hash value of the encryption key.
213    pub key_sha256: String,
214}
215
216/// The owner of a specific resource.
217#[derive(Clone, PartialEq, Eq, Default, serde::Deserialize, serde::Serialize, Debug)]
218#[serde(rename_all = "camelCase")]
219pub struct Owner {
220    /// The entity, in the form `user-`*userId*.
221    #[serde(default)]
222    pub entity: String,
223    /// The ID for the entity.
224    pub entity_id: Option<String>,
225}
226
227/// Description of a source object for a composition request.
228#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
229#[serde(rename_all = "camelCase")]
230pub struct SourceObjects {
231    /// The source object's name. All source objects must reside in the same
232    /// bucket.
233    pub name: String,
234    /// The generation of this object to use as the source.
235    pub generation: Option<i64>,
236    /// Conditions that must be met for this operation to execute.
237    pub object_preconditions: Option<ObjectPreconditions>,
238}
239/// Preconditions for a source object of a composition request.
240#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
241#[serde(rename_all = "camelCase")]
242pub struct ObjectPreconditions {
243    /// Only perform the composition if the generation of the source object
244    /// that would be used matches this value.  If this value and a generation
245    /// are both specified, they must be the same value or the call will fail.
246    pub if_generation_match: Option<i64>,
247}
248
249/// Parameters that can be passed to any object request.
250#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
251#[serde(rename_all = "camelCase")]
252pub struct Encryption {
253    /// Encryption algorithm used with Customer-Supplied Encryption Keys feature.
254    pub encryption_algorithm: String,
255    /// Encryption key used with Customer-Supplied Encryption Keys feature.
256    pub encryption_key: String,
257    /// SHA256 hash of encryption key used with Customer-Supplied Encryption Keys
258    /// feature.
259    pub encryption_key_sha256: String,
260}
261
262impl Encryption {
263    pub(crate) fn with_headers(&self, builder: RequestBuilder) -> RequestBuilder {
264        builder
265            .header("X-Goog-Encryption-Algorithm", &self.encryption_algorithm)
266            .header("X-Goog-Encryption-Key", &self.encryption_key)
267            .header("X-Goog-Encryption-Key-Sha256", &self.encryption_key_sha256)
268    }
269}