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
3 changes: 3 additions & 0 deletions src/storage/examples/src/buckets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ pub mod delete_bucket;
pub mod delete_bucket_default_kms_key;
pub mod disable_bucket_lifecycle_management;
pub mod disable_default_event_based_hold;
pub mod disable_requester_pays;
pub mod disable_uniform_bucket_level_access;
pub mod disable_versioning;
pub mod enable_bucket_lifecycle_management;
pub mod enable_default_event_based_hold;
pub mod enable_requester_pays;
pub mod enable_uniform_bucket_level_access;
pub mod enable_versioning;
pub mod get_autoclass;
pub mod get_bucket_default_kms_key;
pub mod get_bucket_metadata;
pub mod get_default_event_based_hold;
pub mod get_public_access_prevention;
pub mod get_requester_pays_status;
pub mod get_retention_policy;
pub mod get_uniform_bucket_level_access;
pub mod list_buckets;
Expand Down
40 changes: 40 additions & 0 deletions src/storage/examples/src/buckets/disable_requester_pays.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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_disable_requester_pays]
use google_cloud_storage::client::StorageControl;
use google_cloud_storage::model::bucket::Billing;
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_billing(Billing::new().set_requester_pays(false)))
.set_if_metageneration_match(metageneration)
.set_update_mask(FieldMask::default().set_paths(["billing.requester_pays"]))
.send()
.await?;
println!(
"Requester pays was disabled for bucket {bucket_id}: {:?}",
bucket.billing
);
Ok(())
}
// [END storage_disable_requester_pays]
40 changes: 40 additions & 0 deletions src/storage/examples/src/buckets/enable_requester_pays.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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_enable_requester_pays]
use google_cloud_storage::client::StorageControl;
use google_cloud_storage::model::bucket::Billing;
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_billing(Billing::new().set_requester_pays(true)))
.set_if_metageneration_match(metageneration)
.set_update_mask(FieldMask::default().set_paths(["billing.requester_pays"]))
.send()
.await?;
println!(
"Requester pays was enabled for bucket {bucket_id}: {:?}",
bucket.billing
);
Ok(())
}
// [END storage_enable_requester_pays]
30 changes: 30 additions & 0 deletions src/storage/examples/src/buckets/get_requester_pays_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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_get_requester_pays_status]
use google_cloud_storage::client::StorageControl;

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?;
println!(
"Bucket {bucket_id} has billing status: {:?}",
bucket.billing
);
Ok(())
}
// [END storage_get_requester_pays_status]
6 changes: 6 additions & 0 deletions src/storage/examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ pub async fn run_bucket_examples(buckets: &mut Vec<String>) -> anyhow::Result<()
buckets::set_autoclass::sample(&client, &id).await?;
tracing::info!("running get_autoclass example");
buckets::get_autoclass::sample(&client, &id).await?;
tracing::info!("running enable_requester_pays example");
buckets::enable_requester_pays::sample(&client, &id).await?;
tracing::info!("running get_requester_pays_status example");
buckets::get_requester_pays_status::sample(&client, &id).await?;
tracing::info!("running disable_requester_pays example");
buckets::disable_requester_pays::sample(&client, &id).await?;

let id = random_bucket_id();
buckets.push(id.clone());
Expand Down
Loading