@azure/keyvault-secrets
Version:
95 lines • 3.63 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { parseKeyVaultSecretIdentifier } from "./identifier.js";
/**
* @internal
* Shapes the exposed {@link KeyVaultKey} based on either a received secret bundle or deleted secret bundle.
*/
export function getSecretFromSecretBundle(bundle) {
const secretBundle = bundle;
const deletedSecretBundle = bundle;
const parsedId = parseKeyVaultSecretIdentifier(secretBundle.id);
const attributes = secretBundle.attributes;
delete secretBundle.attributes;
const resultObject = {
value: secretBundle.value,
name: parsedId.name,
properties: {
expiresOn: attributes?.expires,
createdOn: attributes?.created,
updatedOn: attributes?.updated,
enabled: attributes?.enabled,
notBefore: attributes?.notBefore,
recoverableDays: attributes?.recoverableDays,
recoveryLevel: attributes?.recoveryLevel,
id: secretBundle.id,
contentType: secretBundle.contentType,
tags: secretBundle.tags,
managed: secretBundle.managed,
previousVersion: secretBundle.previousVersion,
vaultUrl: parsedId.vaultUrl,
version: parsedId.version,
name: parsedId.name,
certificateKeyId: secretBundle.kid,
},
};
if (deletedSecretBundle.recoveryId) {
resultObject.properties.recoveryId = deletedSecretBundle.recoveryId;
resultObject.properties.scheduledPurgeDate = deletedSecretBundle.scheduledPurgeDate;
resultObject.properties.deletedOn = deletedSecretBundle.deletedDate;
resultObject.recoveryId = deletedSecretBundle.recoveryId;
resultObject.scheduledPurgeDate = deletedSecretBundle.scheduledPurgeDate;
resultObject.deletedOn = deletedSecretBundle.deletedDate;
}
if (attributes) {
if (attributes.vaultUrl) {
delete resultObject.properties.vaultUrl;
}
if (attributes.expires) {
delete resultObject.properties.expires;
}
if (attributes.created) {
delete resultObject.properties.created;
}
if (attributes.updated) {
delete resultObject.properties.updated;
}
}
return resultObject;
}
/**
* A helper supporting compatibility between modular and legacy paged async iterables.
*
* Provides the following compatibility:
* 1. Maps the values of the paged async iterable using the provided mapper function.
* 2. Supports `maxPageSize` operation on the paged async iterable.
*
* TODO: move this to keyvault-common once everything is merged
*/
export function mapPagedAsyncIterable(operation, operationOptions, mapper) {
let iter = undefined;
return {
async next() {
iter ??= operation({ ...operationOptions, maxresults: undefined });
const result = await iter.next();
return {
...result,
value: result.value && mapper(result.value),
};
},
[Symbol.asyncIterator]() {
return this;
},
async *byPage(settings) {
// Pass the maxPageSize value to the underlying page operation
const iteratorByPage = operation({
...operationOptions,
maxresults: settings?.maxPageSize,
}).byPage(settings);
for await (const page of iteratorByPage) {
yield page.map(mapper);
}
},
};
}
//# sourceMappingURL=transformations.js.map