google_cloud_storage/http/buckets/
insert.rs

1use std::collections::HashMap;
2
3use reqwest_middleware::{ClientWithMiddleware as Client, RequestBuilder};
4
5use crate::http::bucket_access_controls::{BucketAccessControl, PredefinedBucketAcl};
6use crate::http::buckets::{Billing, Cors, Encryption, IamConfiguration, Lifecycle, Logging, Versioning, Website};
7use crate::http::object_access_controls::insert::ObjectAccessControlCreationConfig;
8use crate::http::object_access_controls::{PredefinedObjectAcl, Projection};
9
10#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Default, Debug)]
11#[serde(rename_all = "camelCase")]
12pub struct BucketCreationConfig {
13    /// Access controls on the bucket, containing one or more bucketAccessControls Resources.
14    /// If iamConfiguration.uniformBucketLevelAccess.enabled is set to true,
15    /// this field is omitted in responses, and requests that specify
16    /// this field fail with a 400 Bad Request response.
17    pub acl: Option<Vec<BucketAccessControl>>,
18    /// Default access controls to apply to new objects when no ACL is provided.
19    /// This list defines an entity and role for one or more defaultObjectAccessControls Resources.
20    /// If iamConfiguration.uniformBucketLevelAccess.enabled is set to true,
21    /// this field is omitted in responses, and requests that specify this field
22    /// fail with a 400 Bad Request response.
23    pub default_object_acl: Option<Vec<ObjectAccessControlCreationConfig>>,
24    /// The bucket's lifecycle configuration. See lifecycle management for more information.
25    pub lifecycle: Option<Lifecycle>,
26    /// The bucket's Cross-Origin Resource Sharing (CORS) configuration.
27    pub cors: Option<Vec<Cors>>,
28    /// The location of the bucket. Object data for objects in the bucket resides in physical storage
29    /// within this region, dual-region, or multi-region. Defaults to "US".
30    /// See Cloud Storage bucket locations for the authoritative list.
31    pub location: String,
32    /// The bucket's default storage class, used whenever no storageClass is specified
33    /// for a newly-created object. If storageClass is not specified when the bucket is created,
34    /// it defaults to "STANDARD". For available storage classes, see Storage classes.
35    pub storage_class: Option<String>,
36    /// Default access controls to apply to new objects when no ACL is provided.
37    /// This list defines an entity and role for one or more defaultObjectAccessControls Resources.
38    /// If iamConfiguration.uniformBucketLevelAccess.enabled is set to true,
39    /// this field is omitted in responses, and requests that specify this field fail with a 400 Bad Request
40    /// response.
41    pub default_event_based_hold: bool,
42    /// User-provided bucket labels, in key/value pairs.
43    pub labels: Option<HashMap<String, String>>,
44    /// The bucket's website configuration, controlling how the service behaves
45    /// when accessing bucket contents as a web site. See the Static Website Examples for more information.
46    pub website: Option<Website>,
47    /// The bucket's versioning configuration.
48    pub versioning: Option<Versioning>,
49    /// The bucket's logging configuration, which defines the destination bucket
50    /// and optional name prefix for the current bucket's logs.
51    pub logging: Option<Logging>,
52    /// Encryption configuration for a bucket.
53    pub encryption: Option<Encryption>,
54    /// The bucket's billing configuration.
55    pub billing: Option<Billing>,
56    /// The bucket's retention policy, which defines the minimum age
57    /// an object in the bucket must have to be deleted or replaced.
58    pub retention_policy: Option<RetentionPolicyCreationConfig>,
59    /// The bucket's IAM configuration.
60    pub iam_configuration: Option<IamConfiguration>,
61    /// The recovery point objective for cross-region replication of the bucket.
62    /// Applicable only for dual- and multi-region buckets.
63    /// "DEFAULT" uses default replication. "ASYNC_TURBO" enables turbo replication,
64    /// valid for dual-region buckets only. If rpo is not specified when the bucket is created,
65    /// it defaults to "DEFAULT". For more information, see Turbo replication.
66    pub rpo: Option<String>,
67}
68
69#[derive(Clone, PartialEq, Eq, serde::Deserialize, serde::Serialize, Debug)]
70#[serde(rename_all = "camelCase")]
71pub struct RetentionPolicyCreationConfig {
72    pub retention_period: u64,
73}
74
75/// Request message for InsertBucket.
76#[derive(Clone, PartialEq, Eq, Default, serde::Deserialize, serde::Serialize, Debug)]
77#[serde(rename_all = "camelCase")]
78pub struct InsertBucketParam {
79    pub project: String,
80    pub predefined_acl: Option<PredefinedBucketAcl>,
81    pub predefined_default_object_acl: Option<PredefinedObjectAcl>,
82    pub projection: Option<Projection>,
83}
84/// Request message for InsertBucket.
85#[derive(Clone, PartialEq, Eq, Default, serde::Deserialize, serde::Serialize, Debug)]
86#[serde(rename_all = "camelCase")]
87pub struct InsertBucketRequest {
88    pub name: String,
89    #[serde(skip_serializing)]
90    pub param: InsertBucketParam,
91    #[serde(flatten)]
92    pub bucket: BucketCreationConfig,
93}
94
95pub(crate) fn build(base_url: &str, client: &Client, req: &InsertBucketRequest) -> RequestBuilder {
96    let url = format!("{base_url}/b");
97    client.post(url).query(&req.param).json(&req)
98}