tame_gcs/v1/common.rs
1//! Types that are commone between different operations.
2
3use std::fmt;
4
5#[allow(clippy::trivially_copy_pass_by_ref)]
6fn pretty_on(pretty_print: &bool) -> bool {
7 *pretty_print
8}
9
10/// [Standard Query Parameters](https://cloud.google.com/storage/docs/json_api/v1/parameters#query)
11/// can be used in almost any API request to GCS
12#[derive(Serialize, Default)]
13#[serde(rename_all = "camelCase")]
14pub struct StandardQueryParameters<'a> {
15 /// Selector specifying a subset of fields to include in the response,
16 /// the primary use of this is for better performance and lower response
17 /// sizes.
18 /// For more information, see the [partial response](https://cloud.google.com/storage/docs/json_api/v1/how-tos/performance#partial)
19 /// documentation.
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub fields: Option<&'a str>,
22 /// Returns the response in a human-readable format, with indentations and
23 /// line breaks, if true. Note that while the default value is `true` for
24 /// GCP, this crate uses a default of `false`
25 #[serde(skip_serializing_if = "pretty_on")]
26 pub pretty_print: bool,
27 /// Lets you enforce per-user quotas from a server-side application even
28 /// in cases when the user's IP address is unknown. This can occur, for
29 /// example, with applications that run cron jobs on App Engine on a
30 /// user's behalf. You can choose any arbitrary string that uniquely
31 /// identifies a user, but it is limited to 40 characters. Overrides
32 /// `userIp` if both are provided. See more about [Capping API usage](https://cloud.google.com/apis/docs/capping-api-usage)
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub quota_user: Option<&'a str>,
35 /// Lets you enforce per-user quotas when calling the API from a server-side application.
36 /// See more about [Capping API usage](https://cloud.google.com/apis/docs/capping-api-usage)
37 #[serde(skip_serializing_if = "Option::is_none")]
38 pub user_ip: Option<&'a str>,
39}
40
41/// Contains common conditionals that determite whether an operation
42/// will actually proceed or not
43#[derive(Default, Serialize)]
44#[serde(rename_all = "camelCase")]
45pub struct Conditionals {
46 /// Makes the operation conditional on whether the object's current
47 /// generation matches the given value. Setting to 0 makes the
48 /// operation succeed only if there are no live versions of the object.
49 #[serde(skip_serializing_if = "Option::is_none")]
50 pub if_generation_match: Option<i64>,
51 /// Makes the operation conditional on whether the object's current
52 /// generation does not match the given value. If no live object exists,
53 /// the precondition fails. Setting to 0 makes the operation succeed only
54 /// if there is a live version of the object.
55 #[serde(skip_serializing_if = "Option::is_none")]
56 pub if_generation_not_match: Option<i64>,
57 /// Makes the operation conditional on whether the object's current
58 /// metageneration matches the given value.
59 #[serde(skip_serializing_if = "Option::is_none")]
60 pub if_metageneration_match: Option<i64>,
61 /// Makes the operation conditional on whether the object's current
62 /// metageneration does not match the given value.
63 #[serde(skip_serializing_if = "Option::is_none")]
64 pub if_metageneration_not_match: Option<i64>,
65}
66
67/// [Storage classes](https://cloud.google.com/storage/docs/storage-classes)
68#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, Eq)]
69#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
70pub enum StorageClass {
71 /// [Multi-Regional Storage](https://cloud.google.com/storage/docs/storage-classes#multi-regional)
72 /// is appropriate for storing data that is frequently accessed ("hot" objects), such as serving
73 /// website content, interactive workloads, or data supporting mobile and gaming applications.
74 /// Multi-Regional Storage data has the most availability compared to other storage classes.
75 MultiRegional,
76 /// [Regional Storage](https://cloud.google.com/storage/docs/storage-classes#regional) enables
77 /// you to store data at lower cost, with the trade-off of data being stored in a specific
78 /// regional location, instead of having redundancy distributed over a large geographic area.
79 Regional,
80 /// [Nearline Storage](https://cloud.google.com/storage/docs/storage-classes#nearline) is a
81 /// low-cost, highly durable storage service for storing infrequently accessed data.
82 /// Nearline Storage is a better choice than Multi-Regional Storage or Regional Storage
83 /// in scenarios where slightly lower availability, a 30-day minimum storage duration,
84 /// and costs for data access are acceptable trade-offs for lowered storage costs.
85 Nearline,
86 /// [Coldline Storage](https://cloud.google.com/storage/docs/storage-classes#coldline)
87 /// is a very-low-cost, highly durable storage service for data archiving, online backup,
88 /// and disaster recovery. Unlike other "cold" storage services, your data is available
89 /// within milliseconds, not hours or days.
90 Coldline,
91 /// Users that create a bucket without specifying a default storage class see the bucket's
92 /// default storage class listed as [Standard Storage](https://cloud.google.com/storage/docs/storage-classes#standard)
93 /// in the API. Objects created without a storage class in such a bucket are also listed
94 /// as Standard Storage in the API. Standard Storage is equivalent to Multi-Regional
95 /// Storage when the associated bucket is located in a multi-regional location. Standard
96 /// Storage is equivalent to Regional Storage when the associated bucket is located in a
97 /// regional location.
98 Standard,
99 /// It is recommended that users utilize Regional Storage in place of [Durable Reduced Availability (DRA)](https://cloud.google.com/storage/docs/storage-classes#dra).
100 /// Regional Storage has lower pricing for operations, but otherwise the same price structure.
101 /// Regional Storage also has better performance, particularly in terms of availability
102 /// (DRA has a 99% availability SLA).
103 DurableReducedAvailability,
104}
105
106impl fmt::Display for StorageClass {
107 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108 write!(f, "{:?}", self)
109 }
110}
111
112/// A [predefined or "canned" ACL](https://cloud.google.com/storage/docs/access-control/lists#predefined-acl)
113/// is an alias for a set of specific ACL entries that you can use to quickly apply many ACL entries at once
114/// to a bucket or object. Predefined ACLs are defined for common scenarios such as revoking all access
115/// permissions except for owner permission (predefined ACL private), or making an object publicly readable
116/// (predefined ACL publicRead).
117#[derive(Serialize, Copy, Clone, Debug, PartialEq, Eq)]
118#[serde(rename_all = "camelCase")]
119pub enum PredefinedAcl {
120 /// Object owner gets OWNER access, and allAuthenticatedUsers get READER access.
121 AuthenticatedRead,
122 /// Object owner gets OWNER access, and project team owners get OWNER access.
123 BucketOwnerFullControl,
124 /// Object owner gets OWNER access, and project team owners get READER access.
125 BucketOwnerRead,
126 /// Object owner gets OWNER access.
127 Private,
128 /// Object owner gets OWNER access, and project team members get access according to their roles.
129 ProjectPrivate,
130 /// Object owner gets OWNER access, and allUsers get READER access.
131 PublicRead,
132}
133
134/// Set of properties to return. Defaults to `NoAcl`.
135#[derive(Serialize, Copy, Clone, Debug, PartialEq, Eq, Default)]
136#[serde(rename_all = "camelCase")]
137pub enum Projection {
138 /// Include all properties.
139 Full,
140 /// Omit the owner, acl property.
141 #[default]
142 NoAcl,
143}