google_cloud_storage/http/buckets/mod.rs
1use time::OffsetDateTime;
2
3use crate::http::bucket_access_controls::BucketAccessControl;
4use crate::http::object_access_controls::ObjectAccessControl;
5use crate::http::objects::Owner;
6
7pub mod delete;
8pub mod get;
9pub mod get_iam_policy;
10pub mod insert;
11pub mod list;
12pub mod list_channels;
13pub mod lock_retention_policy;
14pub mod patch;
15pub mod set_iam_policy;
16pub mod test_iam_permissions;
17
18/// A bucket.
19#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
20#[serde(rename_all = "camelCase")]
21pub struct Bucket {
22 /// Access controls on the bucket.
23 pub acl: Option<Vec<BucketAccessControl>>,
24 /// Default access controls to apply to new objects when no ACL is provided.
25 pub default_object_acl: Option<Vec<ObjectAccessControl>>,
26 /// The bucket's lifecycle configuration. See
27 /// \[<https://developers.google.com/storage/docs/lifecycle\]Lifecycle> Management]
28 /// for more information.
29 pub lifecycle: Option<Lifecycle>,
30 /// The creation time of the bucket in
31 /// \[<https://tools.ietf.org/html/rfc3339\][RFC> 3339] format.
32 /// Attempting to set or update this field will result in a
33 /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
34 #[serde(default, with = "time::serde::rfc3339::option")]
35 pub time_created: Option<OffsetDateTime>,
36 /// The ID of the bucket. For buckets, the `id` and `name` properties are the
37 /// same.
38 /// Attempting to update this field after the bucket is created will result in
39 /// a \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
40 pub id: String,
41 /// The name of the bucket.
42 /// Attempting to update this field after the bucket is created will result in
43 /// an error.
44 pub name: String,
45 /// The project number of the project the bucket belongs to.
46 /// Attempting to set or update this field will result in a
47 /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
48 #[serde(deserialize_with = "crate::http::from_str")]
49 pub project_number: i64,
50 /// The metadata generation of this bucket.
51 /// Attempting to set or update this field will result in a
52 /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
53 #[serde(deserialize_with = "crate::http::from_str")]
54 pub metageneration: i64,
55 /// The bucket's \[<https://www.w3.org/TR/cors/\][Cross-Origin> Resource Sharing]
56 /// (CORS) configuration.
57 pub cors: Option<Vec<Cors>>,
58 /// The location of the bucket. Object data for objects in the bucket resides
59 /// in physical storage within this region. Defaults to `US`. See the
60 /// \[<https://developers.google.com/storage/docs/concepts-techniques#specifyinglocations"\][developer's>
61 /// guide] for the authoritative list. Attempting to update this field after
62 /// the bucket is created will result in an error.
63 pub location: String,
64 /// The bucket's default storage class, used whenever no storageClass is
65 /// specified for a newly-created object. This defines how objects in the
66 /// bucket are stored and determines the SLA and the cost of storage.
67 /// If this value is not specified when the bucket is created, it will default
68 /// to `STANDARD`. For more information, see
69 /// <https://developers.google.com/storage/docs/storage-classes>.
70 pub storage_class: String,
71 /// HTTP 1.1 \[<https://tools.ietf.org/html/rfc7232#section-2.3"\]Entity> tag]
72 /// for the bucket.
73 /// Attempting to set or update this field will result in a
74 /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
75 pub etag: String,
76 /// The modification time of the bucket.
77 /// Attempting to set or update this field will result in a
78 /// \[FieldViolation][google.rpc.BadRequest.FieldViolation\].
79 #[serde(default, with = "time::serde::rfc3339::option")]
80 pub updated: Option<OffsetDateTime>,
81 /// The default value for event-based hold on newly created objects in this
82 /// bucket. Event-based hold is a way to retain objects indefinitely until an
83 /// event occurs, signified by the
84 /// hold's release. After being released, such objects will be subject to
85 /// bucket-level retention (if any). One sample use case of this flag is for
86 /// banks to hold loan documents for at least 3 years after loan is paid in
87 /// full. Here, bucket-level retention is 3 years and the event is loan being
88 /// paid in full. In this example, these objects will be held intact for any
89 /// number of years until the event has occurred (event-based hold on the
90 /// object is released) and then 3 more years after that. That means retention
91 /// duration of the objects begins from the moment event-based hold
92 /// transitioned from true to false. Objects under event-based hold cannot be
93 /// deleted, overwritten or archived until the hold is removed.
94 pub default_event_based_hold: Option<bool>,
95 /// User-provided labels, in key/value pairs.
96 pub labels: Option<::std::collections::HashMap<String, String>>,
97 /// The bucket's website configuration, controlling how the service behaves
98 /// when accessing bucket contents as a web site. See the
99 /// \[<https://cloud.google.com/storage/docs/static-website\][Static> Website
100 /// Examples] for more information.
101 pub website: Option<Website>,
102 /// The bucket's versioning configuration.
103 pub versioning: Option<Versioning>,
104 /// The bucket's logging configuration, which defines the destination bucket
105 /// and optional name prefix for the current bucket's logs.
106 pub logging: Option<Logging>,
107 /// The owner of the bucket. This is always the project team's owner group.
108 pub owner: Option<Owner>,
109 /// Encryption configuration for a bucket.
110 pub encryption: Option<Encryption>,
111 /// The bucket's billing configuration.
112 pub billing: Option<Billing>,
113 /// The bucket's retention policy. The retention policy enforces a minimum
114 /// retention time for all objects contained in the bucket, based on their
115 /// creation time. Any attempt to overwrite or delete objects younger than the
116 /// retention period will result in a PERMISSION_DENIED error. An unlocked
117 /// retention policy can be modified or removed from the bucket via a
118 /// storage.buckets.update operation. A locked retention policy cannot be
119 /// removed or shortened in duration for the lifetime of the bucket.
120 /// Attempting to remove or decrease period of a locked retention policy will
121 /// result in a PERMISSION_DENIED error.
122 pub retention_policy: Option<RetentionPolicy>,
123 /// The location type of the bucket (region, dual-region, multi-region, etc).
124 pub location_type: String,
125 /// The recovery point objective for cross-region replication of the bucket.
126 /// Applicable only for dual- and multi-region buckets.
127 /// "DEFAULT" uses default replication.
128 /// "ASYNC_TURBO" enables turbo replication, valid for dual-region buckets only.
129 /// If rpo is not specified when the bucket is created, it defaults to "DEFAULT".
130 /// For more information, see Turbo replication.
131 pub rpo: Option<String>,
132 /// The bucket's IAM configuration.
133 pub iam_configuration: Option<IamConfiguration>,
134}
135/// Billing properties of a bucket.
136#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
137#[serde(rename_all = "camelCase")]
138pub struct Billing {
139 /// When set to true, Requester Pays is enabled for this bucket.
140 pub requester_pays: bool,
141}
142/// Cross-Origin Response sharing (CORS) properties for a bucket.
143/// For more on GCS and CORS, see
144/// <https://cloud.google.com/storage/docs/cross-origin>.
145/// For more on CORS in general, see <https://tools.ietf.org/html/rfc6454>.
146#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
147#[serde(rename_all = "camelCase")]
148pub struct Cors {
149 /// The list of Origins eligible to receive CORS response headers. See
150 /// \[<https://tools.ietf.org/html/rfc6454\][RFC> 6454] for more on origins.
151 /// Note: "*" is permitted in the list of origins, and means "any Origin".
152 pub origin: Vec<String>,
153 /// The list of HTTP methods on which to include CORS response headers,
154 /// (`GET`, `OPTIONS`, `POST`, etc) Note: "*" is permitted in the list of
155 /// methods, and means "any method".
156 pub method: Vec<String>,
157 /// The list of HTTP headers other than the
158 /// \[<https://www.w3.org/TR/cors/#simple-response-header\][simple> response
159 /// headers] to give permission for the user-agent to share across domains.
160 pub response_header: Vec<String>,
161 /// The value, in seconds, to return in the
162 /// \[<https://www.w3.org/TR/cors/#access-control-max-age-response-header\][Access-Control-Max-Age>
163 /// header] used in preflight responses.
164 pub max_age_seconds: i32,
165}
166/// Encryption properties of a bucket.
167#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
168#[serde(rename_all = "camelCase")]
169pub struct Encryption {
170 /// A Cloud KMS key that will be used to encrypt objects inserted into this
171 /// bucket, if no encryption method is specified.
172 pub default_kms_key_name: String,
173}
174/// Bucket restriction options currently enforced on the bucket.
175#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
176#[serde(rename_all = "camelCase")]
177pub struct IamConfiguration {
178 pub uniform_bucket_level_access: Option<iam_configuration::UniformBucketLevelAccess>,
179 /// Whether IAM will enforce public access prevention.
180 pub public_access_prevention: Option<iam_configuration::PublicAccessPrevention>,
181}
182/// Nested message and enum types in `IamConfiguration`.
183pub mod iam_configuration {
184 use time::OffsetDateTime;
185
186 #[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
187 #[serde(rename_all = "camelCase")]
188 pub struct UniformBucketLevelAccess {
189 /// If set, access checks only use bucket-level IAM policies or above.
190 pub enabled: bool,
191 /// The deadline time for changing
192 /// <code>iamConfiguration.uniformBucketLevelAccess.enabled</code> from
193 /// true to false in \[<https://tools.ietf.org/html/rfc3339\][RFC> 3339]. After
194 /// the deadline is passed the field is immutable.
195 #[serde(default, with = "time::serde::rfc3339::option")]
196 pub locked_time: Option<OffsetDateTime>,
197 }
198 /// Public Access Prevention configuration values.
199 #[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, serde::Deserialize, serde::Serialize, Debug)]
200 #[repr(i32)]
201 pub enum PublicAccessPrevention {
202 /// Prevents access from being granted to public members 'allUsers' and
203 /// 'allAuthenticatedUsers'. Prevents attempts to grant new access to
204 /// public members.
205 #[serde(rename = "enforced")]
206 Enforced = 1,
207 /// This setting is inherited from Org Policy. Does not prevent access from
208 /// being granted to public members 'allUsers' or 'allAuthenticatedUsers'.
209 #[serde(rename = "inherited")]
210 Inherited = 2,
211 }
212}
213/// Lifecycle properties of a bucket.
214/// For more information, see <https://cloud.google.com/storage/docs/lifecycle>.
215#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
216#[serde(rename_all = "camelCase")]
217pub struct Lifecycle {
218 /// A lifecycle management rule, which is made of an action to take and the
219 /// condition(s) under which the action will be taken.
220 pub rule: Vec<lifecycle::Rule>,
221}
222/// Nested message and enum types in `Lifecycle`.
223pub mod lifecycle {
224 /// A lifecycle Rule, combining an action to take on an object and a
225 /// condition which will trigger that action.
226 #[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
227 #[serde(rename_all = "camelCase")]
228 pub struct Rule {
229 /// The action to take.
230 pub action: Option<rule::Action>,
231 /// The condition(s) under which the action will be taken.
232 pub condition: Option<rule::Condition>,
233 }
234 /// Nested message and enum types in `Rule`.
235 pub mod rule {
236 use time::Date;
237
238 // RFC3339 Date part, in format YYYY-MM-DD
239 time::serde::format_description!(date_format, Date, "[year]-[month]-[day]");
240
241 #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
242 pub enum ActionType {
243 /// Deletes a Bucket.
244 Delete,
245 /// Sets the `storage_class` of a Bucket.
246 SetStorageClass,
247 /// Aborts an incomplete multipart upload and deletes the associated parts when the multipart upload meets the conditions specified in the lifecycle rule.
248 AbortIncompleteMultipartUpload,
249 }
250 /// An action to take on an object.
251 #[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
252 #[serde(rename_all = "camelCase")]
253 pub struct Action {
254 pub r#type: ActionType,
255 pub storage_class: Option<String>,
256 }
257 /// A condition of an object which triggers some action.
258 #[derive(Clone, PartialEq, Eq, Default, serde::Deserialize, serde::Serialize, Debug)]
259 #[serde(rename_all = "camelCase")]
260 pub struct Condition {
261 pub age: Option<i32>,
262 #[serde(default, with = "date_format::option")]
263 pub created_before: Option<Date>,
264 #[serde(default, with = "date_format::option")]
265 pub custom_time_before: Option<Date>,
266 pub days_since_custom_time: Option<i32>,
267 pub days_since_noncurrent_time: Option<i32>,
268 pub is_live: Option<bool>,
269 pub matches_storage_class: Option<Vec<String>>,
270 #[serde(default, with = "date_format::option")]
271 pub noncurrent_time_before: Option<Date>,
272 pub num_newer_versions: Option<i32>,
273 }
274 }
275}
276/// Logging-related properties of a bucket.
277#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
278#[serde(rename_all = "camelCase")]
279pub struct Logging {
280 /// The destination bucket where the current bucket's logs should be placed.
281 pub log_bucket: String,
282 /// A prefix for log object names.
283 pub log_object_prefix: String,
284}
285/// Retention policy properties of a bucket.
286#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
287#[serde(rename_all = "camelCase")]
288pub struct RetentionPolicy {
289 /// Server-determined value that indicates the time from which policy was
290 /// enforced and effective. This value is in
291 /// \[<https://tools.ietf.org/html/rfc3339\][RFC> 3339] format.
292 #[serde(default, with = "time::serde::rfc3339::option")]
293 pub effective_time: Option<OffsetDateTime>,
294 /// Once locked, an object retention policy cannot be modified.
295 pub is_locked: Option<bool>,
296 /// The duration in seconds that objects need to be retained. Retention
297 /// duration must be greater than zero and less than 100 years. Note that
298 /// enforcement of retention periods less than a day is not guaranteed. Such
299 /// periods should only be used for testing purposes.
300 #[serde(deserialize_with = "crate::http::from_str")]
301 pub retention_period: u64,
302}
303/// Properties of a bucket related to versioning.
304/// For more on GCS versioning, see
305/// <https://cloud.google.com/storage/docs/object-versioning>.
306#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
307#[serde(rename_all = "camelCase")]
308pub struct Versioning {
309 /// While set to true, versioning is fully enabled for this bucket.
310 pub enabled: bool,
311}
312/// Properties of a bucket related to accessing the contents as a static
313/// website. For more on hosting a static website via GCS, see
314/// <https://cloud.google.com/storage/docs/hosting-static-website>.
315#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
316#[serde(rename_all = "camelCase")]
317pub struct Website {
318 /// If the requested object path is missing, the service will ensure the path
319 /// has a trailing '/', append this suffix, and attempt to retrieve the
320 /// resulting object. This allows the creation of `index.html`
321 /// objects to represent directory pages.
322 pub main_page_suffix: String,
323 /// If the requested object path is missing, and any
324 /// `mainPageSuffix` object is missing, if applicable, the service
325 /// will return the named object from this bucket as the content for a
326 /// \[<https://tools.ietf.org/html/rfc7231#section-6.5.4\][404> Not Found]
327 /// result.
328 pub not_found_page: String,
329}
330/// Configuration for a bucket's Autoclass feature.
331#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
332#[serde(rename_all = "camelCase")]
333pub struct Autoclass {
334 /// Enables Autoclass.
335 pub enabled: bool,
336 /// Latest instant at which the `enabled` bit was flipped.
337 #[serde(default, with = "time::serde::rfc3339::option")]
338 pub toggle_time: Option<OffsetDateTime>,
339}
340
341/// An Identity and Access Management (IAM) policy, which specifies access
342/// controls for Google Cloud resources.
343///
344///
345/// A `Policy` is a collection of `bindings`. A `binding` binds one or more
346/// `members`, or principals, to a single `role`. Principals can be user
347/// accounts, service accounts, Google groups, and domains (such as G Suite). A
348/// `role` is a named list of permissions; each `role` can be an IAM predefined
349/// role or a user-created custom role.
350///
351/// For some types of Google Cloud resources, a `binding` can also specify a
352/// `condition`, which is a logical expression that allows access to a resource
353/// only if the expression evaluates to `true`. A condition can add constraints
354/// based on attributes of the request, the resource, or both. To learn which
355/// resources support conditions in their IAM policies, see the
356/// [IAM documentation](<https://cloud.google.com/iam/help/conditions/resource-policies>).
357///
358/// For a description of IAM and its features, see the
359/// [IAM documentation](<https://cloud.google.com/iam/docs/>).
360#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
361#[serde(rename_all = "camelCase")]
362pub struct Policy {
363 /// Specifies the format of the policy.
364 ///
365 /// Valid values are `0`, `1`, and `3`. Requests that specify an invalid value
366 /// are rejected.
367 ///
368 /// Any operation that affects conditional role bindings must specify version
369 /// `3`. This requirement applies to the following operations:
370 ///
371 /// * Getting a policy that includes a conditional role binding
372 /// * Adding a conditional role binding to a policy
373 /// * Changing a conditional role binding in a policy
374 /// * Removing any role binding, with or without a condition, from a policy
375 /// that includes conditions
376 ///
377 /// **Important:** If you use IAM Conditions, you must include the `etag` field
378 /// whenever you call `setIamPolicy`. If you omit this field, then IAM allows
379 /// you to overwrite a version `3` policy with a version `1` policy, and all of
380 /// the conditions in the version `3` policy are lost.
381 ///
382 /// If a policy does not include any conditions, operations on that policy may
383 /// specify any valid version or leave the field unset.
384 ///
385 /// To learn which resources support conditions in their IAM policies, see the
386 /// [IAM documentation](<https://cloud.google.com/iam/help/conditions/resource-policies>).
387 pub version: i32,
388 /// Associates a list of `members`, or principals, with a `role`. Optionally,
389 /// may specify a `condition` that determines how and when the `bindings` are
390 /// applied. Each of the `bindings` must contain at least one principal.
391 ///
392 /// The `bindings` in a `Policy` can refer to up to 1,500 principals; up to 250
393 /// of these principals can be Google groups. Each occurrence of a principal
394 /// counts towards these limits. For example, if the `bindings` grant 50
395 /// different roles to `user:alice@example.com`, and not to any other
396 /// principal, then you can add another 1,450 principals to the `bindings` in
397 /// the `Policy`.
398 pub bindings: Vec<Binding>,
399 pub etag: String,
400}
401/// Associates `members`, or principals, with a `role`.
402#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
403#[serde(rename_all = "camelCase")]
404pub struct Binding {
405 /// Role that is assigned to the list of `members`, or principals.
406 /// For example, `roles/viewer`, `roles/editor`, or `roles/owner`.
407 pub role: String,
408 /// Specifies the principals requesting access for a Cloud Platform resource.
409 /// `members` can have the following values:
410 ///
411 /// * `allUsers`: A special identifier that represents anyone who is
412 /// on the internet; with or without a Google account.
413 ///
414 /// * `allAuthenticatedUsers`: A special identifier that represents anyone
415 /// who is authenticated with a Google account or a service account.
416 ///
417 /// * `user:{emailid}`: An email address that represents a specific Google
418 /// account. For example, `alice@example.com` .
419 ///
420 ///
421 /// * `serviceAccount:{emailid}`: An email address that represents a service
422 /// account. For example, `my-other-app@appspot.gserviceaccount.com`.
423 ///
424 /// * `group:{emailid}`: An email address that represents a Google group.
425 /// For example, `admins@example.com`.
426 ///
427 /// * `deleted:user:{emailid}?uid={uniqueid}`: An email address (plus unique
428 /// identifier) representing a user that has been recently deleted. For
429 /// example, `alice@example.com?uid=123456789012345678901`. If the user is
430 /// recovered, this value reverts to `user:{emailid}` and the recovered user
431 /// retains the role in the binding.
432 ///
433 /// * `deleted:serviceAccount:{emailid}?uid={uniqueid}`: An email address (plus
434 /// unique identifier) representing a service account that has been recently
435 /// deleted. For example,
436 /// `my-other-app@appspot.gserviceaccount.com?uid=123456789012345678901`.
437 /// If the service account is undeleted, this value reverts to
438 /// `serviceAccount:{emailid}` and the undeleted service account retains the
439 /// role in the binding.
440 ///
441 /// * `deleted:group:{emailid}?uid={uniqueid}`: An email address (plus unique
442 /// identifier) representing a Google group that has been recently
443 /// deleted. For example, `admins@example.com?uid=123456789012345678901`. If
444 /// the group is recovered, this value reverts to `group:{emailid}` and the
445 /// recovered group retains the role in the binding.
446 ///
447 ///
448 /// * `domain:{domain}`: The G Suite domain (primary) that represents all the
449 /// users of that domain. For example, `google.com` or `example.com`.
450 ///
451 ///
452 pub members: Vec<String>,
453 /// The condition that is associated with this binding.
454 ///
455 /// If the condition evaluates to `true`, then this binding applies to the
456 /// current request.
457 ///
458 /// If the condition evaluates to `false`, then this binding does not apply to
459 /// the current request. However, a different role binding might grant the same
460 /// role to one or more of the principals in this binding.
461 ///
462 /// To learn which resources support conditions in their IAM policies, see the
463 /// [IAM
464 /// documentation](<https://cloud.google.com/iam/help/conditions/resource-policies>).
465 pub condition: Option<Condition>,
466}
467
468#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
469#[serde(rename_all = "camelCase")]
470pub struct Condition {
471 /// Textual representation of an expression in Common Expression Language
472 /// syntax.
473 pub expression: String,
474 /// Optional. Title for the expression, i.e. a short string describing
475 /// its purpose. This can be used e.g. in UIs which allow to enter the
476 /// expression.
477 pub title: String,
478 /// Optional. Description of the expression. This is a longer text which
479 /// describes the expression, e.g. when hovered over it in a UI.
480 #[serde(default)]
481 pub description: Option<String>,
482}