Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@ The server now reads its startup configuration itself, where earlier versions ra
- With `HOST` set, the container reuses the certificate files in `cert-info` when all of them exist, `server.crt` names `HOST`, and it hasn't expired, and generates a certificate otherwise. A restart, or a new container that mounts the same `cert-info` volume, keeps its certificate, so you no longer have to drop `HOST` after the first run. A new container without the volume generates its own, as [HTTPS Connections](../../references/security/#https-connections) describes. Earlier versions generated a certificate for every new container when the configuration folder held no lines from an earlier start.
- A run from source (`pnpm dev`, `pnpm start`) now reads a `config.json` at the repository root, the same way the image does, so it applies the Default Connection settings and the Neptune Notebook preset from that file, and it ignores the lines earlier versions appended to `.env`. When that `config.json` sets `PROXY_SERVER_HTTPS_CONNECTION` to `true`, the server stops with `PROXY_SERVER_HTTPS_CONNECTION is true but certificate files are missing`, because only the image generates certificates. Set it to `false`, or remove it, for runs from source.
- A key set more than once in `config.json`, `.env`, or `.env.local` now stops startup with an error that names the file, the key, and its lines, so keep one line for each key and remove the others. In `.env` and `.env.local`, earlier versions used the last line, so keep that one to start as before. The lines earlier versions appended to `.env` don't count.
- An `IAM` value other than `true` or `false` in any letter case now uses `false` with a warning, and `True` or `TRUE` now reads as `true`. Earlier versions wrote the value as it was, which could make a default connection the browser couldn't read.
2 changes: 2 additions & 0 deletions packages/docs/src/content/docs/references/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ These are the valid environment variables used for the default connection, their
- `AWS_REGION` - `None`
- `SERVICE_TYPE` - `neptune-db`, Set this as `neptune-db` for Neptune database or `neptune-graph` for Neptune Analytics.

`IAM` is `true` or `false` in any letter case. For any other value, the server logs a warning and the default connection uses `false`.

### JSON Configuration Approach

First, create a `config.json` file containing values for the connection attributes:
Expand Down
20 changes: 11 additions & 9 deletions packages/graph-explorer-proxy-server/src/app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function createTestApp(
) {
const app = createApp({
configPath,
defaultConnectionJson: undefined,
defaultConnection: undefined,
staticFilesVirtualPath: "/explorer",
staticFilesPath: ".",
version: testVersion,
Expand Down Expand Up @@ -273,13 +273,15 @@ describe("createApp", () => {
});

describe("GET /defaultConnection", () => {
const defaultConnectionJson =
'\n{\n"GRAPH_EXP_CONNECTION_URL":"https://db:8182",\n"GRAPH_EXP_USING_PROXY_SERVER":false\n}\n';
const defaultConnection = {
GRAPH_EXP_CONNECTION_URL: "https://db:8182",
GRAPH_EXP_USING_PROXY_SERVER: true,
};

it("serves the in-memory Default Connection as JSON", async () => {
const app = createApp({
configPath: ".",
defaultConnectionJson,
defaultConnection,
staticFilesVirtualPath: "/explorer",
staticFilesPath: ".",
});
Expand All @@ -289,7 +291,7 @@ describe("createApp", () => {

expect(response.status).toBe(200);
expect(response.type).toBe("application/json");
expect(response.text).toBe(defaultConnectionJson);
expect(response.body).toStrictEqual(defaultConnection);
});

it("prefers the in-memory Default Connection over defaultConnection.json", async () => {
Expand All @@ -301,15 +303,15 @@ describe("createApp", () => {
);
const app = createApp({
configPath: tmpDir,
defaultConnectionJson,
defaultConnection,
staticFilesVirtualPath: "/explorer",
staticFilesPath: ".",
});
app.locals.logger = createLogger(createTestEnvironment());

const response = await request(app).get("/defaultConnection");

expect(response.text).toBe(defaultConnectionJson);
expect(response.body).toStrictEqual(defaultConnection);
} finally {
fs.rmSync(tmpDir, { recursive: true, force: true });
}
Expand Down Expand Up @@ -371,7 +373,7 @@ describe("createApp", () => {
function createStaticTestApp(staticFilesVirtualPath = "/explorer") {
const app = createApp({
configPath: ".",
defaultConnectionJson: undefined,
defaultConnection: undefined,
staticFilesVirtualPath,
staticFilesPath: tmpDir,
version: testVersion,
Expand Down Expand Up @@ -1497,7 +1499,7 @@ describe("createApp", () => {

const app = createApp({
configPath: ".",
defaultConnectionJson: undefined,
defaultConnection: undefined,
staticFilesVirtualPath: "/explorer",
staticFilesPath: ".",
});
Expand Down
12 changes: 7 additions & 5 deletions packages/graph-explorer-proxy-server/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import path from "path";
import { pipeline } from "stream";
import { z } from "zod";

import type { DefaultConnection } from "./default-connection.ts";

import {
blockedResolutionError,
dbAgentFor,
Expand Down Expand Up @@ -165,8 +167,8 @@ function onClientDisconnect(res: Response, onDisconnect: () => void) {

interface CreateAppOptions {
configPath: string;
/** Served at `/defaultConnection`. Without it, the configuration folder's `defaultConnection.json` is. */
defaultConnectionJson: string | undefined;
/** Served at `/defaultConnection`. Without one, the configuration folder's `defaultConnection.json` is. */
defaultConnection: DefaultConnection | undefined;
staticFilesVirtualPath: string;
staticFilesPath: string;
version?: string;
Expand All @@ -176,7 +178,7 @@ interface CreateAppOptions {

export function createApp({
configPath,
defaultConnectionJson,
defaultConnection,
staticFilesVirtualPath,
staticFilesPath,
version,
Expand All @@ -203,11 +205,11 @@ export function createApp({
),
);
app.get("/defaultConnection", (_req, res, next) => {
if (defaultConnectionJson === undefined) {
if (defaultConnection === undefined) {
next();
return;
}
res.type("json").send(defaultConnectionJson);
res.json(defaultConnection);
});
app.use(
"/defaultConnection",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import path from "path";
import request from "supertest";
import { afterEach, beforeEach, describe, it, vi } from "vite-plus/test";

import type { DefaultConnection } from "./default-connection.ts";
import type { EnvironmentValues } from "./env.ts";

import { createApp } from "./app.ts";
Expand Down Expand Up @@ -56,11 +57,11 @@ function readFolder(folder: string) {

async function requestDefaultConnection(
configDir: string,
defaultConnectionJson: string | undefined,
defaultConnection: DefaultConnection | undefined,
): Promise<DefaultConnectionResponse> {
const app = createApp({
configPath: configDir,
defaultConnectionJson,
defaultConnection,
staticFilesVirtualPath: "/explorer",
staticFilesPath: ".",
version: "test",
Expand Down Expand Up @@ -278,7 +279,7 @@ describe("deployment scenarios: TypeScript startup", () => {
certificatesGenerated: certificates === "generated",
defaultConnection: await requestDefaultConnection(
configDir,
startup.defaultConnectionJson,
startup.defaultConnection,
),
},
};
Expand Down
145 changes: 88 additions & 57 deletions packages/graph-explorer-proxy-server/src/default-connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { describe, expect, it } from "vite-plus/test";

import type { ConfigJson } from "./config-json.ts";

import { renderDefaultConnection } from "./default-connection.ts";
import {
type DefaultConnection,
resolveDefaultConnection,
} from "./default-connection.ts";

type Row = {
name: string;
settings: ConfigJson["values"];
/** The Default Connection the text parses to, or `undefined` when no connection is configured. */
expected: Record<string, unknown> | undefined;
/** The Default Connection, or `undefined` when no connection is configured. */
expected: DefaultConnection | undefined;
/** The warnings the resolver gives. */
warnings?: string[];
};

const db = "https://db:8182";
Expand Down Expand Up @@ -318,82 +323,108 @@ const rowGroups: Record<string, Row[]> = {
],

// #2291: the shell never wrote these two settings.
// Earlier versions wrote the IAM value as it was given, so anything but a
// lowercase true or false made the file invalid JSON.
"IAM values": [
{
name: "reads IAM=True as true",
settings: { GRAPH_CONNECTION_URL: db, IAM: "True" },
expected: {
GRAPH_EXP_CONNECTION_URL: db,
GRAPH_EXP_SERVICE_TYPE: "neptune-db",
GRAPH_EXP_IAM: true,
GRAPH_EXP_AWS_REGION: "",
GRAPH_EXP_USING_PROXY_SERVER: true,
},
},
{
name: "uses false for IAM=yes with a warning",
settings: { GRAPH_CONNECTION_URL: db, IAM: "yes" },
expected: {
GRAPH_EXP_CONNECTION_URL: db,
GRAPH_EXP_SERVICE_TYPE: "neptune-db",
GRAPH_EXP_IAM: false,
GRAPH_EXP_AWS_REGION: "",
GRAPH_EXP_USING_PROXY_SERVER: true,
},
warnings: [
`IAM is "yes", which isn't true or false, so the Default Connection uses false.`,
],
},
{
// A config.json null reaches here as the text "null".
name: "uses false for IAM=null with a warning",
settings: { GRAPH_CONNECTION_URL: db, IAM: "null" },
expected: {
GRAPH_EXP_CONNECTION_URL: db,
GRAPH_EXP_SERVICE_TYPE: "neptune-db",
GRAPH_EXP_IAM: false,
GRAPH_EXP_AWS_REGION: "",
GRAPH_EXP_USING_PROXY_SERVER: true,
},
warnings: [
`IAM is "null", which isn't true or false, so the Default Connection uses false.`,
],
},
{
name: "ignores IAM on a direct connection without a warning",
settings: {
USING_PROXY_SERVER: "false",
PUBLIC_OR_PROXY_ENDPOINT: "https://public:9250",
IAM: "yes",
},
expected: {
GRAPH_EXP_CONNECTION_URL: "https://public:9250",
GRAPH_EXP_USING_PROXY_SERVER: false,
},
},
],
};

/** The rendered Default Connection, parsed. */
function renderParsed(settings: ConfigJson["values"]): unknown {
const text = renderDefaultConnection(settings);
return text === undefined ? undefined : JSON.parse(text);
}

describe("renderDefaultConnection", () => {
describe("resolveDefaultConnection", () => {
describe.for(Object.entries(rowGroups))("%s", ([_group, groupRows]) => {
it.for(groupRows.map(row => [row.name, row] as const))(
"%s",
([_name, { settings, expected }]) => {
expect(renderParsed(settings)).toStrictEqual(expected);
([_name, { settings, expected, warnings = [] }]) => {
expect(resolveDefaultConnection(settings)).toStrictEqual({
defaultConnection: expected,
warnings,
});
},
);
});

it("renders the text process-environment.sh wrote, line by line", () => {
expect(
renderDefaultConnection({
GRAPH_CONNECTION_URL: db,
GRAPH_TYPE: "gremlin",
IAM: "true",
AWS_REGION: "us-east-1",
}),
).toBe(
[
"",
"{",
'"GRAPH_EXP_CONNECTION_URL":"https://db:8182",',
'"GRAPH_EXP_GRAPH_TYPE":"gremlin",',
'"GRAPH_EXP_SERVICE_TYPE":"neptune-db",',
'"GRAPH_EXP_IAM":true,',
'"GRAPH_EXP_AWS_REGION":"us-east-1",',
'"GRAPH_EXP_USING_PROXY_SERVER":true',
"}",
"",
].join("\n"),
);
});

// Earlier versions wrote the IAM value as it was given, so a value that
// isn't a JSON literal made a file the browser couldn't read.
it("writes an IAM of True as it is", () => {
expect(
renderDefaultConnection({ GRAPH_CONNECTION_URL: db, IAM: "True" }),
).toContain('"GRAPH_EXP_IAM":True,\n');
});

// Earlier versions wrote the legacy names to defaultConnection.json for no
// reason. The browser reads only the GRAPH_EXP_ names.
it("never includes the legacy variable names", () => {
expect(
renderParsed({
USING_PROXY_SERVER: "true",
GRAPH_CONNECTION_URL: "https://proxied:8182",
PUBLIC_OR_PROXY_ENDPOINT: "https://public:9250",
}),
).not.toHaveProperty("GRAPH_EXP_PUBLIC_OR_PROXY_ENDPOINT");
const { defaultConnection } = resolveDefaultConnection({
USING_PROXY_SERVER: "true",
GRAPH_CONNECTION_URL: "https://proxied:8182",
PUBLIC_OR_PROXY_ENDPOINT: "https://public:9250",
});

expect(defaultConnection).not.toHaveProperty(
"GRAPH_EXP_PUBLIC_OR_PROXY_ENDPOINT",
);
});

it("treats an empty setting as unset", () => {
expect(
renderParsed({
resolveDefaultConnection({
GRAPH_CONNECTION_URL: db,
GRAPH_TYPE: "",
SERVICE_TYPE: "",
IAM: "",
}),
).toStrictEqual({
GRAPH_EXP_CONNECTION_URL: db,
GRAPH_EXP_SERVICE_TYPE: "neptune-db",
GRAPH_EXP_IAM: false,
GRAPH_EXP_AWS_REGION: "",
GRAPH_EXP_USING_PROXY_SERVER: true,
defaultConnection: {
GRAPH_EXP_CONNECTION_URL: db,
GRAPH_EXP_SERVICE_TYPE: "neptune-db",
GRAPH_EXP_IAM: false,
GRAPH_EXP_AWS_REGION: "",
GRAPH_EXP_USING_PROXY_SERVER: true,
},
warnings: [],
});
});
});
Loading
Loading