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/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ pub mod managed_folder_create;
pub mod managed_folder_delete;
pub mod managed_folder_get;
pub mod managed_folder_list;
pub mod quickstart;
pub mod rename_folder;
27 changes: 27 additions & 0 deletions src/storage/examples/src/control/quickstart.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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_control_quickstart_sample]
use google_cloud_storage::client::StorageControl;

pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> {
let layout = client
.get_storage_layout()
.set_name(format!("projects/_/buckets/{bucket_id}/storageLayout"))
.send()
.await?;
println!("successfully retrieved storage layout: {layout:?}");
Ok(())
}
// [END storage_control_quickstart_sample]
9 changes: 9 additions & 0 deletions src/storage/examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod get_bucket_metadata;
mod list_buckets;
mod print_bucket_acl;
mod print_bucket_acl_for_user;
mod quickstart;
mod remove_bucket_owner;

use google_cloud_storage::client::StorageControl;
Expand Down Expand Up @@ -66,6 +67,11 @@ pub async fn run_bucket_examples(buckets: &mut Vec<String>) -> anyhow::Result<()
tracing::info!("running delete_bucket example");
delete_bucket::delete_bucket(&client, &id).await?;

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

let id = random_bucket_id();
buckets.push(id.clone());
tracing::info!("running create_bucket_class_location example");
Expand Down Expand Up @@ -115,6 +121,9 @@ pub async fn run_managed_folder_examples(buckets: &mut Vec<String>) -> anyhow::R
)
.await?;

tracing::info!("running control::quickstart example");
control::quickstart::sample(&client, &id).await?;

tracing::info!("running control::managed_folder_create example");
control::managed_folder_create::sample(&client, &id).await?;
tracing::info!("running control::managed_folder_get example");
Expand Down
38 changes: 38 additions & 0 deletions src/storage/examples/src/quickstart.rs
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_quickstart]
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_storage_class("STANDARD")
.set_location("US"),
)
.send()
.await?;
println!("successfully created bucket {bucket:?}");
Ok(())
}
// [END storage_quickstart]
Loading