-
Notifications
You must be signed in to change notification settings - Fork 103
docs(storage): folder and manage folder examples #2885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // 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. | ||
|
|
||
| pub mod create_folder; | ||
| pub mod delete_folder; | ||
| pub mod get_folder; | ||
| 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 rename_folder; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_control_create_folder] | ||
| use google_cloud_storage::{client::StorageControl, model::Folder}; | ||
|
|
||
| pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> { | ||
| const ID: &str = "example-folder-id"; | ||
| let folder = client | ||
| .create_folder() | ||
| .set_parent(format!("projects/_/buckets/{bucket_id}")) | ||
| .set_folder_id(ID) | ||
| .set_folder(Folder::new()) | ||
| .send() | ||
| .await?; | ||
| println!("folder successfully created {folder:?}"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_create_folder] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // 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_delete_folder] | ||
| use google_cloud_storage::client::StorageControl; | ||
|
|
||
| pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> { | ||
| const ID: &str = "deleted-folder-id"; | ||
| client | ||
| .delete_folder() | ||
| .set_name(format!("projects/_/buckets/{bucket_id}/folders/{ID}")) | ||
| .send() | ||
| .await?; | ||
| println!("folder successfully deleted"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_delete_folder] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // 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_folder] | ||
| use google_cloud_storage::client::StorageControl; | ||
|
|
||
| pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> { | ||
| const ID: &str = "example-folder-id"; | ||
| let folder = client | ||
| .get_folder() | ||
| .set_name(format!("projects/_/buckets/{bucket_id}/folders/{ID}")) | ||
| .send() | ||
| .await?; | ||
| println!("folder metadata successfully retrieved {folder:?}"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_get_folder] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // 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_folders] | ||
| 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 items = client | ||
| .list_folders() | ||
| .set_parent(format!("projects/_/buckets/{bucket_id}")) | ||
| .by_item(); | ||
| println!("Listing folders in bucket {bucket_id}"); | ||
| while let Some(folder) = items.next().await.transpose()? { | ||
| println!("{folder:?}"); | ||
| } | ||
| println!("DONE"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_list_folders] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_control_managed_folder_create] | ||
| use google_cloud_storage::{client::StorageControl, model::ManagedFolder}; | ||
|
|
||
| pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> { | ||
| const ID: &str = "example001"; | ||
| let folder = client | ||
| .create_managed_folder() | ||
| .set_parent(format!("projects/_/buckets/{bucket_id}")) | ||
| .set_managed_folder_id(ID) | ||
| .set_managed_folder(ManagedFolder::new()) | ||
| .send() | ||
| .await?; | ||
| println!("folder successfully created {folder:?}"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_managed_folder_create] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_control_managed_folder_delete] | ||
| use google_cloud_storage::client::StorageControl; | ||
|
|
||
| pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> { | ||
| const ID: &str = "example001"; | ||
| client | ||
| .delete_managed_folder() | ||
| .set_name(format!( | ||
| "projects/_/buckets/{bucket_id}/managedFolders/{ID}" | ||
| )) | ||
| .send() | ||
| .await?; | ||
| println!("folder successfully deleted"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_managed_folder_delete] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_control_managed_folder_get] | ||
| use google_cloud_storage::client::StorageControl; | ||
|
|
||
| pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> { | ||
| const ID: &str = "example001"; | ||
| let folder = client | ||
| .get_managed_folder() | ||
| .set_name(format!( | ||
| "projects/_/buckets/{bucket_id}/managedFolders/{ID}" | ||
| )) | ||
| .send() | ||
| .await?; | ||
| println!("successfully retrieved managed folder metadata: {folder:?}"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_managed_folder_get] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // 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_managed_folder_list] | ||
| 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 items = client | ||
| .list_managed_folders() | ||
| .set_parent(format!("projects/_/buckets/{bucket_id}")) | ||
| .by_item(); | ||
| println!("Listing managed folders in bucket {bucket_id}"); | ||
| while let Some(folder) = items.next().await.transpose()? { | ||
| println!("{folder:?}"); | ||
| } | ||
| println!("DONE"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_managed_folder_list] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // 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_rename_folder] | ||
| use google_cloud_lro::Poller; | ||
| use google_cloud_storage::client::StorageControl; | ||
|
|
||
| pub async fn sample(client: &StorageControl, bucket_id: &str) -> anyhow::Result<()> { | ||
| const ID: &str = "example-folder-id"; | ||
| const NEW_ID: &str = "renamed-folder-id"; | ||
coryan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| let folder = client | ||
| .rename_folder() | ||
| .set_name(format!("projects/_/buckets/{bucket_id}/folders/{ID}")) | ||
| .set_destination_folder_id(NEW_ID) | ||
| .poller() | ||
| .until_done() | ||
| .await?; | ||
| println!("folder successfully renamed {folder:?}"); | ||
| Ok(()) | ||
| } | ||
| // [END storage_control_rename_folder] | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.