Skip to content

Commit f9435a2

Browse files
WIP allow connecting to docker compose
1 parent df4cc48 commit f9435a2

File tree

4 files changed

+78
-10
lines changed

4 files changed

+78
-10
lines changed

.github/workflows/roundtrip/wait-and-test.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ WEB_APP_DIR="$(cd "${ROOT_DIR}/web-app" >/dev/null && pwd)"
99
app_version=$(cd "${ROOT_DIR}/lib" && node -p "require('./package.json').version")
1010
echo "[INFO] App version: ${app_version}"
1111

12+
if [ $1 = backend ]; then
13+
VITE_PROXY='{"/api":"http://localhost:5432","/auth":"http://localhost:5432"}'
14+
VITE_TDF_CFG='{oidc:{host:"http://localhost:65432/auth/realms/tdf",clientId:"browsertest"},kas:"http://localhost:65432/api/kas",reader:"https://secure.virtru.com/start?htmlProtocol=1"}'
15+
else
16+
VITE_PROXY='{"/kas":"http://localhost:8080","/auth":"http://localhost:8888"}'
17+
VITE_TDF_CFG='{oidc:{host:"http://localhost:65432/auth/realms/opentdf",clientId:"browsertest"},kas:"http://localhost:65432/kas",reader:"https://secure.virtru.com/start?htmlProtocol=1"}'
18+
fi
19+
export VITE_PROXY
20+
export VITE_TDF_CFG
21+
1222
_wait-for() {
1323
echo "[INFO] In retry loop for quickstarted opentdf backend..."
1424
limit=5

web-app/src/App.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { showSaveFilePicker } from 'native-file-system-adapter';
44
import './App.css';
55
import { TDF3Client, type DecryptSource, NanoTDFClient } from '@opentdf/client';
66
import { type SessionInformation, OidcClient } from './session.js';
7+
import { c } from './config.js';
78

89
function decryptedFileName(encryptedFileName: string): string {
910
// Groups: 1 file 'name' bit
@@ -30,8 +31,8 @@ function decryptedFileExtension(encryptedFileName: string): string {
3031
}
3132

3233
const oidcClient = new OidcClient(
33-
'http://localhost:65432/auth/realms/opentdf',
34-
'browsertest',
34+
c.oidc.host,
35+
c.oidc.clientId,
3536
'otdf-sample-web-app'
3637
);
3738

@@ -316,8 +317,6 @@ function App() {
316317
}),
317318
};
318319
};
319-
// http://localhost:65432/auth/realms/opentdf/protocol/openid-connect/token
320-
// http://localhost:65432/auth/realms/opentdf/protocol/openid-connect/token
321320

322321
const handleEncrypt = async () => {
323322
if (!inputSource) {
@@ -340,7 +339,7 @@ function App() {
340339
'file' in inputSource
341340
? await inputSource.file.arrayBuffer()
342341
: randomArrayBuffer(inputSource);
343-
const nanoClient = new NanoTDFClient(oidcClient, 'http://localhost:65432/kas');
342+
const nanoClient = new NanoTDFClient(oidcClient, c.kas);
344343
setDownloadState('Encrypting...');
345344
switch (sinkType) {
346345
case 'file':
@@ -373,8 +372,8 @@ function App() {
373372
const client = new TDF3Client({
374373
authProvider: oidcClient,
375374
dpopKeys: oidcClient.getSigningKey(),
376-
kasEndpoint: 'http://localhost:65432/kas',
377-
readerUrl: 'https://secure.virtru.com/start?htmlProtocol=1',
375+
kasEndpoint: c.kas,
376+
readerUrl: c.reader,
378377
});
379378
let source: ReadableStream<Uint8Array>, size: number;
380379
const sc = new AbortController();
@@ -442,7 +441,7 @@ function App() {
442441
const client = new TDF3Client({
443442
authProvider: oidcClient,
444443
dpopKeys: oidcClient.getSigningKey(),
445-
kasEndpoint: 'http://localhost:65432/kas',
444+
kasEndpoint: c.kas,
446445
});
447446
const sc = new AbortController();
448447
setStreamController(sc);
@@ -528,7 +527,7 @@ function App() {
528527
const client = new TDF3Client({
529528
authProvider: oidcClient,
530529
dpopKeys: oidcClient.getSigningKey(),
531-
kasEndpoint: 'http://localhost:65432/kas',
530+
kasEndpoint: c.kas,
532531
});
533532
try {
534533
const sc = new AbortController();
@@ -580,7 +579,7 @@ function App() {
580579
if ('url' in inputSource) {
581580
throw new Error('Unsupported : fetch the url I guess?');
582581
}
583-
const nanoClient = new NanoTDFClient(oidcClient, 'http://localhost:65432/kas');
582+
const nanoClient = new NanoTDFClient(oidcClient, c.kas);
584583
try {
585584
const cipherText =
586585
'file' in inputSource

web-app/src/config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export type TDFConfig = {
2+
oidc: {
3+
// eg 'http://localhost:65432/auth/realms/opentdf'
4+
host: string;
5+
// eg browsertest
6+
clientId: string;
7+
};
8+
kas: string;
9+
reader: string;
10+
};
11+
12+
function cfg(): TDFConfig {
13+
const { VITE_TDF_CFG } = import.meta.env;
14+
if (!VITE_TDF_CFG) {
15+
return {
16+
oidc: {
17+
host: 'http://localhost:65432/auth/realms/opentdf',
18+
clientId: 'browsertest',
19+
},
20+
kas: 'http://localhost:65432/kas',
21+
reader: 'https://secure.virtru.com/start?htmlProtocol=1',
22+
};
23+
}
24+
return JSON.parse(VITE_TDF_CFG);
25+
}
26+
27+
export const c = cfg();

web-app/vite-backend.config.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { createRequire } from 'node:module'
2+
import { defineConfig } from 'vite';
3+
import react from '@vitejs/plugin-react';
4+
5+
const require = createRequire(import.meta.url)
6+
7+
function proxy(): Record<string, string> {
8+
const { VITE_PROXY } = process.env;
9+
if (VITE_PROXY) {
10+
return JSON.parse(VITE_PROXY);
11+
}
12+
return {
13+
'/kas': 'http://localhost:8080',
14+
'/auth': 'http://localhost:8888',
15+
};
16+
}
17+
18+
19+
20+
// https://vitejs.dev/config/
21+
export default defineConfig({
22+
build: {
23+
rollupOptions: {
24+
shimMissingExports: true
25+
}
26+
},
27+
plugins: [react()],
28+
server: {
29+
port: 65432,
30+
proxy: proxy(),
31+
},
32+
});

0 commit comments

Comments
 (0)