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
7 changes: 7 additions & 0 deletions src/storage/examples/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,20 @@
// See the License for the specific language governing permissions and
// limitations under the License.

pub mod create_anywhere_cache;
pub mod create_folder;
pub mod delete_folder;
pub mod disable_anywhere_cache;
pub mod get_anywhere_cache;
pub mod get_folder;
pub mod list_anywhere_caches;
pub mod list_folders;
pub mod managed_folder_create;
pub mod managed_folder_delete;
pub mod managed_folder_get;
pub mod managed_folder_list;
pub mod pause_anywhere_cache;
pub mod quickstart;
pub mod rename_folder;
pub mod resume_anywhere_cache;
pub mod update_anywhere_cache;
33 changes: 33 additions & 0 deletions src/storage/examples/src/control/create_anywhere_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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_create_anywhere_cache]
use google_cloud_lro::Poller;
use google_cloud_storage::client::StorageControl;
use google_cloud_storage::model::AnywhereCache;

pub async fn sample(client: &StorageControl, bucket_id: &str, zone: &str) -> anyhow::Result<()> {
let cache = client
.create_anywhere_cache()
.set_parent(format!("projects/_/buckets/{bucket_id}"))
.set_anywhere_cache(AnywhereCache::new().set_zone(zone).set_name(format!(
"projects/_/buckets/{bucket_id}/anywhereCaches/{zone}"
)))
.poller()
.until_done()
.await?;
println!("Created anywhere cache: {cache:?}");
Ok(())
}
// [END storage_control_create_anywhere_cache]
34 changes: 34 additions & 0 deletions src/storage/examples/src/control/disable_anywhere_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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_disable_anywhere_cache]
use google_cloud_storage::client::StorageControl;

pub async fn sample(
client: &StorageControl,
bucket_id: &str,
cache_id: &str,
) -> anyhow::Result<()> {
let cache = client
.disable_anywhere_cache()
.set_name(format!(
"projects/_/buckets/{}/anywhereCaches/{}",
bucket_id, cache_id
))
.send()
.await?;
println!("Disabled anywhere cache: {:?}", cache);
Ok(())
}
// [END storage_control_disable_anywhere_cache]
33 changes: 33 additions & 0 deletions src/storage/examples/src/control/get_anywhere_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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_get_anywhere_cache]
use google_cloud_storage::client::StorageControl;

pub async fn sample(
client: &StorageControl,
bucket_id: &str,
cache_id: &str,
) -> anyhow::Result<()> {
let cache = client
.get_anywhere_cache()
.set_name(format!(
"projects/_/buckets/{bucket_id}/anywhereCaches/{cache_id}"
))
.send()
.await?;
println!("Got anywhere cache: {:?}", cache);
Ok(())
}
// [END storage_control_get_anywhere_cache]
29 changes: 29 additions & 0 deletions src/storage/examples/src/control/list_anywhere_caches.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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_list_anywhere_caches]
use google_cloud_gax::paginator::ItemPaginator;
use google_cloud_storage::client::StorageControl;

pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> {
let mut stream = client
.list_anywhere_caches()
.set_parent(format!("projects/_/buckets/{}", bucket_id))
.by_item();
while let Some(cache) = stream.next().await {
println!("Found cache: {:?}", cache?);
}
Ok(())
}
// [END storage_control_list_anywhere_caches]
33 changes: 33 additions & 0 deletions src/storage/examples/src/control/pause_anywhere_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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_pause_anywhere_cache]
use google_cloud_storage::client::StorageControl;

pub async fn sample(
client: &StorageControl,
bucket_id: &str,
cache_id: &str,
) -> anyhow::Result<()> {
let cache = client
.pause_anywhere_cache()
.set_name(format!(
"projects/_/buckets/{bucket_id}/anywhereCaches/{cache_id}"
))
.send()
.await?;
println!("Paused anywhere cache: {:?}", cache);
Ok(())
}
// [END storage_control_pause_anywhere_cache]
34 changes: 34 additions & 0 deletions src/storage/examples/src/control/resume_anywhere_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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_resume_anywhere_cache]
use google_cloud_storage::client::StorageControl;

pub async fn sample(
client: &StorageControl,
bucket_id: &str,
cache_id: &str,
) -> anyhow::Result<()> {
let cache = client
.resume_anywhere_cache()
.set_name(format!(
"projects/_/buckets/{}/anywhereCaches/{}",
bucket_id, cache_id
))
.send()
.await?;
println!("Resumed anywhere cache: {:?}", cache);
Ok(())
}
// [END storage_control_resume_anywhere_cache]
42 changes: 42 additions & 0 deletions src/storage/examples/src/control/update_anywhere_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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_update_anywhere_cache]
use google_cloud_lro::Poller;
use google_cloud_storage::client::StorageControl;
use google_cloud_storage::model::AnywhereCache;
use google_cloud_wkt::FieldMask;

pub async fn sample(
client: &StorageControl,
bucket_id: &str,
cache_id: &str,
) -> anyhow::Result<()> {
let anywhere_cache = AnywhereCache::new()
.set_name(format!(
"projects/_/buckets/{}/anywhereCaches/{}",
bucket_id, cache_id
))
.set_admission_policy("ADMIT_ON_SECOND_MISS".to_string());
let operation = client
.update_anywhere_cache()
.set_anywhere_cache(anywhere_cache)
.set_update_mask(FieldMask::default().set_paths(["admission_policy"]))
.poller()
.until_done()
.await?;
println!("Updated anywhere cache: {:?}", operation);
Ok(())
}
// [END storage_control_update_anywhere_cache]
Loading
Loading