Cloud Shell is a great environment to run small examples and tests. This guide shows you how to configure Rust and install one of the Cloud Client Libraries in Cloud Shell.
Start up Cloud Shell
- In the Google Cloud console project selector , select a project.
- Open
https://shell.cloud.google.comto start a new shell. You might be prompted to authorize Cloud Shell to use your credentials for Google Cloud API calls.
Configure Rust
Cloud Shell comes with
rustuppre-installed. You can use it to install and configure the default version of Rust:rustup default stableConfirm that you have the most recent version of Rust installed:
cargo --version
Install Rust client libraries in Cloud Shell
Create a new Rust project:
cargo new my-projectChange your directory to the new project:
cd my-projectAdd the Secret Manager client library to the new project:
cargo add google-cloud-secretmanager-v1Add the google-cloud-gax crate to the new project:
cargo add google-cloud-gaxAdd the tokio crate to the new project:
cargo add tokio --features macrosEdit
src/main.rsin your project to use the Secret Manager client library:#[tokio::main] async fn main() -> Result<(), Box<dyn std::error::Error>> { use google_cloud_gax::paginator::ItemPaginator as _; use google_cloud_secretmanager_v1::client::SecretManagerService; let project_id = std::env::args().nth(1).unwrap(); let client = SecretManagerService::builder().build().await?; let mut items = client .list_secrets() .set_parent(format!("projects/{project_id}")) .by_item(); while let Some(item) = items.next().await { println!("{}", item?.name); } Ok(()) }Run your program, supplying your Google Cloud project ID:
PROJECT_ID=$(gcloud config get project) cargo run ${PROJECT_ID}The program will print the secrets associated with your project ID. If you don't see any secrets, you might not have any in Secret Manager. Create a secret and rerun the program, and you should see the secret printed in the output.