Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/storage/examples/src/buckets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod create_bucket_class_location;
pub mod create_bucket_dual_region;
pub mod create_bucket_hierarchical_namespace;
pub mod create_bucket_turbo_replication;
pub mod create_bucket_with_object_retention;
pub mod define_bucket_website_configuration;
pub mod delete_bucket;
pub mod disable_bucket_lifecycle_management;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// [START storage_create_bucket_with_object_retention]
use google_cloud_storage::{client::StorageControl, model::Bucket, model::bucket::ObjectRetention};

pub async fn sample(
client: &StorageControl,
project_id: &str,
bucket_id: &str,
) -> anyhow::Result<()> {
let bucket = client
.create_bucket()
.set_parent("projects/_")
.set_bucket_id(bucket_id)
.set_bucket(
Bucket::new()
.set_project(format!("projects/{project_id}"))
.set_object_retention(ObjectRetention::new().set_enabled(true)),
)
.send()
.await?;
println!("successfully created bucket {bucket:?}");
Ok(())
}
// [END storage_create_bucket_with_object_retention]
5 changes: 5 additions & 0 deletions src/storage/examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ pub async fn run_bucket_examples(buckets: &mut Vec<String>) -> anyhow::Result<()
tracing::info!("running create_bucket_hierarchical_namespace example");
buckets::create_bucket_hierarchical_namespace::sample(&client, &project_id, &id).await?;

let id = random_bucket_id();
buckets.push(id.clone());
tracing::info!("running create_bucket_with_object_retention example");
buckets::create_bucket_with_object_retention::sample(&client, &project_id, &id).await?;

// Use a new bucket to avoid clashing policies from the previous examples.
let id = random_bucket_id();
buckets.push(id.clone());
Expand Down
Loading