Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Default Connection Support #108

Merged
merged 25 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c553c99
add acceptance of config file for default connection in the docker ru…
May 9, 2023
2f6043f
add FE support to accept default connection
May 11, 2023
e430197
Add support for providing connection details through docker --env var…
May 12, 2023
cf07a96
Build app during build time and add https environment variable to run…
Jun 1, 2023
f1d17a8
Fix README
Jun 1, 2023
f950b23
Bug fix for Adding default configuration when no graph_connection_url…
Jun 8, 2023
695734a
Fix container failing to start when PROXY_SERVER_HTTPS_CONNECTION is …
michaelnchin Jun 21, 2023
7844020
Update node version in git workflow to fix pnpm install errors
jackson-millard Jul 7, 2023
126b061
Merge branch 'AddDefaultConfiguration' of https://github.com/jackson-…
jackson-millard Jul 7, 2023
18cb0c4
Merge in latest
jackson-millard Jul 7, 2023
99fa172
Update docker-entrypoint.sh
michaelnchin Jul 18, 2023
64befe7
Accept GRAPH_EXP_HTTPS_CONNECTION setting on run, enforce default for…
michaelnchin Jul 19, 2023
3d2fc99
feat: docker ignore node_modules to avoid issues with Esbuild switchi…
agutierrezgit Jul 26, 2023
b686a8d
feat: update graph type name to match with translations used in the r…
agutierrezgit Jul 26, 2023
f7aa6da
feat: add GRAPH_EXP_HTTPS_CONNECTION attribute and format markdown
agutierrezgit Jul 26, 2023
c2a63b3
feat: add readOnly prop to connection config
agutierrezgit Jul 26, 2023
c8fbd05
feat: make file config readonly by default unless indicated otherwise
agutierrezgit Jul 26, 2023
83b65e4
feat: grab config refactor to fix syntax error when defaultConnection…
agutierrezgit Jul 26, 2023
8682d4f
feat: disable edit for read-only configurations
agutierrezgit Jul 26, 2023
12cefa7
feat: create multiple default connections when graph type is not spec…
agutierrezgit Jul 28, 2023
2405126
Merge pull request #1 from jackson-millard/agutierrez/AddDefaultConfi…
agutierrezgit Jul 31, 2023
056b692
Merge remote-tracking branch 'upstream/main' into AddDefaultConfigura…
michaelnchin Aug 2, 2023
505fa6f
Merge branch 'main' of https://github.com/aws/graph-explorer into Add…
michaelnchin Aug 9, 2023
c392caf
update changelog
michaelnchin Aug 9, 2023
794352f
Merge branch 'main' into AddDefaultConfiguration
michaelnchin Aug 15, 2023
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ COPY . /graph-explorer/
WORKDIR /graph-explorer
# Keeping all the RUN commands on a single line reduces the number of layers and,
# as a result, significantly reduces the final image size.
RUN curl -sL https://rpm.nodesource.com/setup_16.x | bash - && yum install -y nodejs openssl && npm install -g pnpm && pnpm install && rm -rf /var/cache/yum
RUN curl -sL https://rpm.nodesource.com/setup_16.x | bash - && yum install -y nodejs openssl && npm install -g pnpm && pnpm install && rm -rf /var/cache/yum && chmod a+x ./process-environment.sh
WORKDIR /graph-explorer/
ENV HOME=/graph-explorer
RUN pnpm build
Expand Down
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ You can create and manage connections to graph databases using this feature. Con
* __Add a new connection:__
* __Name:__ Enter a name for your connection (e.g., `MyNeptuneCluster`).
* __Graph Type:__ Choose a graph data model that corresponds to your graph database.
* __Public Endpoint:__ Provide the publicly accessible endpoint URL for a graph database, e.g., Gremlin Server. If connecting to Amazon Neptune, then provide a proxy endpoint URL that is accessible from outside the VPC, e.g., EC2.
* __Public or proxy endpoint:__ Provide the publicly accessible endpoint URL for a graph database, e.g., Gremlin Server. If connecting to Amazon Neptune, then provide a proxy endpoint URL that is accessible from outside the VPC, e.g., EC2.
* **Note:** For connecting to Amazon Neptune, ensure that the graph connection URL is in the format `https://[NEPTUNE_ENDPOINT]:8182`, and that the proxy endpoint URL is either `https://[EC2_PUBLIC_HOSTNAME]:443` or `http://[EC2_PUBLIC_HOSTNAME]:80`, depending on the protocol used. Ensure that you don't end either of the URLs with `/`.
* __Using proxy server:__ Check this box if using a proxy endpoint.
Expand Down Expand Up @@ -94,6 +93,39 @@ You can search, browse, expand, customize views of your graph data using Graph E
## Connections
The Graph Explorer supports visualizing both **property graphs** and **RDF graphs**. You can connect to Amazon Neptune or you can also connect to open graph databases that implement an Apache TinkerPop Gremlin Server endpoint or the SPARQL 1.1 protocol, such as Blazegraph. For additional details on connecting to different graph databases, see [Connections](./additionaldocs/connections.md).

### Providing a Default Connection
To provide a default connection such that initial loads of the graph explorer always result with the same starting connection, modify the `docker run ...` command to either take in a json configuration or runtime environment variables. A json configuration approach would look like `docker run -p 80:80 -p 443:443 --env HOST={hostname-or-ip-address} -v /path/to/config.json:/graph-explorer/config.json graph-explorer` or create a `config.json` file at the root of the project. An environment variable approach would look like `docker run -p 80:80 -p 443:443 --env HOST={hostname-or-ip-address} --env PUBLIC_OR_PROXY_ENDPOINT=https://public-endpoint --env GRAPH_TYPE=gremlin --env USING_PROXY_SERVER=true --env IAM=false --env GRAPH_CONNECTION_URL=https://cluster-cqmizgqgrsbf.us-west-2.neptune.amazonaws.com:8182 --env AWS_REGION=us-west-2 --env PROXY_SERVER_HTTPS_CONNECTION=true graph-explorer`. IF you provide both, the json approach will be prioritized.


The set of valid ENV connection variables, their defaults, and their descriptions:
* Required:
* PUBLIC_OR_PROXY_ENDPOINT - None - See [Add a New Connection](#connections-ui)
* Optional
* GRAPH_TYPE - PG (Property Graph)- See [Add a New Connection](#connections-ui)
* USING_PROXY_SERVER - False- See [Add a New Connection](#connections-ui)
* IAM - False- See [Add a New Connection](#connections-ui)
* PROXY_SERVER_HTTPS_CONNECTION - True - Controls whether the server uses SSL or not
* Conditionally Required:
* Required if USING_PROXY_SERVER=True
* 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)


The config.json file should provide values for the attributes at the top level as in the example below:

```
{
"PUBLIC_OR_PROXY_ENDPOINT": "https://public-endpoint",
"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)
"AWS_REGION": "us-west-2",
"GRAPH_TYPE": "gremlin" (Possible Values: "gremlin" or "sparql"),
"PROXY_SERVER_HTTPS_CONNECTION: true, (Can be string or boolean)
}
```

## Development
For development guidance, see [Development](./additionaldocs/development.md).

Expand Down
12 changes: 8 additions & 4 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/sh

if [ $(grep -e 'GRAPH_EXP_HTTPS_CONNECTION' ./packages/graph-explorer/.env | cut -d "=" -f 2) ]; then
./process-environment.sh

PROXY_SERVER_HTTPS_CONNECTION_VALUE = $(grep -e 'PROXY_SERVER_HTTPS_CONNECTION' ./packages/graph-explorer/.env | cut -d "=" -f 2)

if [ -n "$PROXY_SERVER_HTTPS_CONNECTION_VALUE" ] && [ "$PROXY_SERVER_HTTPS_CONNECTION_VALUE" == "true" ]; then

if [ $HOST ]; then
echo "Generating new self-signed SSL cert using $HOST..."
Expand All @@ -11,19 +15,19 @@ if [ $(grep -e 'GRAPH_EXP_HTTPS_CONNECTION' ./packages/graph-explorer/.env | cut
openssl genrsa -out ./server.key 2048
openssl req -new -key ./server.key -out ./server.csr -config ./csr.conf
openssl x509 -req -in ./server.csr -CA ./rootCA.crt -CAkey ./rootCA.key -CAcreateserial -out ./server.crt -days 365 -sha256 -extfile ./cert.conf
else
else
echo "No HOST environment variable specified."
if [ -f "./rootCA.key" ] && [ -f "./rootCA.crt" ] && [ -f "./rootCA.crt" ] && [ -f "./server.csr"] && [ -f "./server.crt"]; then
echo "Found existing self-signed SSL certificate. Re-using existing cert."
else
else
echo "No existing self-signed SSL certificate found. Please specify --env HOST=<hostname> during docker run command to create SSL cert."
exit 1
fi
fi

else
echo "SSL disabled. Skipping self-signed certificate generation."
exit 1
fi

echo "Starting graph explorer..."
pnpm -w start:proxy-server
1 change: 1 addition & 0 deletions packages/graph-explorer-proxy-server/node-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dotenv.config({ path: "../graph-explorer/.env" });
app.use(cors());

app.use("/explorer", express.static(path.join(__dirname, "../graph-explorer/dist")));
app.use("/defaultConnection", express.static(path.join(__dirname, "../graph-explorer/defaultConnection.json")));

const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms));

Expand Down
2 changes: 0 additions & 2 deletions packages/graph-explorer/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
PROXY_SERVER_HTTPS_CONNECTION=true
GRAPH_EXP_HTTPS_CONNECTION=true
GRAPH_EXP_ENV_ROOT_FOLDER=/explorer
87 changes: 54 additions & 33 deletions packages/graph-explorer/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,67 @@
import queryString from "query-string";
import React from "react";
import React, { useEffect, useState } from "react";
import ReactDOM from "react-dom";
import { HashRouter as Router } from "react-router-dom";
import App from "./App";
import { RawConfiguration } from "./core";
import ConnectedProvider from "./core/ConnectedProvider";
import "./index.css";

const params = queryString.parse(location.search) as {
configFile?: string;
};
const BootstrapApp = () => {
const [config, setConfig] = useState<RawConfiguration | undefined>(undefined);

useEffect(() => {
const grabConfig = async () => {
const defaultConnectionPath = `${location.origin}/defaultConnection`;
const params = queryString.parse(location.search) as {
configFile?: string;
};

try {
const defaultConnectionFile = await fetch(defaultConnectionPath)

if (params.configFile) {
setConfig({
id: params.configFile,
remoteConfigFile: params.configFile,
});
} else if (defaultConnectionFile.ok) {
let defaultConnectionData = await defaultConnectionFile.json();

setConfig({
id: "Default Connection",
displayLabel: "Default Connection",
connection: {
url: defaultConnectionData.GRAPH_EXP_PUBLIC_OR_PROXY_ENDPOINT || "",
queryEngine: (defaultConnectionData.GRAPH_EXP_GRAPH_TYPE.toLowerCase() === "sparql") ? "sparql" : "gremlin",
proxyConnection: defaultConnectionData.GRAPH_EXP_USING_PROXY_SERVER ? true : false,
graphDbUrl: defaultConnectionData.GRAPH_EXP_CONNECTION_URL || "",
awsAuthEnabled: defaultConnectionData.GRAPH_EXP_IAM ? true : false,
awsRegion: defaultConnectionData.GRAPH_EXP_AWS_REGION || "",
},
});
}

} catch (error) {
console.error(`Error when trying to create connection: ${error}`);
}
};

let config: RawConfiguration | undefined = undefined;
if (params.configFile) {
config = {
id: params.configFile,
remoteConfigFile: params.configFile,
};
} else if (import.meta.env.GRAPH_EXP_CONNECTION_URL) {
config = {
id: import.meta.env.GRAPH_EXP_CONNECTION_URL,
displayLabel:
import.meta.env.GRAPH_EXP_CONNECTION_NAME ||
import.meta.env.GRAPH_EXP_CONNECTION_URL,
connection: {
url: import.meta.env.GRAPH_EXP_CONNECTION_URL,
queryEngine:
(import.meta.env.GRAPH_EXP_CONNECTION_ENGINE as
| "gremlin"
| "sparql"
| undefined) || "gremlin",
},
};
}
grabConfig();
}, []);

return (
<React.StrictMode>
<Router>
<ConnectedProvider config={config}>
<App />
</ConnectedProvider>
</Router>
</React.StrictMode>
);
};

ReactDOM.render(
<React.StrictMode>
<Router>
<ConnectedProvider config={config}>
<App />
</ConnectedProvider>
</Router>
</React.StrictMode>,
<BootstrapApp />,
document.getElementById("root")
);
Loading
Loading