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