google_cloud_kms/lib.rs
1//! # google-cloud-kms
2//!
3//! Google Cloud Platform Key Management Service Client library.
4//!
5//! ## Quickstart
6//!
7//! ### Authentication
8//! There are two ways to create a client that is authenticated against the google cloud.
9//!
10//! #### Automatically
11//!
12//! The function `with_auth()` will try and read the credentials from a file specified in the environment variable `GOOGLE_APPLICATION_CREDENTIALS`, `GOOGLE_APPLICATION_CREDENTIALS_JSON` or
13//! from a metadata server.
14//!
15//! This is also described in [google-cloud-auth](https://github.com/yoshidan/google-cloud-rust/blob/main/foundation/auth/README.md)
16//!
17//! ```rust
18//! use google_cloud_kms::client::{Client, ClientConfig};
19//!
20//! async fn run() {
21//! let config = ClientConfig::default().with_auth().await.unwrap();
22//! let client = Client::new(config);
23//! }
24//! ```
25//!
26//! #### Manually
27//!
28//! When you can't use the `gcloud` authentication but you have a different way to get your credentials (e.g a different environment variable)
29//! you can parse your own version of the 'credentials-file' and use it like that:
30//!
31//! ```rust
32//! use google_cloud_auth::credentials::CredentialsFile;
33//! // or google_cloud_kms::client::google_cloud_auth::credentials::CredentialsFile
34//! use google_cloud_kms::client::{Client, ClientConfig};
35//!
36//! async fn run(cred: CredentialsFile) {
37//! let config = ClientConfig::default().with_credentials(cred).await.unwrap();
38//! let client = Client::new(config);
39//! }
40//! ```
41//!
42//! ### Usage
43//!
44//! #### Key ring operations
45//!
46//! ```
47//! use std::collections::HashMap;
48//! use prost_types::FieldMask;
49//! use google_cloud_googleapis::cloud::kms::v1::{CreateKeyRingRequest, GetKeyRingRequest, ListKeyRingsRequest};
50//! use google_cloud_kms::client::{Client, ClientConfig};
51//!
52//! async fn run(config: ClientConfig) {
53//!
54//! // Create client
55//! let client = Client::new(config).await.unwrap();
56//!
57//! // Key ring
58//! // create
59//! match client
60//! .create_key_ring(
61//! CreateKeyRingRequest {
62//! parent: "projects/qovery-gcp-tests/locations/europe-west9".to_string(),
63//! key_ring_id: "123-456".to_string(),
64//! key_ring: None,
65//! },
66//! None,
67//! )
68//! .await
69//! {
70//! Ok(mut r) => println!("Created key ring {:?}", r),
71//! Err(err) => panic!("err: {:?}", err),
72//! };
73//!
74//! // list
75//! match client
76//! .list_key_rings(
77//! ListKeyRingsRequest {
78//! parent: "projects/qovery-gcp-tests/locations/europe-west9".to_string(),
79//! page_size: 5,
80//! page_token: "".to_string(),
81//! filter: "".to_string(),
82//! order_by: "".to_string(),
83//! },
84//! None,
85//! )
86//! .await
87//! {
88//! Ok(response) => {
89//! println!("List key rings");
90//! for r in response.key_rings {
91//! println!("- {:?}", r);
92//! }
93//! }
94//! Err(err) => panic!("err: {:?}", err),
95//! };
96//!
97//! // get
98//! match client
99//! .get_key_ring(
100//! GetKeyRingRequest {
101//! name: "projects/qovery-gcp-tests/locations/europe-west9/keyRings/key-ring-for-documentation"
102//! .to_string(),
103//! },
104//! None,
105//! )
106//! .await
107//! {
108//! Ok(response) => {
109//! println!("Get keyring: {:?}", response);
110//! }
111//! Err(err) => panic!("err: {:?}", err),
112//! }
113//!}
114//!```
115//!
116//! ### Ethereum Integration
117//!
118//! Enable 'eth' feature.
119//! google-cloud-kms = { version="version", features=["eth"] }
120//!
121//! ```
122//! use ethers::prelude::SignerMiddleware;
123//! use ethers::providers::{Http, Middleware, Provider};
124//! use ethers_core::types::{TransactionReceipt, TransactionRequest};
125//! use ethers_signers::Signer as EthSigner;
126//! use google_cloud_kms::client::Client;
127//! use google_cloud_kms::signer::ethereum::{Error, Signer};
128//!
129//! pub async fn send_bnb(client: Client, key_name: &str, rpc_node: &str) {
130//!
131//! // BSC testnet
132//! let chain_id = 97;
133//!
134//! let signer = Signer::new(client, key_name, chain_id, None).await.unwrap();
135//! let provider = Provider::<Http>::try_from(rpc_node).unwrap();
136//! let signer_address = signer.address();
137//!
138//! let eth_client = SignerMiddleware::new_with_provider_chain(provider, signer).await.unwrap();
139//!
140//! let tx = TransactionRequest::new()
141//! .to(signer_address)
142//! .value(100_000_000_000_000_u128)
143//! .gas(1_500_000_u64)
144//! .gas_price(4_000_000_000_u64)
145//! .chain_id(chain_id);
146//!
147//! let res = eth_client.send_transaction(tx, None).await.unwrap();
148//! let receipt: TransactionReceipt = res.confirmations(3).await.unwrap().unwrap();
149//! }
150//! ```
151pub mod client;
152pub mod grpc;
153pub mod signer;