google_cloud_storage/http/objects/copy.rs
1use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
2
3use crate::http::objects::{Encryption, Object};
4use crate::http::{object_access_controls::Projection, Escape};
5/// Request message for GetObject.
6#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug, Default)]
7#[serde(rename_all = "camelCase")]
8pub struct CopyObjectRequest {
9 /// Name of the new object. Required when the object metadata is not otherwise provided. Overrides the object metadata's name value, if any.
10 pub destination_bucket: String,
11 /// Name of the new object. Required when the object metadata is not otherwise provided. Overrides the object metadata's name value, if any.
12 pub destination_object: String,
13 // Name of the source object. For information about how to URL encode object names to be path safe, see Encoding URI path parts.
14 pub source_object: String,
15 /// Name of the bucket in which to find the source object.
16 #[serde(skip_serializing)]
17 pub source_bucket: String,
18
19 /// Makes the operation conditional on there being a live destination object with a generation number that matches the given value. Setting ifGenerationMatch to 0 makes the operation succeed only if there is no live destination object.
20 pub if_generation_match: Option<i64>,
21 /// Makes the operation conditional on there being a live destination object with a generation number that does not match the given value. If no live destination object exists, the precondition fails. Setting ifGenerationNotMatch to 0 makes the operation succeed if there is a live version of the object.
22 pub if_generation_not_match: Option<i64>,
23 /// Makes the operation conditional on there being a live destination object with a metageneration number that matches the given value.
24 pub if_metageneration_match: Option<i64>,
25 /// Makes the operation conditional on there being a live destination object with a metageneration number that does not match the given value.
26 pub if_metageneration_not_match: Option<i64>,
27 /// Makes the operation conditional on whether the source object's generation matches the given value.
28 pub if_source_generation_match: Option<i64>,
29 /// Makes the operation conditional on whether the source object's generation does not match the given value.
30 pub if_source_generation_not_match: Option<i64>,
31 /// Makes the operation conditional on whether the source object's current metageneration matches the given value.
32 pub if_source_metageneration_match: Option<i64>,
33 /// Makes the operation conditional on whether the source object's current metageneration does not match the given value.
34 pub if_source_metageneration_not_match: Option<i64>,
35 /// Set of properties to return. Defaults to noAcl, unless the object resource specifies the acl property, when it defaults to full.
36 ///
37 /// Acceptable values are:
38 /// full: Include all properties.
39 /// noAcl: Omit the owner, acl property.
40 pub projection: Option<Projection>,
41 /// If present, selects a specific revision of the source object (as opposed to the latest version, the default)
42 pub source_generation: Option<i64>,
43 /// The Object metadata for updating.
44 #[serde(skip_serializing)]
45 pub metadata: Option<Object>,
46
47 #[serde(skip_serializing)]
48 pub encryption: Option<Encryption>,
49}
50
51pub(crate) fn build(base_url: &str, client: &Client, req: &CopyObjectRequest) -> RequestBuilder {
52 let url = format!(
53 "{}/b/{}/o/{}/copyTo/b/{}/o/{}",
54 base_url,
55 req.source_bucket.escape(),
56 req.source_object.escape(),
57 req.destination_bucket.escape(),
58 req.destination_object.escape()
59 );
60 let builder = client.post(url).query(&req).json(&req.metadata);
61 if let Some(e) = &req.encryption {
62 e.with_headers(builder)
63 } else {
64 builder
65 }
66}