@azure/keyvault-certificates 4.9.1-alpha.20250206.1 → 4.9.1-alpha.20250211.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +173 -196
- package/dist/browser/identifier.d.ts +1 -1
- package/dist/browser/identifier.js +1 -1
- package/dist/browser/identifier.js.map +1 -1
- package/dist/browser/index.d.ts +371 -149
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.js +371 -149
- package/dist/browser/index.js.map +1 -1
- package/dist/commonjs/identifier.d.ts +1 -1
- package/dist/commonjs/identifier.js +1 -1
- package/dist/commonjs/identifier.js.map +1 -1
- package/dist/commonjs/index.d.ts +371 -149
- package/dist/commonjs/index.d.ts.map +1 -1
- package/dist/commonjs/index.js +371 -149
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/identifier.d.ts +1 -1
- package/dist/esm/identifier.js +1 -1
- package/dist/esm/identifier.js.map +1 -1
- package/dist/esm/index.d.ts +371 -149
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +371 -149
- package/dist/esm/index.js.map +1 -1
- package/dist/react-native/identifier.d.ts +1 -1
- package/dist/react-native/identifier.js +1 -1
- package/dist/react-native/identifier.js.map +1 -1
- package/dist/react-native/index.d.ts +371 -149
- package/dist/react-native/index.d.ts.map +1 -1
- package/dist/react-native/index.js +371 -149
- package/dist/react-native/index.js.map +1 -1
- package/package.json +18 -18
package/README.md
CHANGED
|
@@ -65,18 +65,11 @@ In order to interact with the Azure Key Vault service, you will need to create a
|
|
|
65
65
|
|
|
66
66
|
You can find more information on different ways of authenticating and their corresponding credential types in the [Azure Identity documentation][azure_identity].
|
|
67
67
|
|
|
68
|
-
Here's a quick example. First, import `DefaultAzureCredential` and `CertificateClient
|
|
68
|
+
Here's a quick example. First, import `DefaultAzureCredential` and `CertificateClient`. Once these are imported, we can next connect to the key vault service:
|
|
69
69
|
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
Once these are imported, we can next connect to the key vault service:
|
|
76
|
-
|
|
77
|
-
```javascript
|
|
78
|
-
const { DefaultAzureCredential } = require("@azure/identity");
|
|
79
|
-
const { CertificateClient } = require("@azure/keyvault-certificates");
|
|
70
|
+
```ts snippet:ReadmeSampleCreateClient
|
|
71
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
72
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
80
73
|
|
|
81
74
|
const credential = new DefaultAzureCredential();
|
|
82
75
|
|
|
@@ -110,9 +103,9 @@ const client = new CertificateClient(url, credential);
|
|
|
110
103
|
|
|
111
104
|
By default, this package uses the latest Azure Key Vault service version which is `7.1`. The only other version that is supported is `7.0`. You can change the service version being used by setting the option `serviceVersion` in the client constructor as shown below:
|
|
112
105
|
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
|
|
106
|
+
```ts snippet:ReadmeSampleCreateClientWithVersion
|
|
107
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
108
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
116
109
|
|
|
117
110
|
const credential = new DefaultAzureCredential();
|
|
118
111
|
|
|
@@ -121,7 +114,7 @@ const url = `https://${vaultName}.vault.azure.net`;
|
|
|
121
114
|
|
|
122
115
|
// Change the Azure Key Vault service API version being used via the `serviceVersion` option
|
|
123
116
|
const client = new CertificateClient(url, credential, {
|
|
124
|
-
serviceVersion: "7.
|
|
117
|
+
serviceVersion: "7.5",
|
|
125
118
|
});
|
|
126
119
|
```
|
|
127
120
|
|
|
@@ -145,9 +138,9 @@ tasks using Azure Key Vault Certificates. The scenarios that are covered here co
|
|
|
145
138
|
a certificate with the same name already exists, a new version of the
|
|
146
139
|
certificate is created.
|
|
147
140
|
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
```ts snippet:ReadmeSampleCreateCertificate
|
|
142
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
143
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
151
144
|
|
|
152
145
|
const credential = new DefaultAzureCredential();
|
|
153
146
|
|
|
@@ -158,15 +151,11 @@ const client = new CertificateClient(url, credential);
|
|
|
158
151
|
|
|
159
152
|
const certificateName = "MyCertificateName";
|
|
160
153
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
main();
|
|
154
|
+
// Note: Sending `Self` as the `issuerName` of the certificate's policy will create a self-signed certificate.
|
|
155
|
+
await client.beginCreateCertificate(certificateName, {
|
|
156
|
+
issuerName: "Self",
|
|
157
|
+
subject: "cn=MyCert",
|
|
158
|
+
});
|
|
170
159
|
```
|
|
171
160
|
|
|
172
161
|
Besides the name of the certificate and the policy, you can also pass the following properties in a third argument with optional values:
|
|
@@ -174,9 +163,9 @@ Besides the name of the certificate and the policy, you can also pass the follow
|
|
|
174
163
|
- `enabled`: A boolean value that determines whether the certificate can be used or not.
|
|
175
164
|
- `tags`: Any set of key-values that can be used to search and filter certificates.
|
|
176
165
|
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
|
|
166
|
+
```ts snippet:ReadmeSampleCreateCertificateWithOptions
|
|
167
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
168
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
180
169
|
|
|
181
170
|
const credential = new DefaultAzureCredential();
|
|
182
171
|
|
|
@@ -197,14 +186,10 @@ const tags = {
|
|
|
197
186
|
myCustomTag: "myCustomTagsValue",
|
|
198
187
|
};
|
|
199
188
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
main();
|
|
189
|
+
await client.beginCreateCertificate(certificateName, certificatePolicy, {
|
|
190
|
+
enabled,
|
|
191
|
+
tags,
|
|
192
|
+
});
|
|
208
193
|
```
|
|
209
194
|
|
|
210
195
|
Calling to `beginCreateCertificate` with the same name will create a new version of
|
|
@@ -219,9 +204,9 @@ The received poller will allow you to get the created certificate by calling to
|
|
|
219
204
|
You can also wait until the deletion finishes, either by running individual service
|
|
220
205
|
calls until the certificate is created, or by waiting until the process is done:
|
|
221
206
|
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
|
|
207
|
+
```ts snippet:ReadmeSampleCreateCertificatePoller
|
|
208
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
209
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
225
210
|
|
|
226
211
|
const credential = new DefaultAzureCredential();
|
|
227
212
|
|
|
@@ -236,26 +221,21 @@ const certificatePolicy = {
|
|
|
236
221
|
subject: "cn=MyCert",
|
|
237
222
|
};
|
|
238
223
|
|
|
239
|
-
|
|
240
|
-
const poller = await client.beginCreateCertificate(certificateName, certificatePolicy);
|
|
241
|
-
|
|
242
|
-
// You can use the pending certificate immediately:
|
|
243
|
-
const pendingCertificate = poller.getResult();
|
|
224
|
+
const poller = await client.beginCreateCertificate(certificateName, certificatePolicy);
|
|
244
225
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
console.log(keyVaultCertificate);
|
|
248
|
-
}
|
|
226
|
+
// You can use the pending certificate immediately:
|
|
227
|
+
const pendingCertificate = poller.getResult();
|
|
249
228
|
|
|
250
|
-
|
|
229
|
+
// Or you can wait until the certificate finishes being signed:
|
|
230
|
+
const keyVaultCertificate = await poller.pollUntilDone();
|
|
231
|
+
console.log(keyVaultCertificate);
|
|
251
232
|
```
|
|
252
233
|
|
|
253
234
|
Another way to wait until the certificate is signed is to do individual calls, as follows:
|
|
254
235
|
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const { delay } = require("@azure/core-util");
|
|
236
|
+
```ts snippet:ReadmeSampleCreateCertificatePollerIndividualCalls
|
|
237
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
238
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
259
239
|
|
|
260
240
|
const credential = new DefaultAzureCredential();
|
|
261
241
|
|
|
@@ -270,18 +250,16 @@ const certificatePolicy = {
|
|
|
270
250
|
subject: "cn=MyCert",
|
|
271
251
|
};
|
|
272
252
|
|
|
273
|
-
|
|
274
|
-
const poller = await client.beginCreateCertificate(certificateName, certificatePolicy);
|
|
253
|
+
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
275
254
|
|
|
276
|
-
|
|
277
|
-
await poller.poll();
|
|
278
|
-
await delay(5000);
|
|
279
|
-
}
|
|
255
|
+
const poller = await client.beginCreateCertificate(certificateName, certificatePolicy);
|
|
280
256
|
|
|
281
|
-
|
|
257
|
+
while (!poller.isDone()) {
|
|
258
|
+
await poller.poll();
|
|
259
|
+
await delay(5000);
|
|
282
260
|
}
|
|
283
261
|
|
|
284
|
-
|
|
262
|
+
console.log(`The certificate ${certificateName} is fully created`);
|
|
285
263
|
```
|
|
286
264
|
|
|
287
265
|
### Getting a Key Vault certificate
|
|
@@ -293,9 +271,9 @@ optionally get a different version of the certificate by calling
|
|
|
293
271
|
`getCertificateVersion` if you specify the version. `getCertificateVersion` does not return
|
|
294
272
|
the certificate's policy.
|
|
295
273
|
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
|
|
274
|
+
```ts snippet:ReadmeSampleGetCertificate
|
|
275
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
276
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
299
277
|
|
|
300
278
|
const credential = new DefaultAzureCredential();
|
|
301
279
|
|
|
@@ -306,20 +284,16 @@ const client = new CertificateClient(url, credential);
|
|
|
306
284
|
|
|
307
285
|
const certificateName = "MyCertificateName";
|
|
308
286
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
main();
|
|
287
|
+
const latestCertificate = await client.getCertificate(certificateName);
|
|
288
|
+
console.log(`Latest version of the certificate ${certificateName}: `, latestCertificate);
|
|
289
|
+
const specificCertificate = await client.getCertificateVersion(
|
|
290
|
+
certificateName,
|
|
291
|
+
latestCertificate.properties.version,
|
|
292
|
+
);
|
|
293
|
+
console.log(
|
|
294
|
+
`The certificate ${certificateName} at the version ${latestCertificate.properties.version}: `,
|
|
295
|
+
specificCertificate,
|
|
296
|
+
);
|
|
323
297
|
```
|
|
324
298
|
|
|
325
299
|
### Getting the full information of a certificate
|
|
@@ -340,14 +314,20 @@ Knowing that the private key is stored in a Key Vault Secret,
|
|
|
340
314
|
with the public certificate included, we can retrieve it
|
|
341
315
|
by using the Key Vault Secrets client.
|
|
342
316
|
|
|
343
|
-
```ts
|
|
344
|
-
|
|
345
|
-
// and the same keyVaultUrl,
|
|
346
|
-
// let's create a SecretClient
|
|
317
|
+
```ts snippet:ReadmeSampleGetCertificateFullInfo
|
|
318
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
347
319
|
import { SecretClient } from "@azure/keyvault-secrets";
|
|
320
|
+
import { writeFileSync } from "node:fs";
|
|
321
|
+
|
|
322
|
+
const credential = new DefaultAzureCredential();
|
|
323
|
+
|
|
324
|
+
const vaultName = "<YOUR KEYVAULT NAME>";
|
|
325
|
+
const keyVaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
348
326
|
|
|
349
327
|
const secretClient = new SecretClient(keyVaultUrl, credential);
|
|
350
328
|
|
|
329
|
+
const certificateName = "MyCertificateName";
|
|
330
|
+
|
|
351
331
|
// Assuming you've already created a Key Vault certificate,
|
|
352
332
|
// and that certificateName contains the name of your certificate
|
|
353
333
|
const certificateSecret = await secretClient.getSecret(certificateName);
|
|
@@ -356,7 +336,7 @@ const certificateSecret = await secretClient.getSecret(certificateName);
|
|
|
356
336
|
const PKCS12Certificate = certificateSecret.value!;
|
|
357
337
|
|
|
358
338
|
// You can write this into a file:
|
|
359
|
-
|
|
339
|
+
writeFileSync("myCertificate.p12", PKCS12Certificate);
|
|
360
340
|
```
|
|
361
341
|
|
|
362
342
|
Note that, by default, the content type of the certificates
|
|
@@ -395,7 +375,18 @@ The following example shows how to create and retrieve
|
|
|
395
375
|
the public and the private parts of a PEM formatted certificate
|
|
396
376
|
using the Key Vault clients for Certificates and Secrets:
|
|
397
377
|
|
|
398
|
-
```ts
|
|
378
|
+
```ts snippet:ReadmeSampleCreateCertificatePEM
|
|
379
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
380
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
381
|
+
import { SecretClient } from "@azure/keyvault-secrets";
|
|
382
|
+
|
|
383
|
+
const credential = new DefaultAzureCredential();
|
|
384
|
+
|
|
385
|
+
const vaultName = "<YOUR KEYVAULT NAME>";
|
|
386
|
+
const keyVaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
387
|
+
|
|
388
|
+
const client = new CertificateClient(keyVaultUrl, credential);
|
|
389
|
+
const secretClient = new SecretClient(keyVaultUrl, credential);
|
|
399
390
|
// Creating the certificate
|
|
400
391
|
const certificateName = "MyCertificate";
|
|
401
392
|
const createPoller = await client.beginCreateCertificate(certificateName, {
|
|
@@ -403,7 +394,7 @@ const createPoller = await client.beginCreateCertificate(certificateName, {
|
|
|
403
394
|
subject: "cn=MyCert",
|
|
404
395
|
contentType: "application/x-pem-file", // Here you specify you want to work with PEM certificates.
|
|
405
396
|
});
|
|
406
|
-
|
|
397
|
+
await createPoller.pollUntilDone();
|
|
407
398
|
|
|
408
399
|
// Getting the PEM formatted private key and public certificate:
|
|
409
400
|
const certificateSecret = await secretClient.getSecret(certificateName);
|
|
@@ -420,24 +411,30 @@ You can use the PEM headers to extract them accordingly.
|
|
|
420
411
|
|
|
421
412
|
`listPropertiesOfCertificates` will list all certificates in the Key Vault.
|
|
422
413
|
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
|
|
414
|
+
```ts snippet:ReadmeSampleListCertificates
|
|
415
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
416
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
426
417
|
|
|
427
418
|
const credential = new DefaultAzureCredential();
|
|
428
419
|
|
|
429
420
|
const vaultName = "<YOUR KEYVAULT NAME>";
|
|
430
|
-
const
|
|
421
|
+
const keyVaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
431
422
|
|
|
432
|
-
const client = new CertificateClient(
|
|
423
|
+
const client = new CertificateClient(keyVaultUrl, credential);
|
|
433
424
|
|
|
434
|
-
|
|
435
|
-
for await (let certificateProperties of client.listPropertiesOfCertificates()) {
|
|
436
|
-
console.log("Certificate properties: ", certificateProperties);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
425
|
+
const certificateName = "MyCertificate";
|
|
439
426
|
|
|
440
|
-
|
|
427
|
+
for await (const certificateProperties of client.listPropertiesOfCertificates()) {
|
|
428
|
+
console.log("Certificate properties: ", certificateProperties);
|
|
429
|
+
}
|
|
430
|
+
for await (const deletedCertificate of client.listDeletedCertificates()) {
|
|
431
|
+
console.log("Deleted certificate: ", deletedCertificate);
|
|
432
|
+
}
|
|
433
|
+
for await (const certificateProperties of client.listPropertiesOfCertificateVersions(
|
|
434
|
+
certificateName,
|
|
435
|
+
)) {
|
|
436
|
+
console.log("Certificate properties: ", certificateProperties);
|
|
437
|
+
}
|
|
441
438
|
```
|
|
442
439
|
|
|
443
440
|
### Updating a certificate
|
|
@@ -445,57 +442,49 @@ main();
|
|
|
445
442
|
The certificate attributes can be updated to an existing certificate version with
|
|
446
443
|
`updateCertificate`, as follows:
|
|
447
444
|
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
|
|
445
|
+
```ts snippet:ReadmeSampleUpdateCertificate
|
|
446
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
447
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
451
448
|
|
|
452
449
|
const credential = new DefaultAzureCredential();
|
|
453
450
|
|
|
454
451
|
const vaultName = "<YOUR KEYVAULT NAME>";
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
const client = new CertificateClient(url, credential);
|
|
452
|
+
const keyVaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
458
453
|
|
|
459
|
-
const
|
|
454
|
+
const client = new CertificateClient(keyVaultUrl, credential);
|
|
460
455
|
|
|
461
|
-
|
|
462
|
-
const result = await client.getCertificate(certificateName);
|
|
463
|
-
await client.updateCertificateProperties(certificateName, result.properties.version, {
|
|
464
|
-
enabled: false,
|
|
465
|
-
tags: {
|
|
466
|
-
myCustomTag: "myCustomTagsValue",
|
|
467
|
-
},
|
|
468
|
-
});
|
|
469
|
-
}
|
|
456
|
+
const certificateName = "MyCertificate";
|
|
470
457
|
|
|
471
|
-
|
|
458
|
+
const result = await client.getCertificate(certificateName);
|
|
459
|
+
await client.updateCertificateProperties(certificateName, result.properties.version, {
|
|
460
|
+
enabled: false,
|
|
461
|
+
tags: {
|
|
462
|
+
myCustomTag: "myCustomTagsValue",
|
|
463
|
+
},
|
|
464
|
+
});
|
|
472
465
|
```
|
|
473
466
|
|
|
474
467
|
The certificate's policy can also be updated individually with `updateCertificatePolicy`, as follows:
|
|
475
468
|
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
|
|
469
|
+
```ts snippet:ReadmeSampleUpdateCertificatePolicy
|
|
470
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
471
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
479
472
|
|
|
480
473
|
const credential = new DefaultAzureCredential();
|
|
481
474
|
|
|
482
475
|
const vaultName = "<YOUR KEYVAULT NAME>";
|
|
483
|
-
const
|
|
476
|
+
const keyVaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
484
477
|
|
|
485
|
-
const client = new CertificateClient(
|
|
478
|
+
const client = new CertificateClient(keyVaultUrl, credential);
|
|
486
479
|
|
|
487
|
-
const certificateName = "
|
|
488
|
-
|
|
489
|
-
async function main() {
|
|
490
|
-
const result = client.getCertificate(certificateName);
|
|
491
|
-
// Note: Sending `Self` as the `issuerName` of the certificate's policy will create a self-signed certificate.
|
|
492
|
-
await client.updateCertificatePolicy(certificateName, {
|
|
493
|
-
issuerName: "Self",
|
|
494
|
-
subject: "cn=MyCert",
|
|
495
|
-
});
|
|
496
|
-
}
|
|
480
|
+
const certificateName = "MyCertificate";
|
|
497
481
|
|
|
498
|
-
|
|
482
|
+
const result = client.getCertificate(certificateName);
|
|
483
|
+
// Note: Sending `Self` as the `issuerName` of the certificate's policy will create a self-signed certificate.
|
|
484
|
+
await client.updateCertificatePolicy(certificateName, {
|
|
485
|
+
issuerName: "Self",
|
|
486
|
+
subject: "cn=MyCert",
|
|
487
|
+
});
|
|
499
488
|
```
|
|
500
489
|
|
|
501
490
|
### Deleting a certificate
|
|
@@ -508,42 +497,38 @@ is enabled for the Key Vault, this operation will only label the certificate as
|
|
|
508
497
|
_deleted_ certificate. A deleted certificate can't be updated. They can only be either
|
|
509
498
|
read, recovered or purged.
|
|
510
499
|
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
|
|
500
|
+
```ts snippet:ReadmeSampleDeleteCertificate
|
|
501
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
502
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
514
503
|
|
|
515
504
|
const credential = new DefaultAzureCredential();
|
|
516
505
|
|
|
517
506
|
const vaultName = "<YOUR KEYVAULT NAME>";
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
const client = new CertificateClient(url, credential);
|
|
507
|
+
const keyVaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
521
508
|
|
|
522
|
-
const
|
|
509
|
+
const client = new CertificateClient(keyVaultUrl, credential);
|
|
523
510
|
|
|
524
|
-
|
|
525
|
-
const poller = await client.beginDeleteCertificate(certificateName);
|
|
511
|
+
const certificateName = "MyCertificate";
|
|
526
512
|
|
|
527
|
-
|
|
528
|
-
const deletedCertificate = poller.getResult();
|
|
513
|
+
const poller = await client.beginDeleteCertificate(certificateName);
|
|
529
514
|
|
|
530
|
-
|
|
531
|
-
|
|
515
|
+
// You can use the deleted certificate immediately:
|
|
516
|
+
const deletedCertificate = poller.getResult();
|
|
532
517
|
|
|
533
|
-
|
|
534
|
-
|
|
518
|
+
// The certificate is being deleted. Only wait for it if you want to restore it or purge it.
|
|
519
|
+
await poller.pollUntilDone();
|
|
535
520
|
|
|
536
|
-
|
|
521
|
+
// You can also get the deleted certificate this way:
|
|
522
|
+
await client.getDeletedCertificate(certificateName);
|
|
537
523
|
|
|
538
|
-
|
|
539
|
-
// const recoverPoller = await client.beginRecoverDeletedCertificate(certificateName);
|
|
540
|
-
// await recoverPoller.pollUntilDone();
|
|
524
|
+
// Deleted certificates can also be recovered or purged.
|
|
541
525
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
526
|
+
// recoverDeletedCertificate returns a poller, just like beginDeleteCertificate.
|
|
527
|
+
// const recoverPoller = await client.beginRecoverDeletedCertificate(certificateName);
|
|
528
|
+
// await recoverPoller.pollUntilDone();
|
|
545
529
|
|
|
546
|
-
|
|
530
|
+
// If a certificate is done and the Key Vault has soft-delete enabled, the certificate can be purged with:
|
|
531
|
+
await client.purgeDeletedCertificate(certificateName);
|
|
547
532
|
```
|
|
548
533
|
|
|
549
534
|
Since the deletion of a certificate won't happen instantly, some time is needed
|
|
@@ -565,79 +550,71 @@ versions of a specific certificate. The following API methods are available:
|
|
|
565
550
|
|
|
566
551
|
Which can be used as follows:
|
|
567
552
|
|
|
568
|
-
```
|
|
569
|
-
|
|
570
|
-
|
|
553
|
+
```ts snippet:ReadmeSampleListCertificates
|
|
554
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
555
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
571
556
|
|
|
572
557
|
const credential = new DefaultAzureCredential();
|
|
573
558
|
|
|
574
559
|
const vaultName = "<YOUR KEYVAULT NAME>";
|
|
575
|
-
const
|
|
560
|
+
const keyVaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
576
561
|
|
|
577
|
-
const client = new CertificateClient(
|
|
562
|
+
const client = new CertificateClient(keyVaultUrl, credential);
|
|
578
563
|
|
|
579
|
-
const certificateName = "
|
|
564
|
+
const certificateName = "MyCertificate";
|
|
580
565
|
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
)
|
|
591
|
-
console.log("Certificate properties: ", certificateProperties);
|
|
592
|
-
}
|
|
566
|
+
for await (const certificateProperties of client.listPropertiesOfCertificates()) {
|
|
567
|
+
console.log("Certificate properties: ", certificateProperties);
|
|
568
|
+
}
|
|
569
|
+
for await (const deletedCertificate of client.listDeletedCertificates()) {
|
|
570
|
+
console.log("Deleted certificate: ", deletedCertificate);
|
|
571
|
+
}
|
|
572
|
+
for await (const certificateProperties of client.listPropertiesOfCertificateVersions(
|
|
573
|
+
certificateName,
|
|
574
|
+
)) {
|
|
575
|
+
console.log("Certificate properties: ", certificateProperties);
|
|
593
576
|
}
|
|
594
|
-
|
|
595
|
-
main();
|
|
596
577
|
```
|
|
597
578
|
|
|
598
579
|
All of these methods will return **all of the available results** at once. To
|
|
599
580
|
retrieve them by pages, add `.byPage()` right after invoking the API method you
|
|
600
581
|
want to use, as follows:
|
|
601
582
|
|
|
602
|
-
```
|
|
603
|
-
|
|
604
|
-
|
|
583
|
+
```ts snippet:ReadmeSampleListCertificatesByPage
|
|
584
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
585
|
+
import { CertificateClient } from "@azure/keyvault-certificates";
|
|
605
586
|
|
|
606
587
|
const credential = new DefaultAzureCredential();
|
|
607
588
|
|
|
608
589
|
const vaultName = "<YOUR KEYVAULT NAME>";
|
|
609
|
-
const
|
|
590
|
+
const keyVaultUrl = `https://${vaultName}.vault.azure.net`;
|
|
610
591
|
|
|
611
|
-
const client = new CertificateClient(
|
|
592
|
+
const client = new CertificateClient(keyVaultUrl, credential);
|
|
612
593
|
|
|
613
|
-
const certificateName = "
|
|
594
|
+
const certificateName = "MyCertificate";
|
|
614
595
|
|
|
615
|
-
|
|
616
|
-
for
|
|
617
|
-
|
|
618
|
-
console.log("Certificate properties: ", certificateProperties);
|
|
619
|
-
}
|
|
596
|
+
for await (const page of client.listPropertiesOfCertificates().byPage()) {
|
|
597
|
+
for (const certificateProperties of page) {
|
|
598
|
+
console.log("Certificate properties: ", certificateProperties);
|
|
620
599
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
600
|
+
}
|
|
601
|
+
for await (const page of client.listDeletedCertificates().byPage()) {
|
|
602
|
+
for (const deletedCertificate of page) {
|
|
603
|
+
console.log("Deleted certificate: ", deletedCertificate);
|
|
625
604
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
605
|
+
}
|
|
606
|
+
for await (const page of client.listPropertiesOfCertificateVersions(certificateName).byPage()) {
|
|
607
|
+
for (const certificateProperties of page) {
|
|
608
|
+
console.log("Properties of certificate: ", certificateProperties);
|
|
630
609
|
}
|
|
631
610
|
}
|
|
632
|
-
|
|
633
|
-
main();
|
|
634
611
|
```
|
|
635
612
|
|
|
636
613
|
## Troubleshooting
|
|
637
614
|
|
|
638
615
|
Enabling logging may help uncover useful information about failures. In order to see a log of HTTP requests and responses, set the `AZURE_LOG_LEVEL` environment variable to `info`. Alternatively, logging can be enabled at runtime by calling `setLogLevel` in the `@azure/logger`:
|
|
639
616
|
|
|
640
|
-
```
|
|
617
|
+
```ts snippet:SetLogLevel
|
|
641
618
|
import { setLogLevel } from "@azure/logger";
|
|
642
619
|
|
|
643
620
|
setLogLevel("info");
|
|
@@ -28,7 +28,7 @@ export interface KeyVaultCertificateIdentifier {
|
|
|
28
28
|
* https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>
|
|
29
29
|
*
|
|
30
30
|
* On parsing the above Id, this function returns:
|
|
31
|
-
*```ts
|
|
31
|
+
*```ts snippet:ignore
|
|
32
32
|
* {
|
|
33
33
|
* sourceId: "https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>",
|
|
34
34
|
* vaultUrl: "https://<keyvault-name>.vault.azure.net",
|
|
@@ -7,7 +7,7 @@ import { parseKeyVaultIdentifier } from "@azure/keyvault-common";
|
|
|
7
7
|
* https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>
|
|
8
8
|
*
|
|
9
9
|
* On parsing the above Id, this function returns:
|
|
10
|
-
*```ts
|
|
10
|
+
*```ts snippet:ignore
|
|
11
11
|
* {
|
|
12
12
|
* sourceId: "https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>",
|
|
13
13
|
* vaultUrl: "https://<keyvault-name>.vault.azure.net",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifier.js","sourceRoot":"","sources":["../../src/identifier.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AA8BjE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,kCAAkC,CAAC,EAAU;IAC3D,MAAM,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/B,uBACE,QAAQ,EAAE,EAAE,IACT,uBAAuB,CAAC,UAAU,EAAE,EAAE,CAAC,EAC1C;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { parseKeyVaultIdentifier } from \"@azure/keyvault-common\";\n\n/**\n * Represents the segments that compose a Key Vault Certificate Id.\n */\nexport interface KeyVaultCertificateIdentifier {\n /**\n * The complete representation of the Key Vault Certificate Id. For example:\n *\n * https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>\n *\n */\n sourceId: string;\n\n /**\n * The URL of the Azure Key Vault instance to which the Certificate belongs.\n */\n vaultUrl: string;\n\n /**\n * The version of Key Vault Certificate. Might be undefined.\n */\n version?: string;\n\n /**\n * The name of the Key Vault Certificate.\n */\n name: string;\n}\n\n/**\n * Parses the given Key Vault Certificate Id. An example is:\n *\n * https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>\n *\n * On parsing the above Id, this function returns:\n *```ts\n * {\n * sourceId: \"https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>\",\n * vaultUrl: \"https://<keyvault-name>.vault.azure.net\",\n * version: \"<unique-version-id>\",\n * name: \"<certificate-name>\"\n * }\n *```\n * @param id - The Id of the Key Vault Certificate.\n */\nexport function parseKeyVaultCertificateIdentifier(id: string): KeyVaultCertificateIdentifier {\n const urlParts = id.split(\"/\");\n const collection = urlParts[3];\n\n return {\n sourceId: id,\n ...parseKeyVaultIdentifier(collection, id),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"identifier.js","sourceRoot":"","sources":["../../src/identifier.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AA8BjE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,kCAAkC,CAAC,EAAU;IAC3D,MAAM,QAAQ,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,UAAU,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE/B,uBACE,QAAQ,EAAE,EAAE,IACT,uBAAuB,CAAC,UAAU,EAAE,EAAE,CAAC,EAC1C;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { parseKeyVaultIdentifier } from \"@azure/keyvault-common\";\n\n/**\n * Represents the segments that compose a Key Vault Certificate Id.\n */\nexport interface KeyVaultCertificateIdentifier {\n /**\n * The complete representation of the Key Vault Certificate Id. For example:\n *\n * https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>\n *\n */\n sourceId: string;\n\n /**\n * The URL of the Azure Key Vault instance to which the Certificate belongs.\n */\n vaultUrl: string;\n\n /**\n * The version of Key Vault Certificate. Might be undefined.\n */\n version?: string;\n\n /**\n * The name of the Key Vault Certificate.\n */\n name: string;\n}\n\n/**\n * Parses the given Key Vault Certificate Id. An example is:\n *\n * https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>\n *\n * On parsing the above Id, this function returns:\n *```ts snippet:ignore\n * {\n * sourceId: \"https://<keyvault-name>.vault.azure.net/certificates/<certificate-name>/<unique-version-id>\",\n * vaultUrl: \"https://<keyvault-name>.vault.azure.net\",\n * version: \"<unique-version-id>\",\n * name: \"<certificate-name>\"\n * }\n *```\n * @param id - The Id of the Key Vault Certificate.\n */\nexport function parseKeyVaultCertificateIdentifier(id: string): KeyVaultCertificateIdentifier {\n const urlParts = id.split(\"/\");\n const collection = urlParts[3];\n\n return {\n sourceId: id,\n ...parseKeyVaultIdentifier(collection, id),\n };\n}\n"]}
|