Skip to content

Commit a1cf99b

Browse files
authored
Regenerate Key Vault with renames, update READMEs (#2459)
* Regenerate Key Vault with renames, update READMEs * Update release information * Fix typo * Set VCPKG_ROOT Also includes instructions in the root `CONTRIBUTING.md`. The unsetting of `VCPKG_ROOT` was intentional: <actions/runner-images#6376> Still, that was done a while ago and our pipelines had been working. We're still investigating *what* changed. * Remove dev-dependency on openssl Need to build openssl on Windows, but we'll tackle that post-beta.2.
1 parent e715663 commit a1cf99b

File tree

35 files changed

+1618
-1371
lines changed

35 files changed

+1618
-1371
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"undelete",
7070
"upvote",
7171
"userdelegationkey",
72+
"vcpkg",
7273
"versionid",
7374
"virtualmachine",
7475
"worktree"

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,38 @@ Alternatively, you can build any one or more crates by passing their crate names
3030
You can also build the entire workspace by either building from the root source directory or running `cargo build --workspace`, but unless you're making changes to `azure_core`
3131
or its dependencies, this is generally unnecessary nor recommended. It will take considerable time and drive space.
3232

33+
### Building on Windows
34+
35+
By default we use the [`openssl`](https://crates.io/crates/openssl) crate and, indirectly, the [`openssl-sys`](https://crates.io/crates/openssl-sys) crate. On Windows, you may need to download and build openssl before you can successfully compile.
36+
Since `openssl-sys` supports [vcpkg](https://learn.microsoft.com/vcpkg/), you can bootstrap OpenSSL:
37+
38+
1. Clone `vcpkg` somewhere in your development environment:
39+
40+
```pwsh
41+
git clone --depth=1 https://github.com/microsoft/vcpkg.git
42+
```
43+
44+
2. Run the bootstrap script to download a prebuilt binary:
45+
46+
```pwsh
47+
cd vcpkg; .\bootstrap-vcpkg.bat
48+
```
49+
50+
3. Set up environment variables:
51+
52+
```pwsh
53+
$env:VCPKG_ROOT = "C:\path\to\vcpkg" # from step 1
54+
$env:PATH = "${env:VCPKG_ROOT};${env:PATH}"
55+
```
56+
57+
To persist these variables for future sessions, remember to set them in the Windows System Environment Variables panel.
58+
59+
4. In the root of this repo, run:
60+
61+
```pwsh
62+
vcpkg install
63+
```
64+
3365
### Linting
3466

3567
You can run `cargo clippy` to check for common issues. Like `cargo build`, you can pass one or more crate names to `--package`.

eng/emitter-package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/emitter-package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"main": "dist/src/index.js",
33
"dependencies": {
4-
"@azure-tools/typespec-rust": "0.13.2"
4+
"@azure-tools/typespec-rust": "0.13.3"
55
},
66
"devDependencies": {
77
"@azure-tools/typespec-azure-core": "0.54.0",
@@ -14,4 +14,4 @@
1414
"@typespec/versioning": "0.68.0",
1515
"@typespec/xml": "0.68.0"
1616
}
17-
}
17+
}

sdk/keyvault/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "rust",
44
"TagPrefix": "rust/keyvault",
5-
"Tag": "rust/keyvault_4acaa30551"
5+
"Tag": "rust/keyvault_59ae61e2f7"
66
}

sdk/keyvault/azure_security_keyvault_certificates/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 0.1.0 (Unreleased)
3+
## 0.1.0 (2025-04-09)
44

55
### Features Added
66

sdk/keyvault/azure_security_keyvault_certificates/README.md

Lines changed: 218 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ Instantiate a `DefaultAzureCredential` to pass to the client. The same instance
5252

5353
## Key concepts
5454

55-
### CertificateBundle
55+
### Certificate
5656

57-
A Azure Key Vault certificate public key. The private key is never included when retrieving a `CertificateBundle`.
57+
A Azure Key Vault certificate public key. The private key is never included when retrieving a `Certificate`.
5858

5959
### CertificateClient
6060

@@ -66,7 +66,222 @@ We guarantee that all client instance methods are thread-safe and independent of
6666

6767
## Examples
6868

69-
> TODO
69+
The following section provides several code snippets using the `CertificateClient`, covering some of the most common Azure Key Vault certificates service related tasks:
70+
71+
* [Create a certificate](#create-a-certificate)
72+
* [Retrieve a certificate](#retrieve-a-certificate)
73+
* [Update an existing certificate](#update-an-existing-certificate)
74+
* [Delete a certificate](#delete-a-certificate)
75+
* [List certificates](#list-certificates)
76+
77+
### Create a certificate
78+
79+
`create_certificate` creates a Key Vault certificate to be stored in the Azure Key Vault. If a certificate with the same name already exists, then a new version of the certificate is created.
80+
Before we can create a new certificate, though, we need to define a certificate policy. This is used for the first certificate version and all subsequent versions of that certificate until changed.
81+
82+
```rust no_run
83+
use azure_identity::DefaultAzureCredential;
84+
use azure_security_keyvault_certificates::{
85+
models::{CertificatePolicy, CreateCertificateParameters, IssuerParameters, X509CertificateProperties},
86+
ResourceExt, CertificateClient,
87+
};
88+
use std::{sync::LazyLock, time::Duration};
89+
use tokio::time::sleep;
90+
91+
static DEFAULT_POLICY: LazyLock<CertificatePolicy> = LazyLock::new(|| CertificatePolicy {
92+
x509_certificate_properties: Some(X509CertificateProperties {
93+
subject: Some("CN=DefaultPolicy".into()),
94+
..Default::default()
95+
}),
96+
issuer_parameters: Some(IssuerParameters {
97+
name: Some("Self".into()),
98+
..Default::default()
99+
}),
100+
..Default::default()
101+
});
102+
103+
#[tokio::main]
104+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
105+
let credential = DefaultAzureCredential::new()?;
106+
let client = CertificateClient::new(
107+
"https://your-key-vault-name.vault.azure.net/",
108+
credential.clone(),
109+
None,
110+
)?;
111+
112+
// Create a self-signed certificate.
113+
let body = CreateCertificateParameters {
114+
certificate_policy: Some(DEFAULT_POLICY.clone()),
115+
..Default::default()
116+
};
117+
118+
let mut operation = client
119+
.create_certificate("certificate-name", body.try_into()?, None)
120+
.await?
121+
.into_body()
122+
.await?;
123+
let name = operation.resource_id()?.name;
124+
125+
// Wait for the certificate operation to complete.
126+
loop {
127+
if matches!(operation.status, Some(ref status) if status == "completed") {
128+
break;
129+
}
130+
131+
if let Some(err) = operation.error {
132+
return Err(azure_core::Error::new(
133+
azure_core::error::ErrorKind::Other,
134+
err.message
135+
.unwrap_or_else(|| "failed to create certificate".into()),
136+
))?;
137+
}
138+
139+
sleep(Duration::from_secs(3)).await;
140+
141+
operation = client
142+
.get_certificate_operation(&name, None)
143+
.await?
144+
.into_body()
145+
.await?;
146+
}
147+
148+
Ok(())
149+
}
150+
```
151+
152+
### Retrieve a certificate
153+
154+
`get_certificate` retrieves a certificate that was created or even still in progress in Key Vault.
155+
Setting the `certificate-version` to an empty string will return the latest version.
156+
157+
```rust no_run
158+
use azure_core::base64;
159+
use azure_identity::DefaultAzureCredential;
160+
use azure_security_keyvault_certificates::CertificateClient;
161+
162+
#[tokio::main]
163+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
164+
let credential = DefaultAzureCredential::new()?;
165+
let client = CertificateClient::new(
166+
"https://your-key-vault-name.vault.azure.net/",
167+
credential.clone(),
168+
None,
169+
)?;
170+
171+
let certificate = client
172+
.get_certificate("certificate-name", "certificate-version", None)
173+
.await?
174+
.into_body()
175+
.await?;
176+
177+
println!(
178+
"Certificate thumbprint: {:?}",
179+
certificate.x509_thumbprint.map(base64::encode)
180+
);
181+
182+
Ok(())
183+
}
184+
```
185+
186+
### Update an existing certificate
187+
188+
`update_certificate_properties` updates a certificate previously stored in the Azure Key Vault.
189+
Only the attributes of the certificate are updated. To regenerate the certificate, call `CertificateClient::create_certificate` on a certificate with the same name.
190+
191+
```rust no_run
192+
use azure_identity::DefaultAzureCredential;
193+
use azure_security_keyvault_certificates::{
194+
models::UpdateCertificatePropertiesParameters, CertificateClient,
195+
};
196+
use std::collections::HashMap;
197+
198+
#[tokio::main]
199+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
200+
let credential = DefaultAzureCredential::new()?;
201+
let client = CertificateClient::new(
202+
"https://your-key-vault-name.vault.azure.net/",
203+
credential.clone(),
204+
None,
205+
)?;
206+
207+
// Update a certificate using the certificate client.
208+
let certificate_update_parameters = UpdateCertificatePropertiesParameters {
209+
tags: HashMap::from_iter(vec![("tag-name".into(), "tag-value".into())]),
210+
..Default::default()
211+
};
212+
213+
client
214+
.update_certificate_properties(
215+
"certificate-name",
216+
"",
217+
certificate_update_parameters.try_into()?,
218+
None,
219+
)
220+
.await?
221+
.into_body()
222+
.await?;
223+
224+
Ok(())
225+
}
226+
```
227+
228+
### Delete a certificate
229+
230+
`delete_certificate` will tell Key Vault to delete a certificate but it is not deleted immediately.
231+
It will not be deleted until the service-configured data retention period - the default is 90 days - or until you call `purge_certificate` on the returned `DeletedCertificate.id`.
232+
233+
```rust no_run
234+
use azure_identity::DefaultAzureCredential;
235+
use azure_security_keyvault_certificates::CertificateClient;
236+
237+
#[tokio::main]
238+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
239+
let credential = DefaultAzureCredential::new()?;
240+
let client = CertificateClient::new(
241+
"https://your-key-vault-name.vault.azure.net/",
242+
credential.clone(),
243+
None,
244+
)?;
245+
246+
// Delete a certificate using the certificate client.
247+
client.delete_certificate("certificate-name", None).await?;
248+
249+
Ok(())
250+
}
251+
```
252+
253+
### List certificates
254+
255+
This example lists all the certificates in the specified Azure Key Vault.
256+
257+
```rust no_run
258+
use azure_identity::DefaultAzureCredential;
259+
use azure_security_keyvault_certificates::{CertificateClient, ResourceExt};
260+
use futures::TryStreamExt;
261+
262+
#[tokio::main]
263+
async fn main() -> Result<(), Box<dyn std::error::Error>> {
264+
// Create a new certificate client
265+
let credential = DefaultAzureCredential::new()?;
266+
let client = CertificateClient::new(
267+
"https://your-key-vault-name.vault.azure.net/",
268+
credential.clone(),
269+
None,
270+
)?;
271+
272+
let mut pager = client.list_certificate_properties(None)?.into_stream();
273+
while let Some(certificates) = pager.try_next().await? {
274+
let certificates = certificates.into_body().await?.value;
275+
for certificate in certificates {
276+
// Get the certificate name from the ID.
277+
let name = certificate.resource_id()?.name;
278+
println!("Found Certificate with Name: {}", name);
279+
}
280+
}
281+
282+
Ok(())
283+
}
284+
```
70285

71286
## Troubleshooting
72287

0 commit comments

Comments
 (0)