Skip to content

Commit 4da150c

Browse files
author
Paul Korzhyk
committed
Add Slash API Key to the Extra Settings
1 parent 3bd6d62 commit 4da150c

File tree

7 files changed

+1727
-1646
lines changed

7 files changed

+1727
-1646
lines changed

client/package-lock.json

Lines changed: 1671 additions & 1637 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
"core-js": "^3.6.5",
188188
"crypto-js": "^4.0.0",
189189
"d3": "^5.16.0",
190-
"dgraph-js-http": "^20.7.0-rc1",
190+
"dgraph-js-http": "^20.7.1-rc1",
191191
"graphql": "0.13.0",
192192
"immer": "^6.0.3",
193193
"jquery": "^3.5.0",

client/src/actions/connection.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ import {
2121
QUERY_TIMEOUT_DEFAULT,
2222
Unknown,
2323
} from "../lib/constants";
24-
import { sanitizeUrl, setCurrentServerUrl } from "../lib/helpers";
2524

2625
export const LOGIN_ERROR = "connection/LOGIN_ERROR";
2726
export const LOGIN_PENDING = "connection/LOGIN_PENDING";
2827
export const LOGIN_SUCCESS = "connection/LOGIN_SUCCESS";
2928
export const LOGIN_TIMEOUT = "connection/LOGIN_TIMEOUT";
3029
export const DO_LOGOUT = "connection/DO_LOGOUT";
3130
export const SET_QUERY_TIMEOUT = "connection/SET_QUERY_TIMEOUT";
31+
export const SET_SLASH_API_KEY = "connection/SET_SLASH_API_KEY";
3232
export const UPDATE_URL = "connection/UPDATE_URL";
3333
export const UPDATE_ACL_STATE = "connection/UPDATE_ACL_STATE";
3434
export const UPDATE_NETWORK_HEALTH = "connection/UPDATE_NETWORK_HEALTH";
@@ -53,12 +53,20 @@ export function setQueryTimeout(url, queryTimeout) {
5353
};
5454
}
5555

56+
export function setSlashApiKey(url, slashApiKey) {
57+
return {
58+
type: SET_SLASH_API_KEY,
59+
url,
60+
slashApiKey,
61+
};
62+
}
63+
5664
export const updateUrl = url => async (dispatch, getState) => {
5765
dispatch(loginTimeout(getState().connection.serverHistory[0].url));
5866

5967
dispatch({
6068
type: UPDATE_URL,
61-
url: sanitizeUrl(url),
69+
url: helpers.sanitizeUrl(url),
6270
});
6371

6472
dispatch(checkHealth());
@@ -82,7 +90,7 @@ export const checkNetworkHealth = async (dispatch, getState) => {
8290
export const checkAclState = async (dispatch, getState) => {
8391
const url = getState().connection.serverHistory[0].url;
8492
try {
85-
setCurrentServerUrl(url);
93+
helpers.setCurrentServerUrl(url);
8694
const client = await helpers.getDgraphClient();
8795
const res = await client
8896
.newTxn()
@@ -105,7 +113,7 @@ export const checkHealth = ({
105113
const url = getState().connection.serverHistory[0].url;
106114
unknownOnStart && dispatch(serverHealth(url, Unknown));
107115
try {
108-
setCurrentServerUrl(url);
116+
helpers.setCurrentServerUrl(url);
109117
const stub = await helpers.getDgraphClientStub();
110118
const health = await stub.getHealth();
111119
dispatch(serverHealth(url, OK));

client/src/components/ServerConnectionModal.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ export default function ServerConnectionModal() {
122122
}}
123123
/>
124124
</Form.Group>
125+
<Form.Group controlId="slashApiKeyInput">
126+
<Form.Label>Slash API Key:</Form.Label>
127+
<Form.Control
128+
type="text"
129+
placeholder="Slash API Key"
130+
value={activeServer.slashApiKey}
131+
onChange={e =>
132+
dispatch(
133+
actions.setSlashApiKey(
134+
activeServer.url,
135+
e.target.value,
136+
),
137+
)
138+
}
139+
/>
140+
</Form.Group>
125141
</Tab>
126142
</Tabs>
127143
);

client/src/containers/AppProvider.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import makeRootReducer from "../reducers";
3030

3131
import {
3232
setCurrentServerQueryTimeout,
33+
setCurrentServerSlashApiKey,
3334
setCurrentServerUrl,
3435
} from "../lib/helpers";
3536

@@ -58,6 +59,9 @@ store.subscribe(() => {
5859
setCurrentServerQueryTimeout(
5960
store.getState().connection.serverHistory[0].queryTimeout || 20,
6061
);
62+
setCurrentServerSlashApiKey(
63+
store.getState().connection.serverHistory[0].slashApiKey,
64+
);
6165
});
6266

6367
export default class AppProvider extends React.Component {
@@ -101,7 +105,7 @@ export default class AppProvider extends React.Component {
101105
);
102106
}
103107

104-
if (state && state.frames) {
108+
if (state?.frames) {
105109
// HACK: setResultsTab will validate the tab name.
106110
store.dispatch(setResultsTab(state.frames.tab));
107111
}

client/src/lib/helpers.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ export function humanizeBytes(space) {
7676
}
7777

7878
let dgraphServerUrl = getDefaultUrl();
79+
const clientStubOptions = { headers: {} };
7980

8081
const createDgraphClient = memoizeOne(async url => {
81-
const stub = new dgraph.DgraphClientStub(url, {
82-
jsonParser: JSONbigint.parse.bind(JSONbigint),
83-
});
82+
const stub = new dgraph.DgraphClientStub(
83+
url,
84+
{
85+
jsonParser: JSONbigint.parse.bind(JSONbigint),
86+
},
87+
clientStubOptions,
88+
);
8489
try {
8590
await stub.detectApiVersion();
8691
} catch (err) {
@@ -102,6 +107,10 @@ export async function setCurrentServerQueryTimeout(timeout) {
102107
(await createDgraphClient(dgraphServerUrl)).client.setQueryTimeout(timeout);
103108
}
104109

110+
export function setCurrentServerSlashApiKey(slashApiKey) {
111+
clientStubOptions.headers["X-Auth-Token"] = slashApiKey;
112+
}
113+
105114
export const getDgraphClient = async () =>
106115
(await createDgraphClient(dgraphServerUrl)).client;
107116

client/src/reducers/connection.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
LOGIN_SUCCESS,
2323
LOGIN_TIMEOUT,
2424
SET_QUERY_TIMEOUT,
25+
SET_SLASH_API_KEY,
2526
UPDATE_URL,
2627
UPDATE_ACL_STATE,
2728
UPDATE_NETWORK_HEALTH,
@@ -36,6 +37,7 @@ import {
3637
import {
3738
getDefaultUrl,
3839
setCurrentServerQueryTimeout,
40+
setCurrentServerSlashApiKey,
3941
setCurrentServerUrl,
4042
sanitizeUrl,
4143
} from "../lib/helpers";
@@ -65,6 +67,7 @@ const makeServerRecord = url => ({
6567
networkHealth: Unknown,
6668
aclState: Unknown,
6769
queryTimeout: QUERY_TIMEOUT_DEFAULT,
70+
slashApiKey: null,
6871

6972
licenseWarningDismissedTs: -1,
7073

@@ -143,6 +146,13 @@ export default (state = defaultState, action) =>
143146
setCurrentServerQueryTimeout(activeServer.queryTimeout);
144147
}
145148
break;
149+
case SET_SLASH_API_KEY:
150+
assert(action.url, "This action requires url " + action.type);
151+
activeServer.slashApiKey = action.slashApiKey;
152+
if (action.url === currentServer.url) {
153+
setCurrentServerSlashApiKey(activeServer.slashApiKey);
154+
}
155+
break;
146156

147157
case DO_LOGOUT:
148158
logoutServer(currentServer);

0 commit comments

Comments
 (0)