Async Google gRPC/REST APIs and the client implementation hiding complexity of GCP authentication based on Tonic middleware and Reqwest.
This is NOT OFFICIAL Google Cloud SDK (and it doesn't exist for Rust at the time this page updated).
This library contains all the code generated from the Google API for gRPC and REST APIs.
When using each product API, you must explicitly include it in your build using a feature flag.
For example, if you want to use Cloud Pub/Sub, write features = ["google-pubsub-v1"]
to Cargo.toml.
The feature name is the period of the package name of each proto file, replaced by a hyphen.
If you specify a package, it will automatically load the dependent packages and include them in the build.
It means that features = ["google-firestore-v1"]
.
In addition, multiple features can be specified.
The list of available features can be found here.
```rust
// The library handles getting token from environment automatically
let firestoreclient: GoogleApi
let response = firestore_client
.get()
.list_documents(tonic::Request::new(ListDocumentsRequest {
parent: format!("{}/documents", cloud_resource_prefix),
..Default::default()
}))
.await?;
``` More complete examples are located here.
Cargo.toml:
toml
[dependencies]
gcloud-sdk = { version = "0.19", features = ["google-firestore-v1"] }
tonic = { version = "0.8", features = ["tls"] }
prost = "0.11"
prost-types = "0.11"
```rust let googlerestclient = gcloud_sdk::GoogleRestApi::new().await?;
let response = gcloudsdk::googlerestapis::storagev1::bucketsapi::storagebucketslist( &googlerestclient.creategooglestoragev1config().await?, gcloudsdk::googlerestapis::storagev1::bucketsapi::StoragePeriodBucketsPeriodListParams { project: googleprojectid, ..Default::default() } ).await?;
```
Default Scope is https://www.googleapis.com/auth/cloud-platform
.
To specify custom scopes there is from_function_with_scopes()
function
instead of from_function()
;
Looks for credentials in the following places, preferring the first location found:
- A JSON file whose path is specified by the GOOGLEAPPLICATIONCREDENTIALS environment variable.
- A JSON file in a location known to the gcloud command-line tool using gcloud auth application-default login
.
- On Google Compute Engine, it fetches credentials from the metadata server.
Don't confuse gcloud auth login
with gcloud auth application-default login
for local development,
since the first authorize only gcloud
tool to access the Cloud Platform.
The latter obtains user access credentials via a web flow and puts them in the well-known location for Application Default Credentials (ADC).
This command is useful when you are developing code that would normally use a service account but need to run the code in a local development environment where it's easier to provide user credentials.
So to work for local development you need to use gcloud auth application-default login
.
Sometimes using proto generated APIs are tedious and cumbersome, so you may need to introduce facade APIs on top of them: * firestore - to work with Firestore; * secret-vault - to read secrets from Google Secret Manager; * kms-aead - envelope encryption using Google KMS and Ring AEAD. * opentelemetry-gcloud-trace - Google Cloud Trace support for OpenTelemetry project.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
The library was started as a fork of mechiru/googapis and mechiru/gouth libraries, but now includes much more: