From 3c18caeecc9cd53ea385980653ca4c440b488af0 Mon Sep 17 00:00:00 2001 From: Trevor McMaster Date: Thu, 19 Dec 2024 14:44:50 -0700 Subject: [PATCH] Update node dependencies Scripting 2024-12-19 (#276) * PewRL fixes and updates (#274) * Endpoint modal initially open w/o useEffect, removed devkey option * Clear URL button added * Clear URL button, query params, request body * Replaced console.error with log() * Update node dependencies 2024-12-19 (#275) * Added back in the ec2-metadata-service call to getInstanceId * Updated version and dependencies - Updated lockfile to latest - Updated Mocha to v11 * Updated Next.js to 15.1 * Fixed timeout issue in unit tests by only calling metadata service in AWS --------- Co-authored-by: blonde-mike --- agent/package.json | 4 +- common/package.json | 5 +- common/src/util/ec2.ts | 24 + common/src/util/util.ts | 1 + controller/next-env.d.ts | 2 +- controller/package.json | 10 +- .../src/components/Modal/index.tsx | 6 +- .../components/YamlUrls/QueryParamsView.tsx | 68 + .../components/YamlUrls/RequestBodyView.tsx | 46 + .../YamlUrls/RequestDetailsTabs.tsx | 26 +- .../src/components/YamlUrls/index.tsx | 144 +- .../src/util/yamlwriter.ts | 11 +- package-lock.json | 3699 +++++++++-------- package.json | 4 +- 14 files changed, 2326 insertions(+), 1724 deletions(-) create mode 100644 guide/results-viewer-react/src/components/YamlUrls/QueryParamsView.tsx create mode 100644 guide/results-viewer-react/src/components/YamlUrls/RequestBodyView.tsx diff --git a/agent/package.json b/agent/package.json index efe4dc70..4ec7d7ce 100644 --- a/agent/package.json +++ b/agent/package.json @@ -1,6 +1,6 @@ { "name": "@fs/ppaas-agent", - "version": "3.3.4", + "version": "3.3.5", "description": "Agent Service for running pewpew tests", "main": "dist/src/app.js", "scripts": { @@ -58,7 +58,7 @@ "axios": "~1.7.0", "chai": "^4.3.7", "eslint": "^9.15.0", - "mocha": "^10.2.0", + "mocha": "^11.0.0", "nyc": "^17.0.0", "typescript": "^5.3.0" } diff --git a/common/package.json b/common/package.json index c00ecbf1..46b4ad3b 100644 --- a/common/package.json +++ b/common/package.json @@ -1,6 +1,6 @@ { "name": "@fs/ppaas-common", - "version": "3.3.4", + "version": "3.3.5", "description": "Common Code for the PewPewController and PewPewAgent", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", @@ -35,6 +35,7 @@ "dependencies": { "@aws-sdk/client-s3": "^3.363.0", "@aws-sdk/client-sqs": "^3.363.0", + "@aws-sdk/ec2-metadata-service": "^3.363.0", "@aws-sdk/lib-storage": "^3.363.0", "bunyan": "~1.8.0", "rimraf": "^5.0.0" @@ -55,7 +56,7 @@ "dotenv": "^16.0.0", "dotenv-flow": "^4.0.1", "eslint": "^9.15.0", - "mocha": "^10.2.0", + "mocha": "^11.0.0", "nyc": "^17.0.0", "typescript": "^5.3.0" } diff --git a/common/src/util/ec2.ts b/common/src/util/ec2.ts index 4fbff0bc..40abfa8d 100644 --- a/common/src/util/ec2.ts +++ b/common/src/util/ec2.ts @@ -1,4 +1,6 @@ import { LogLevel, log } from "./log"; +import { IS_RUNNING_IN_AWS } from "./util"; +import { MetadataService } from "@aws-sdk/ec2-metadata-service"; import { exec as _exec } from "child_process"; import { promisify } from "util"; import { readFile } from "fs/promises"; @@ -8,7 +10,29 @@ export const INSTANCE_ID_FILE = "/var/lib/cloud/data/instance-id"; export const INSTANCE_ID_REGEX = /^i-[0-9a-z]+$/; export const INSTANCE_FILE_REGEX = /^instance-id:\s*(i-[0-9a-z]+)$/; export const INSTANCE_ID_COMMAND = "ec2-metadata --instance-id"; + +// Putting back code removed by https://github.com/fs-eng/ppaas-common/commit/397d38e31ebafa9551dec8d9a2082140e8d949ae#diff-b0083bb9a17262c7a014463e8dee3fd0489cad8cb220d19531f295b9592826a0L14 +// AWS SDK V3 finally supports the MetadataService +const metadata: MetadataService = new MetadataService({ + // host: "169.254.169.254" +}); + export async function getInstanceId (): Promise { + // Our current mocks do not support the metadata service. bypass when not in AWS so we don't timeout on integration and unit tests + if (IS_RUNNING_IN_AWS) { + try { + // curl http://169.254.169.254/latest/meta-data/instance-id -> "i-0cfd3309705a3ce79" + const instanceId: string = await metadata.request("/latest/meta-data/instance-id", {}); + log("getInstanceId MetadataService /latest/meta-data/instance-id: " + instanceId, LogLevel.WARN, instanceId); + if (!INSTANCE_ID_REGEX.test(instanceId)) { + log(`InstanceId did not match regex [${instanceId}]`, LogLevel.WARN, { match: instanceId?.match(INSTANCE_ID_REGEX), INSTANCE_ID_REGEX }); + throw new Error("InstanceId did not match regex"); + } + return instanceId; + } catch (error: unknown) { + log("Could not load instanceId metadata", LogLevel.WARN, error); + } + } // Try to load from file first // $ cat /var/lib/cloud/data/instance-id -> "i-0cfd3309705a3ce79" try { diff --git a/common/src/util/util.ts b/common/src/util/util.ts index dd3d634e..3d0a07a7 100644 --- a/common/src/util/util.ts +++ b/common/src/util/util.ts @@ -7,6 +7,7 @@ export const CONTROLLER_APPLICATION_PREFIX: string = CONTROLLER_APPLICATION_NAME export const SYSTEM_NAME: string = process.env.SYSTEM_NAME || "unittests"; export const CONTROLLER_ENV = process.env.CONTROLLER_ENV; export const AGENT_ENV = process.env.AGENT_ENV; +export const IS_RUNNING_IN_AWS: boolean = process.env.APPLICATION_NAME !== undefined && process.env.SYSTEM_NAME !== undefined; export const PEWPEW_BINARY_FOLDER: string = "pewpew"; export const PEWPEW_VERSION_LATEST: string = "latest"; diff --git a/controller/next-env.d.ts b/controller/next-env.d.ts index a4a7b3f5..52e831b4 100644 --- a/controller/next-env.d.ts +++ b/controller/next-env.d.ts @@ -2,4 +2,4 @@ /// // NOTE: This file should not be edited -// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information. +// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information. diff --git a/controller/package.json b/controller/package.json index 77d6b5b6..3b588ffa 100644 --- a/controller/package.json +++ b/controller/package.json @@ -1,6 +1,6 @@ { "name": "@fs/ppaas-controller", - "version": "3.3.4", + "version": "3.3.5", "description": "Controller Service for running pewpew tests", "private": true, "scripts": { @@ -63,7 +63,7 @@ "formidable": "~3.5.0", "js-cookie": "^3.0.5", "js-yaml": "^4.1.0", - "next": "~15.0.3", + "next": "~15.1.0", "next-cookies": "^2.0.3", "openid-client": "~5.7.0", "rc-progress": "^4.0.0", @@ -84,7 +84,7 @@ "@aws-sdk/util-stream-node": "^3.363.0", "@eslint/eslintrc": "^3.1.0", "@eslint/js": "^9.8.0", - "@next/eslint-plugin-next": "~15.0.3", + "@next/eslint-plugin-next": "~15.1.0", "@storybook/addon-actions": "~8.4.0", "@storybook/addon-links": "~8.4.0", "@storybook/nextjs": "~8.4.0", @@ -115,13 +115,13 @@ "dotenv-flow": "^4.0.1", "esbuild": ">=0.17", "eslint": "^9.15.0", - "eslint-config-next": "~15.0.3", + "eslint-config-next": "~15.1.0", "form-data": "^4.0.0", "glob-parent": "^6.0.2", "immer": "^10.0.2", "jsdom": ">=23.0.0", "jsdom-global": "^3.0.2", - "mocha": "^10.2.0", + "mocha": "^11.0.0", "nyc": "^17.0.0", "postcss": "^8.4.24", "set-value": "^4.1.0", diff --git a/guide/results-viewer-react/src/components/Modal/index.tsx b/guide/results-viewer-react/src/components/Modal/index.tsx index d20d0d2c..71bc1ec2 100644 --- a/guide/results-viewer-react/src/components/Modal/index.tsx +++ b/guide/results-viewer-react/src/components/Modal/index.tsx @@ -93,6 +93,7 @@ interface ModalProps { children?: React.ReactNode; isReady?: boolean; scrollable?: boolean; + initialDisplay?: boolean; } export interface ModalObject { @@ -136,9 +137,10 @@ export const Modal = forwardRef(({ submitText = "submit", children, isReady, - scrollable + scrollable, + initialDisplay = false }: ModalProps, ref: Ref) => { - const [display, setDisplay] = useState(false); + const [display, setDisplay] = useState(initialDisplay); let windowOffset: number = 0; useImperativeHandle(ref, () => { diff --git a/guide/results-viewer-react/src/components/YamlUrls/QueryParamsView.tsx b/guide/results-viewer-react/src/components/YamlUrls/QueryParamsView.tsx new file mode 100644 index 00000000..2932b0b0 --- /dev/null +++ b/guide/results-viewer-react/src/components/YamlUrls/QueryParamsView.tsx @@ -0,0 +1,68 @@ +import { PewPewHeader, PewPewQueryParam } from "../../util/yamlwriter"; +import { PewPewQueryParamStringType } from "."; +import React from "react"; + +export interface QueryParamsViewProps { + id: string; + queryParamList: PewPewQueryParam[]; + removeParam: (param: PewPewQueryParam) => void; + changeParam: (paramIndex: number, type: PewPewQueryParamStringType, value: string) => void; + addParam: () => void; +} + +function QueryParamsView ({ id, queryParamList, removeParam, changeParam, addParam }: QueryParamsViewProps): JSX.Element { + const styles: Record = { + headersDisplay: { + marginTop: "10px", + maxHeight: "300px", + overflow: "auto" + }, + gridContainer: { + display: "grid", + gap: "10px" + }, + gridHeader: { + display: "grid", + gridTemplateColumns: "auto 1fr 2fr", + gap: "10px", + fontWeight: "bold", + height: "20px" + }, + gridRows: { + display: "grid", + gridTemplateColumns: "auto 1fr 2fr", + gap: "10px", + alignItems: "stretch" + }, + input: { + boxSizing: "border-box" + }, + button: { + boxSizing: "border-box", + whiteSpace: "nowrap" + } + }; + return ( + +
+
+
+ + Name + Value +
+ {queryParamList.length === 0 && No Query Params yet, click "+" to create one} + {queryParamList.map((param: PewPewHeader, index: number) => ( +
+ + changeParam(index, "name", event.target.value)} /> + changeParam(index, "value", event.target.value)} /> +
+ ))} +
+
+
+ ); +} + +export default QueryParamsView; \ No newline at end of file diff --git a/guide/results-viewer-react/src/components/YamlUrls/RequestBodyView.tsx b/guide/results-viewer-react/src/components/YamlUrls/RequestBodyView.tsx new file mode 100644 index 00000000..7ef86b34 --- /dev/null +++ b/guide/results-viewer-react/src/components/YamlUrls/RequestBodyView.tsx @@ -0,0 +1,46 @@ +import { LogLevel, log } from "../../util/log"; +import React from "react"; + +export interface RequestBodyViewProps { + requestBody: object | undefined; + updateRequestBody: (newRequestBody: object) => void; +} + +function RequestBodyView ({ requestBody, updateRequestBody }: RequestBodyViewProps): JSX.Element { + const [requestBodyInEdit, setRequestBodyInEdit] = React.useState(JSON.stringify(requestBody, null, 2).replace(/\\n/g, "\n").replace(/^"|"$/g, "")); + + const requestBodyDisplayStyle: React.CSSProperties = { + fontFamily: "monospace", + width: "100%", + height: "270px", + overflow: "auto", + border: "1px solid #ccc", + padding: "10px", + backgroundColor: "#2e3438", + resize: "none", + tabSize: 2, + boxSizing: "border-box" + }; + + const handleEditorInput = (event: React.ChangeEvent) => { + const newRequestBody = event.target.value; + setRequestBodyInEdit(newRequestBody); + try { + updateRequestBody(JSON.parse(newRequestBody)); + } catch (error) { + log("Invalid JSON", LogLevel.WARN, error); + } + }; + + return ( + +