UNPKG

@azure/app-configuration

Version:
77 lines (76 loc) 3.1 kB
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 secretReference_exports = {}; __export(secretReference_exports, { SecretReferenceHelper: () => SecretReferenceHelper, isSecretReference: () => isSecretReference, parseSecretReference: () => parseSecretReference, secretReferenceContentType: () => secretReferenceContentType }); module.exports = __toCommonJS(secretReference_exports); var import_logger = require("./logger.js"); const secretReferenceContentType = "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8"; const SecretReferenceHelper = { /** * Takes the SecretReference (JSON) and returns a ConfigurationSetting (with the props encoded in the value). */ toConfigurationSettingParam: (secretReference) => { import_logger.logger.info("Encoding SecretReference value in a ConfigurationSetting:", secretReference); if (!secretReference.value) { import_logger.logger.error(`SecretReference has an unexpected value`, secretReference); throw new TypeError(`SecretReference has an unexpected value - ${secretReference.value}`); } const jsonSecretReferenceValue = { uri: secretReference.value.secretId }; const configSetting = { ...secretReference, value: JSON.stringify(jsonSecretReferenceValue) }; return configSetting; } }; function parseSecretReference(setting) { import_logger.logger.info( "[parseSecretReference] Parsing the value to return the SecretReferenceValue", setting ); if (!isSecretReference(setting)) { import_logger.logger.error("Invalid SecretReference input", setting); throw TypeError( `Setting with key ${setting.key} is not a valid SecretReference, make sure to have the correct content-type and a valid non-null value.` ); } const jsonSecretReferenceValue = JSON.parse(setting.value); const secretReference = { ...setting, value: { secretId: jsonSecretReferenceValue.uri } }; return secretReference; } function isSecretReference(setting) { return setting && setting.contentType === secretReferenceContentType && typeof setting.value === "string"; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { SecretReferenceHelper, isSecretReference, parseSecretReference, secretReferenceContentType }); //# sourceMappingURL=secretReference.js.map