UNPKG

serverless-spy

Version:

CDK-based library for writing elegant integration tests on AWS serverless architecture and an additional web console to monitor events in real time.

102 lines (98 loc) 3.39 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); 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); // src/index.ts var src_exports = {}; __export(src_exports, { getSsecPlugin: () => getSsecPlugin, isValidBase64EncodedSSECustomerKey: () => isValidBase64EncodedSSECustomerKey, ssecMiddleware: () => ssecMiddleware, ssecMiddlewareOptions: () => ssecMiddlewareOptions }); module.exports = __toCommonJS(src_exports); function ssecMiddleware(options) { return (next) => async (args) => { const input = { ...args.input }; const properties = [ { target: "SSECustomerKey", hash: "SSECustomerKeyMD5" }, { target: "CopySourceSSECustomerKey", hash: "CopySourceSSECustomerKeyMD5" } ]; for (const prop of properties) { const value = input[prop.target]; if (value) { let valueForHash; if (typeof value === "string") { if (isValidBase64EncodedSSECustomerKey(value, options)) { valueForHash = options.base64Decoder(value); } else { valueForHash = options.utf8Decoder(value); input[prop.target] = options.base64Encoder(valueForHash); } } else { valueForHash = ArrayBuffer.isView(value) ? new Uint8Array(value.buffer, value.byteOffset, value.byteLength) : new Uint8Array(value); input[prop.target] = options.base64Encoder(valueForHash); } const hash = new options.md5(); hash.update(valueForHash); input[prop.hash] = options.base64Encoder(await hash.digest()); } } return next({ ...args, input }); }; } __name(ssecMiddleware, "ssecMiddleware"); var ssecMiddlewareOptions = { name: "ssecMiddleware", step: "initialize", tags: ["SSE"], override: true }; var getSsecPlugin = /* @__PURE__ */ __name((config) => ({ applyToStack: (clientStack) => { clientStack.add(ssecMiddleware(config), ssecMiddlewareOptions); } }), "getSsecPlugin"); function isValidBase64EncodedSSECustomerKey(str, options) { const base64Regex = /^(?:[A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/; if (!base64Regex.test(str)) return false; try { const decodedBytes = options.base64Decoder(str); return decodedBytes.length === 32; } catch { return false; } } __name(isValidBase64EncodedSSECustomerKey, "isValidBase64EncodedSSECustomerKey"); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ssecMiddleware, ssecMiddlewareOptions, getSsecPlugin, isValidBase64EncodedSSECustomerKey });