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
2 changes: 2 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ extend-ignore-re = [
"\"typ\"",
"\\Wtyp:",
"test_typ\"",
# The name of a Cloud Storage dual region, used in some tests.
"NAM4",
]
3 changes: 3 additions & 0 deletions src/storage/examples/src/buckets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub mod create_bucket;
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 define_bucket_website_configuration;
pub mod delete_bucket;
pub mod disable_bucket_lifecycle_management;
Expand Down Expand Up @@ -50,6 +51,8 @@ pub mod set_public_access_prevention_enforced;
pub mod set_public_access_prevention_inherited;
pub mod set_public_access_prevention_unspecified;
pub mod set_retention_policy;
pub mod set_rpo_async_turbo;
pub mod set_rpo_default;
pub mod view_bucket_iam_members;
pub mod view_lifecycle_management_configuration;
pub mod view_versioning_status;
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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_turbo_replication]
use google_cloud_storage::{client::StorageControl, model::Bucket};

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_location("NAM4")
.set_rpo("ASYNC_TURBO"),
)
.send()
.await?;
println!("successfully created bucket {bucket:?}");
Ok(())
}
// [END storage_create_bucket_turbo_replication]
36 changes: 36 additions & 0 deletions src/storage/examples/src/buckets/set_rpo_async_turbo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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_set_rpo_async_turbo]
use google_cloud_storage::client::StorageControl;
use google_cloud_wkt::FieldMask;

pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> {
let bucket = client
.get_bucket()
.set_name(format!("projects/_/buckets/{bucket_id}"))
.send()
.await?;
let metageneration = bucket.metageneration;
let bucket = client
.update_bucket()
.set_bucket(bucket.set_rpo("ASYNC_TURBO"))
.set_if_metageneration_match(metageneration)
.set_update_mask(FieldMask::default().set_paths(["rpo"]))
.send()
.await?;
println!("successfully updated bucket RPO to ASYNC_TURBO: {bucket:?}");
Ok(())
}
// [END storage_set_rpo_async_turbo]
36 changes: 36 additions & 0 deletions src/storage/examples/src/buckets/set_rpo_default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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_set_rpo_default]
use google_cloud_storage::client::StorageControl;
use google_cloud_wkt::FieldMask;

pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> {
let bucket = client
.get_bucket()
.set_name(format!("projects/_/buckets/{bucket_id}"))
.send()
.await?;
let metageneration = bucket.metageneration;
let bucket = client
.update_bucket()
.set_bucket(bucket.set_rpo("DEFAULT"))
.set_if_metageneration_match(metageneration)
.set_update_mask(FieldMask::default().set_paths(["rpo"]))
.send()
.await?;
println!("successfully updated bucket RPO to DEFAULT: {bucket:?}");
Ok(())
}
// [END storage_set_rpo_default]
9 changes: 9 additions & 0 deletions src/storage/examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ pub async fn run_bucket_examples(buckets: &mut Vec<String>) -> anyhow::Result<()
tracing::info!("running create_bucket_dual_region example");
buckets::create_bucket_dual_region::sample(&client, &project_id, &id).await?;

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

let id = random_bucket_id();
buckets.push(id.clone());
tracing::info!("running create_bucket_hierarchical_namespace example");
Expand Down
Loading