google_cloud_storage/http/objects/
compose.rs

1use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
2
3use crate::http::object_access_controls::PredefinedObjectAcl;
4use crate::http::objects::{Encryption, Object, SourceObjects};
5use crate::http::Escape;
6
7/// Request message for ComposeObject.
8#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
9#[serde(rename_all = "camelCase")]
10pub struct ComposeObjectRequest {
11    /// Required. Name of the bucket containing the source objects. The destination object is
12    /// stored in this bucket.
13    #[serde(skip_serializing)]
14    pub bucket: String,
15    /// Required. Name of the new object.
16    #[serde(skip_serializing)]
17    pub destination_object: String,
18    /// Apply a predefined set of access controls to the destination object.
19    pub destination_predefined_acl: Option<PredefinedObjectAcl>,
20    #[serde(skip_serializing)]
21    pub composing_targets: ComposingTargets,
22    /// Makes the operation conditional on whether the object's current generation
23    /// matches the given value. Setting to 0 makes the operation succeed only if
24    /// there are no live versions of the object.
25    pub if_generation_match: Option<i64>,
26    /// Makes the operation conditional on whether the object's current
27    /// metageneration matches the given value.
28    pub if_metageneration_match: Option<i64>,
29    /// Resource name of the Cloud KMS key, of the form
30    /// `projects/my-project/locations/my-location/keyRings/my-kr/cryptoKeys/my-key`,
31    /// that will be used to encrypt the object. Overrides the object
32    /// metadata's `kms_key_name` value, if any.
33    pub kms_key_name: Option<String>,
34    /// A set of parameters common to Storage API requests concerning an object.
35    #[serde(skip_serializing)]
36    pub encryption: Option<Encryption>,
37}
38
39#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
40#[serde(rename_all = "camelCase")]
41pub struct ComposingTargets {
42    /// Properties of the resulting object.
43    pub destination: Option<Object>,
44    /// The list of source objects that will be concatenated into a single object.
45    pub source_objects: Vec<SourceObjects>,
46}
47
48pub(crate) fn build(base_url: &str, client: &Client, req: &ComposeObjectRequest) -> RequestBuilder {
49    let url = format!(
50        "{}/b/{}/o/{}/compose",
51        base_url,
52        req.bucket.escape(),
53        req.destination_object.escape()
54    );
55    let builder = client.post(url).query(&req).json(&req.composing_targets);
56    if let Some(e) = &req.encryption {
57        e.with_headers(builder)
58    } else {
59        builder
60    }
61}