@azure/keyvault-certificates
Version:
Azure Key Vault Certificates
164 lines (163 loc) • 6.35 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var operation_exports = {};
__export(operation_exports, {
CreateCertificatePollOperation: () => CreateCertificatePollOperation
});
module.exports = __toCommonJS(operation_exports);
var import_keyVaultCertificatePoller = require("../keyVaultCertificatePoller.js");
var import_transformations = require("../../transformations.js");
var import_tracing = require("../../tracing.js");
class CreateCertificatePollOperation extends import_keyVaultCertificatePoller.KeyVaultCertificatePollOperation {
constructor(state, client, operationOptions = {}) {
super(state);
this.state = state;
this.client = client;
this.operationOptions = operationOptions;
}
state;
client;
operationOptions;
/**
* Creates a new certificate. If this is the first version, the certificate resource is created. This operation requires the certificates/create permission.
*/
createCertificate(certificateName, certificatePolicy, options = {}) {
return import_tracing.tracingClient.withSpan(
"CreateCertificatePoller.createCertificate",
options,
async (updatedOptions) => {
const id = options.id;
const certificateAttributes = (0, import_transformations.toCoreAttributes)(options);
const corePolicy = (0, import_transformations.toCorePolicy)(id, certificatePolicy, certificateAttributes);
const result = await this.client.createCertificate(
certificateName,
{
certificatePolicy: corePolicy,
certificateAttributes,
tags: updatedOptions.tags,
preserveCertOrder: updatedOptions.preserveCertificateOrder
},
updatedOptions
);
return (0, import_transformations.getCertificateWithPolicyFromCertificateBundle)(result);
}
);
}
/**
* Gets the latest information available from a specific certificate, including the certificate's policy. This operation requires the certificates/get permission.
*/
getCertificate(certificateName, options = {}) {
return import_tracing.tracingClient.withSpan(
"CreateCertificatePoller.getCertificate",
options,
async (updatedOptions) => {
const result = await this.client.getCertificate(certificateName, "", updatedOptions);
return (0, import_transformations.getCertificateWithPolicyFromCertificateBundle)(result);
}
);
}
/**
* Gets the certificate operation.
*/
getPlainCertificateOperation(certificateName, options = {}) {
return import_tracing.tracingClient.withSpan(
"CreateCertificatePoller.getPlainCertificateOperation",
options,
async (updatedOptions) => {
const response = await this.client.getCertificateOperation(certificateName, {
...updatedOptions
});
return (0, import_transformations.getCertificateOperationFromCoreOperation)(certificateName, response);
}
);
}
/**
* Cancels a certificate creation operation that is already in progress. This operation requires the certificates/update permission.
*/
cancelCertificateOperation(certificateName, options = {}) {
return import_tracing.tracingClient.withSpan(
"CreateCertificatePoller.cancelCertificateOperation",
options,
async (updatedOptions) => {
const response = await this.client.updateCertificateOperation(
certificateName,
{ cancellationRequested: true },
updatedOptions
);
return (0, import_transformations.getCertificateOperationFromCoreOperation)(certificateName, response);
}
);
}
/**
* Reaches to the service and updates the create certificate's poll operation.
*/
async update(options = {}) {
const state = this.state;
const { certificateName, certificatePolicy, createCertificateOptions } = state;
if (options.abortSignal) {
this.operationOptions.abortSignal = options.abortSignal;
createCertificateOptions.abortSignal = options.abortSignal;
}
if (!state.isStarted) {
state.isStarted = true;
state.result = await this.createCertificate(
certificateName,
certificatePolicy,
createCertificateOptions
);
this.state.certificateOperation = await this.getPlainCertificateOperation(
certificateName,
this.operationOptions
);
} else if (!state.isCompleted) {
this.state.certificateOperation = await this.getPlainCertificateOperation(
certificateName,
this.operationOptions
);
}
if (state.certificateOperation && state.certificateOperation.status !== "inProgress") {
state.isCompleted = true;
state.result = await this.getCertificate(certificateName, this.operationOptions);
if (state.certificateOperation.error) {
state.error = new Error(state.certificateOperation.error.message);
}
}
return this;
}
/**
* Reaches to the service and cancels the certificate's operation, also updating the certificate's poll operation
*/
async cancel(options = {}) {
const state = this.state;
const { certificateName } = state;
if (options.abortSignal) {
this.operationOptions.abortSignal = options.abortSignal;
}
state.certificateOperation = await this.cancelCertificateOperation(
certificateName,
this.operationOptions
);
this.state.isCancelled = true;
return this;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CreateCertificatePollOperation
});
//# sourceMappingURL=operation.js.map