@azure/app-configuration
Version:
An isomorphic client library for the Azure App Configuration service.
57 lines (56 loc) • 2.56 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 appConfigCredential_exports = {};
__export(appConfigCredential_exports, {
appConfigKeyCredentialPolicy: () => appConfigKeyCredentialPolicy
});
module.exports = __toCommonJS(appConfigCredential_exports);
var import_core_util = require("@azure/core-util");
var import_logger = require("./logger.js");
function appConfigKeyCredentialPolicy(credential, secret) {
return {
name: "AppConfigKeyCredentialPolicy",
async sendRequest(request, next) {
const verb = request.method;
const utcNow = (/* @__PURE__ */ new Date()).toUTCString();
import_logger.logger.info("[appConfigKeyCredentialPolicy] Computing SHA-256 from the request body");
const contentHash = await (0, import_core_util.computeSha256Hash)(request.body?.toString() || "", "base64");
const signedHeaders = "x-ms-date;host;x-ms-content-sha256";
const url = new URL(request.url);
const query = url.search;
const urlPathAndQuery = query ? `${url.pathname}${query}` : url.pathname;
const stringToSign = `${verb}
${urlPathAndQuery}
${utcNow};${url.host};${contentHash}`;
import_logger.logger.info("[appConfigKeyCredentialPolicy] Computing a SHA-256 Hmac signature");
const signature = await (0, import_core_util.computeSha256Hmac)(secret, stringToSign, "base64");
request.headers.set("x-ms-date", utcNow);
request.headers.set("x-ms-content-sha256", contentHash);
request.headers.set(
"Authorization",
`HMAC-SHA256 Credential=${credential}&SignedHeaders=${signedHeaders}&Signature=${signature}`
);
return next(request);
}
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
appConfigKeyCredentialPolicy
});
//# sourceMappingURL=appConfigCredential.js.map