Skip to content

Commit 29c53bd

Browse files
authored
chore(compass-web): use ccs for atlas sandbox instead of local proxy COMPASS-8693 (#6570)
* chore(compass-web): use ccs for atlas sandbox instead of local proxy * chore: clean-up headers override, allow to filter out headers * chore(web): listen to socket error to avoid uncaught exceptions
1 parent 375a2b4 commit 29c53bd

File tree

8 files changed

+193
-229
lines changed

8 files changed

+193
-229
lines changed

packages/atlas-service/src/util.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ export type AtlasServiceConfig = {
122122
* Atlas service backend configurations.
123123
* - atlas-local: local mms backend (localhost)
124124
* - atlas-dev: dev mms backend (cloud-dev.mongodb.com)
125+
* - atlas-qa: qa mms backend (cloud-qa.mongodb.com)
125126
* - atlas: mms backend (cloud.mongodb.com)
126127
* - web-sandbox-atlas-local: local mms backend + proxy (localhost / proxy prefix)
127128
* - web-sandbox-atlas-dev: dev mms backend + proxy (cloud-dev.mongodb.com / proxy prefix)
129+
* - web-sandbox-atlas-qa: qa mms backend + proxy (cloud-qa.mongodb.com / proxy prefix)
128130
* - web-sandbox-atlas: mms backend + proxy (cloud.mongodb.com / proxy prefix)
129131
*/
130132
const config = {
@@ -148,6 +150,16 @@ const config = {
148150
},
149151
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
150152
},
153+
'atlas-qa': {
154+
wsBaseUrl: '',
155+
cloudBaseUrl: '',
156+
atlasApiBaseUrl: 'https://cloud-qa.mongodb.com/api/private',
157+
atlasLogin: {
158+
clientId: '0oaq1le5jlzxCuTbu357',
159+
issuer: 'https://auth-qa.mongodb.com/oauth2/default',
160+
},
161+
authPortalUrl: 'https://account-qa.mongodb.com/account/login',
162+
},
151163
atlas: {
152164
wsBaseUrl: '',
153165
cloudBaseUrl: '',
@@ -159,7 +171,7 @@ const config = {
159171
authPortalUrl: 'https://account.mongodb.com/account/login',
160172
},
161173
'web-sandbox-atlas-local': {
162-
wsBaseUrl: 'ws://localhost:1337',
174+
wsBaseUrl: '/ccs',
163175
cloudBaseUrl: '/cloud-mongodb-com',
164176
atlasApiBaseUrl: 'http://localhost:8080/api/private',
165177
atlasLogin: {
@@ -169,7 +181,17 @@ const config = {
169181
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
170182
},
171183
'web-sandbox-atlas-dev': {
172-
wsBaseUrl: 'ws://localhost:1337',
184+
wsBaseUrl: '/ccs',
185+
cloudBaseUrl: '/cloud-mongodb-com',
186+
atlasApiBaseUrl: 'https://cloud-dev.mongodb.com/api/private',
187+
atlasLogin: {
188+
clientId: '0oaq1le5jlzxCuTbu357',
189+
issuer: 'https://auth-qa.mongodb.com/oauth2/default',
190+
},
191+
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
192+
},
193+
'web-sandbox-atlas-qa': {
194+
wsBaseUrl: '/ccs',
173195
cloudBaseUrl: '/cloud-mongodb-com',
174196
atlasApiBaseUrl: 'https://cloud-dev.mongodb.com/api/private',
175197
atlasLogin: {
@@ -179,7 +201,7 @@ const config = {
179201
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
180202
},
181203
'web-sandbox-atlas': {
182-
wsBaseUrl: 'ws://localhost:1337',
204+
wsBaseUrl: '/ccs',
183205
cloudBaseUrl: '/cloud-mongodb-com',
184206
atlasApiBaseUrl: 'https://cloud.mongodb.com/api/private',
185207
atlasLogin: {

packages/compass-e2e-tests/helpers/compass-web-sandbox.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ export async function spawnCompassWebSandboxAndSignInToAtlas(
182182
return electronProxyRemote;
183183
}
184184

185-
debug('Waiting for x509 cert to propagate to Atlas clusters ...');
186-
187-
await fetch(`${sandboxUrl}/x509`);
188-
189185
return electronProxyRemote;
190186
}
191187

packages/compass-preferences-model/src/preferences-schema.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ export type UserConfigurablePreferences = PermanentFeatureFlags &
5252
atlasServiceBackendPreset:
5353
| 'atlas-local'
5454
| 'atlas-dev'
55+
| 'atlas-qa'
5556
| 'atlas'
5657
| 'web-sandbox-atlas-local'
5758
| 'web-sandbox-atlas-dev'
59+
| 'web-sandbox-atlas-qa'
5860
| 'web-sandbox-atlas';
5961
optInDataExplorerGenAIFeatures: boolean;
6062
// Features that are enabled by default in Compass, but are disabled in Data
@@ -669,6 +671,7 @@ export const storedUserPreferencesProps: Required<{
669671
* Chooses atlas service backend configuration from preset
670672
* - atlas-local: local mms backend (http://localhost:8080)
671673
* - atlas-dev: dev mms backend (cloud-dev.mongodb.com)
674+
* - atlas-qa: qa mms backend (cloud-qa.mongodb.com)
672675
* - atlas: mms backend (cloud.mongodb.com)
673676
*/
674677
atlasServiceBackendPreset: {
@@ -680,11 +683,13 @@ export const storedUserPreferencesProps: Required<{
680683
},
681684
validator: z
682685
.enum([
683-
'atlas-dev',
684686
'atlas-local',
687+
'atlas-dev',
688+
'atlas-qa',
685689
'atlas',
686-
'web-sandbox-atlas-dev',
687690
'web-sandbox-atlas-local',
691+
'web-sandbox-atlas-dev',
692+
'web-sandbox-atlas-qa',
688693
'web-sandbox-atlas',
689694
])
690695
.default('atlas'),

packages/compass-web/polyfills/net/index.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ import { ipVersion } from 'is-ip';
22
import type { ConnectionOptions } from 'mongodb-data-service';
33
import { Duplex } from 'stream';
44

5-
const WS_PROXY_PORT = process.env.COMPASS_WEB_WS_PROXY_PORT
6-
? Number(process.env.COMPASS_WEB_WS_PROXY_PORT)
7-
: 1337;
8-
95
/**
106
* net.Socket interface that works over the WebSocket connection. For now, only
117
* used when running compass-web in a local sandbox, mms has their own
128
* implementation
139
*/
1410
class Socket extends Duplex {
11+
private _tls = false;
1512
private _ws: WebSocket | null = null;
1613
private _setOptions: {
1714
setKeepAlive?: { enabled?: boolean; initialDelay?: number };
@@ -30,17 +27,20 @@ class Socket extends Duplex {
3027
lookup?: ConnectionOptions['lookup'];
3128
tls?: boolean;
3229
}) {
33-
const { wsURL, ...atlasOptions } = lookup?.() ?? {};
34-
this._ws = new WebSocket(wsURL ?? `ws://localhost:${WS_PROXY_PORT}`);
30+
this._tls = !!options.tls;
31+
const { wsURL, ...atlasOptions } =
32+
lookup?.() ?? ({} as { wsURL?: string; clusterName?: string });
33+
this._ws = new WebSocket(wsURL ?? '/ws-proxy');
3534
this._ws.binaryType = 'arraybuffer';
3635
this._ws.addEventListener(
3736
'open',
3837
() => {
3938
const connectMsg = JSON.stringify({
40-
connectOptions: options,
41-
atlasOptions:
42-
Object.keys(atlasOptions).length > 0 ? atlasOptions : undefined,
43-
setOptions: this._setOptions,
39+
port: options.port,
40+
host: options.host,
41+
tls: options.tls ?? false,
42+
clusterName: atlasOptions.clusterName,
43+
ok: 1,
4444
});
4545
setTimeout(() => {
4646
this._ws?.send(connectMsg);
@@ -59,16 +59,12 @@ class Socket extends Duplex {
5959
({ data }: MessageEvent<string | ArrayBuffer>) => {
6060
if (typeof data === 'string') {
6161
try {
62-
const { evt, error } = JSON.parse(data) as {
63-
evt: string;
64-
error?: Error;
65-
};
66-
setTimeout(() => {
67-
this.emit(
68-
evt,
69-
evt === 'error' ? Object.assign(new Error(), error) : undefined
70-
);
71-
});
62+
const res = JSON.parse(data) as { preMessageOk: 1 };
63+
if (res.preMessageOk) {
64+
setTimeout(() => {
65+
this.emit(this._tls ? 'secureConnect' : 'connect');
66+
});
67+
}
7268
} catch (err) {
7369
// eslint-disable-next-line no-console
7470
console.error('error parsing proxy message "%s":', data, err);

packages/compass-web/sandbox/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ const App = () => {
4949
const atlasServiceSandboxBackendVariant =
5050
process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'local'
5151
? 'web-sandbox-atlas-local'
52-
: process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'dev' ||
53-
process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'qa'
52+
: process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'dev'
5453
? 'web-sandbox-atlas-dev'
54+
: process.env.COMPASS_WEB_HTTP_PROXY_CLOUD_CONFIG === 'qa'
55+
? 'web-sandbox-atlas-qa'
5556
: 'web-sandbox-atlas';
5657

5758
const sandboxPreferencesUpdateTrigger =

0 commit comments

Comments
 (0)