|
| 1 | +# Azure KeyVault keys client library for Rust |
| 2 | + |
| 3 | +Azure Key Vault is a cloud service that provides secure storage and management of sensitive information such as API keys, passwords, certificates, and cryptographic keys. The `azure_security_keyvault_keys` crate provides a client library for interacting with the Azure Key Vault Keys service. |
| 4 | + |
| 5 | +## Getting started |
| 6 | + |
| 7 | +### Install the crate |
| 8 | + |
| 9 | +Install the Azure Key Vault keys library for Rust with cargo: |
| 10 | + |
| 11 | +```bash |
| 12 | +cargo add azure_security_keyvault_keys |
| 13 | +``` |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | + |
| 17 | +- An [Azure subscription](https://azure.microsoft.com/free/) |
| 18 | +- A [Key Vault resource](https://docs.microsoft.com/azure/key-vault/quick-create-portal) |
| 19 | + |
| 20 | +### Authentication |
| 21 | + |
| 22 | +This crate uses the [azure_identity](https://crates.io/crates/azure_identity) crate for authentication. You can authenticate using a variety of methods, including environment variables, managed identity, and more. |
| 23 | + |
| 24 | +## Key concepts |
| 25 | + |
| 26 | +### KeyClient |
| 27 | + |
| 28 | +The `KeyClient` struct provides methods to manage keys in the Azure Key Vault. You can create, retrieve, update, and delete keys, as well as perform cryptographic operations. |
| 29 | + |
| 30 | +## Examples |
| 31 | + |
| 32 | +### Creating a key |
| 33 | + |
| 34 | +```rust no_run |
| 35 | +use azure_identity::DefaultAzureCredential; |
| 36 | +use azure_security_keyvault_keys::{models::KeyCreateParameters, KeyClient}; |
| 37 | + |
| 38 | +#[tokio::main] |
| 39 | +async fn main() -> Result<(), Box<dyn std::error::Error>> { |
| 40 | + let credential = DefaultAzureCredential::new()?; |
| 41 | + |
| 42 | + let client = KeyClient::new( |
| 43 | + "https://<your-key-vault-name>.vault.azure.net", |
| 44 | + credential.clone(), |
| 45 | + None, |
| 46 | + )?; |
| 47 | + |
| 48 | + let key = client |
| 49 | + .create_key("my-key", KeyCreateParameters::default().try_into()?, None) |
| 50 | + .await? |
| 51 | + .into_body() |
| 52 | + .await?; |
| 53 | + |
| 54 | + println!("Created key: {:?}", key); |
| 55 | + |
| 56 | + Ok(()) |
| 57 | +} |
| 58 | + |
| 59 | +## Contributing |
| 60 | + |
| 61 | +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit [https://cla.microsoft.com](https://cla.microsoft.com). |
| 62 | + |
| 63 | +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. |
| 64 | + |
| 65 | +This project has adopted the [ Microsoft Open Source Code of Conduct](https ://opensource.microsoft.com/codeofconduct/). For more information, see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments. |
0 commit comments