From 811721a9b0ad547a0c4a1f046284ee440d987bff Mon Sep 17 00:00:00 2001 From: Juan Cubeddu Date: Thu, 16 Nov 2023 11:15:20 -0600 Subject: [PATCH 1/2] Fix service type casing in environment variables and headers --- README.md | 6 +++--- packages/graph-explorer-proxy-server/node-server.js | 12 +++++++++--- .../src/connector/AbstractConnector.ts | 3 +++ .../modules/ConnectionDetail/ConnectionDetail.tsx | 1 + .../modules/CreateConnection/CreateConnection.tsx | 4 ++-- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9ec1e79db..f0aa51e08 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ To provide a default connection such that initial loads of the graph explorer al - `GRAPH_CONNECTION_URL` - `None` - See [Add a New Connection](#connections-ui) - Required if `USING_PROXY_SERVER=True` and `IAM=True` - `AWS_REGION` - `None` - See [Add a New Connection](#connections-ui) - - `SERVICE_TYPE` - `Neptune-db` + - `SERVICE_TYPE` - `neptune-db` #### JSON Configuration Approach @@ -135,7 +135,7 @@ First, create a `config.json` file containing values for the connection attribut "GRAPH_CONNECTION_URL": "https://cluster-cqmizgqgrsbf.us-west-2.neptune.amazonaws.com:8182", "USING_PROXY_SERVER": true, (Can be string or boolean) "IAM": true, (Can be string or boolean) - "SERVICE_TYPE": "Neptune-db", + "SERVICE_TYPE": "neptune-db", "AWS_REGION": "us-west-2", "GRAPH_TYPE": "gremlin" (Possible Values: "gremlin", "sparql", "opencypher"), "GRAPH_EXP_HTTPS_CONNECTION": true (Can be string or boolean), @@ -163,7 +163,7 @@ docker run -p 80:80 -p 443:443 \ --env IAM=false \ --env GRAPH_CONNECTION_URL=https://cluster-cqmizgqgrsbf.us-west-2.neptune.amazonaws.com:8182 \ --env AWS_REGION=us-west-2 \ - --env SERVICE_TYPE=Neptune-db \ + --env SERVICE_TYPE=neptune-db \ --env PROXY_SERVER_HTTPS_CONNECTION=true \ --env GRAPH_EXP_FETCH_REQUEST_TIMEOUT=9000 \ graph-explorer diff --git a/packages/graph-explorer-proxy-server/node-server.js b/packages/graph-explorer-proxy-server/node-server.js index 4f22e82bc..f34b1e4a3 100644 --- a/packages/graph-explorer-proxy-server/node-server.js +++ b/packages/graph-explorer-proxy-server/node-server.js @@ -10,7 +10,6 @@ const path = require("path"); const pino = require("pino"); const { fromNodeProviderChain } = require("@aws-sdk/credential-providers"); const aws4 = require("aws4"); -const serviceType = process.env.SERVICE_TYPE || "neptune-db"; dotenv.config({ path: "../graph-explorer/.env" }); @@ -62,6 +61,10 @@ const errorHandler = (error, request, response, next) => { (async () => { app.use(cors()); + app.use((req, res, next) => { + console.log("Headers: ", req.headers); + next(); + }); app.use( "/defaultConnection", express.static( @@ -88,13 +91,16 @@ const errorHandler = (error, request, response, next) => { ) => { // remove the existing host headers, we want ensure that we are passing the DB endpoint hostname. delete headers["host"]; - if (headers["aws-neptune-region"]) { + const serviceType = headers["service-type"]; + const AWSRegion = headers["aws-neptune-region"]; + + if (AWSRegion && serviceType) { data = await getIAMHeaders({ host: url.hostname, port: url.port, path: url.pathname + url.search, service: serviceType, - region: headers["aws-neptune-region"], + region: AWSRegion, }); headers = { ...headers, ...data }; } diff --git a/packages/graph-explorer/src/connector/AbstractConnector.ts b/packages/graph-explorer/src/connector/AbstractConnector.ts index b0e0ba01e..528684b55 100644 --- a/packages/graph-explorer/src/connector/AbstractConnector.ts +++ b/packages/graph-explorer/src/connector/AbstractConnector.ts @@ -307,6 +307,9 @@ export abstract class AbstractConnector { if (this._connection?.awsAuthEnabled) { headers["aws-neptune-region"] = this._connection?.awsRegion || ""; } + if (this._connection?.serviceType) { + headers["service-type"] = this._connection?.serviceType || ""; + } return headers; } diff --git a/packages/graph-explorer/src/modules/ConnectionDetail/ConnectionDetail.tsx b/packages/graph-explorer/src/modules/ConnectionDetail/ConnectionDetail.tsx index 7f602fe55..bd0b7ad82 100644 --- a/packages/graph-explorer/src/modules/ConnectionDetail/ConnectionDetail.tsx +++ b/packages/graph-explorer/src/modules/ConnectionDetail/ConnectionDetail.tsx @@ -217,6 +217,7 @@ const ConnectionDetail = ({ isSync, onSyncChange }: ConnectionDetailProps) => { url: config.connection?.url, type: config.connection?.queryEngine, fetchTimeMs: config.connection?.fetchTimeoutMs, + serviceType: config.connection?.serviceType, }} /> diff --git a/packages/graph-explorer/src/modules/CreateConnection/CreateConnection.tsx b/packages/graph-explorer/src/modules/CreateConnection/CreateConnection.tsx index 7ccffcbdf..d0284af05 100644 --- a/packages/graph-explorer/src/modules/CreateConnection/CreateConnection.tsx +++ b/packages/graph-explorer/src/modules/CreateConnection/CreateConnection.tsx @@ -147,7 +147,7 @@ const CreateConnection = ({ proxyConnection: initialData?.proxyConnection || false, graphDbUrl: initialData?.graphDbUrl || "", awsAuthEnabled: initialData?.awsAuthEnabled || false, - serviceType: initialData?.serviceType || "neptune-db", + serviceType: initialData?.serviceType || "neptune-graph", awsRegion: initialData?.awsRegion || "", enableCache: true, cacheTimeMs: (initialData?.cacheTimeMs ?? 10 * 60 * 1000) / 60000, @@ -177,7 +177,7 @@ const CreateConnection = ({ return; } - if (form.awsAuthEnabled && !form.awsRegion) { + if (form.awsAuthEnabled && !form.awsRegion && !form.serviceType) { setError(true); return; } From fea0ebc7eed8afd70f2151422a3e2062e6d40f3b Mon Sep 17 00:00:00 2001 From: Juan Cubeddu Date: Thu, 16 Nov 2023 11:25:55 -0600 Subject: [PATCH 2/2] Remove unnecessary console.log statement in node-server.js --- packages/graph-explorer-proxy-server/node-server.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/graph-explorer-proxy-server/node-server.js b/packages/graph-explorer-proxy-server/node-server.js index f34b1e4a3..2ca5fffad 100644 --- a/packages/graph-explorer-proxy-server/node-server.js +++ b/packages/graph-explorer-proxy-server/node-server.js @@ -61,10 +61,6 @@ const errorHandler = (error, request, response, next) => { (async () => { app.use(cors()); - app.use((req, res, next) => { - console.log("Headers: ", req.headers); - next(); - }); app.use( "/defaultConnection", express.static(