google_cloud_storage/http/objects/
patch.rs

1use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
2
3use crate::http::bucket_access_controls::PredefinedBucketAcl;
4use crate::http::object_access_controls::Projection;
5use crate::http::objects::{Encryption, Object};
6use crate::http::Escape;
7
8/// Request message for PatchObject.
9#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
10#[serde(rename_all = "camelCase")]
11pub struct PatchObjectRequest {
12    /// Required. Name of the bucket in which the object resides.
13    #[serde(skip_serializing)]
14    pub bucket: String,
15    /// Required. Name of the object.
16    #[serde(skip_serializing)]
17    pub object: String,
18    /// If present, selects a specific revision of this object (as opposed to the
19    /// latest version, the default).
20    pub generation: Option<i64>,
21    /// Makes the operation conditional on whether the object's current generation
22    /// matches the given value. Setting to 0 makes the operation succeed only if
23    /// there are no live versions of the object.
24    pub if_generation_match: Option<i64>,
25    /// Makes the operation conditional on whether the object's current generation
26    /// does not match the given value. If no live object exists, the precondition
27    /// fails. Setting to 0 makes the operation succeed only if there is a live
28    /// version of the object.
29    pub if_generation_not_match: Option<i64>,
30    /// Makes the operation conditional on whether the object's current
31    /// metageneration matches the given value.
32    pub if_metageneration_match: Option<i64>,
33    /// Makes the operation conditional on whether the object's current
34    /// metageneration does not match the given value.
35    pub if_metageneration_not_match: Option<i64>,
36    /// Apply a predefined set of access controls to this object.
37    pub predefined_acl: Option<PredefinedBucketAcl>,
38    /// Set of properties to return. Defaults to `FULL`.
39    pub projection: Option<Projection>,
40    /// The Object metadata for updating.
41    #[serde(skip_serializing)]
42    pub metadata: Option<Object>,
43    /// A set of parameters common to Storage API requests concerning an object.
44    #[serde(skip_serializing)]
45    pub encryption: Option<Encryption>,
46}
47
48pub(crate) fn build(base_url: &str, client: &Client, req: &PatchObjectRequest) -> RequestBuilder {
49    let url = format!("{}/b/{}/o/{}", base_url, req.bucket.escape(), req.object.escape());
50    let builder = client.patch(url).query(&req).json(&req.metadata);
51    if let Some(e) = &req.encryption {
52        e.with_headers(builder)
53    } else {
54        builder
55    }
56}