Skip to content

Commit 9661413

Browse files
authored
chore(compass-web): add connections storage implementation for compass-web COMPASS-7917 (#5863)
* chore(atlas-service): cleanup backend presets and add new values * chore(compass-web): implement connections-storage for cloud environment * chore(compass-web): emit connections-changed after polling is finished * chore(compass-web): remove only from test * chore(web): clearer code for non-atlas connection in the sandbox
1 parent 8057162 commit 9661413

16 files changed

+688
-173
lines changed

packages/atlas-service/src/atlas-service.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { createNoopLoggerAndTelemetry } from '@mongodb-js/compass-logging/provid
77
import { CompassAtlasAuthService } from './compass-atlas-auth-service';
88

99
const ATLAS_CONFIG = {
10-
atlasApiBaseUrl: 'http://example.com/api/private',
11-
atlasApiUnauthBaseUrl: 'http://api.example.com',
10+
wsBaseUrl: 'ws://example.com',
11+
cloudBaseUrl: 'ws://example.com/cloud',
12+
atlasApiBaseUrl: 'http://example.com/api',
1213
atlasLogin: {
1314
clientId: 'some-client-id',
1415
issuer: 'http://example.com/oauth2/default',

packages/atlas-service/src/atlas-service.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,20 @@ export class AtlasService {
2323
) {
2424
this.config = getAtlasConfig(preferences);
2525
}
26-
privateUnAuthEndpoint(path: string): string {
27-
return `${this.config.atlasApiUnauthBaseUrl}/${path}`;
26+
adminApiEndpoint(path?: string, requestId?: string): string {
27+
const uri = encodeURI(
28+
`${this.config.atlasApiBaseUrl}${path ? `/${path}` : ''}`
29+
);
30+
const query = requestId
31+
? `?request_id=${encodeURIComponent(requestId)}`
32+
: '';
33+
return `${uri}${query}`;
34+
}
35+
cloudEndpoint(path?: string): string {
36+
return encodeURI(`${this.config.cloudBaseUrl}${path ? `/${path}` : ''}`);
2837
}
29-
privateAtlasEndpoint(path: string, requestId?: string): string {
30-
return `${this.config.atlasApiBaseUrl}/${path}${
31-
requestId ? `?request_id=${requestId}` : ''
32-
}`;
38+
driverProxyEndpoint(path?: string): string {
39+
return encodeURI(`${this.config.wsBaseUrl}${path ? `/${path}` : ''}`);
3340
}
3441
async fetch(url: RequestInfo, init?: RequestInit): Promise<Response> {
3542
throwIfNetworkTrafficDisabled(this.preferences);
@@ -75,7 +82,6 @@ export class AtlasService {
7582
throw err;
7683
}
7784
}
78-
7985
async authenticatedFetch(
8086
url: RequestInfo,
8187
init?: RequestInit

packages/atlas-service/src/main.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ describe('CompassAuthServiceMain', function () {
5353
};
5454

5555
const defaultConfig = {
56-
atlasApiBaseUrl: 'http://example.com',
57-
atlasApiUnauthBaseUrl: 'http://example.com/unauth',
56+
wsBaseUrl: 'ws://example.com',
57+
cloudBaseUrl: 'ws://example.com/cloud',
58+
atlasApiBaseUrl: 'http://example.com/api',
5859
atlasLogin: {
5960
issuer: 'http://example.com',
6061
clientId: '1234abcd',

packages/atlas-service/src/util.ts

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -78,63 +78,95 @@ export async function throwIfNotOk(
7878
}
7979

8080
export type AtlasServiceConfig = {
81+
/**
82+
* MongoDB Driver WebSocket proxy base url
83+
*/
84+
wsBaseUrl: string;
85+
/**
86+
* Cloud UI backend base url
87+
*/
88+
cloudBaseUrl: string;
89+
/**
90+
* Atlas admin API base url
91+
*/
8192
atlasApiBaseUrl: string;
82-
atlasApiUnauthBaseUrl: string;
93+
/**
94+
* Atlas OIDC config
95+
*/
8396
atlasLogin: {
8497
clientId: string;
8598
issuer: string;
8699
};
100+
/**
101+
* Atlas Account Portal UI base url
102+
*/
87103
authPortalUrl: string;
88104
};
89105

90106
/**
91107
* Atlas service backend configurations.
92-
* - compass-dev: locally running compass kanopy backend (localhost)
93-
* - compass: compass kanopy backend (compass.mongodb.com)
94-
* - atlas-local: local mms backend (localhost)
95-
* - atlas-dev: dev mms backend (cloud-dev.mongodb.com)
96-
* - atlas: mms backend (cloud.mongodb.com)
108+
* - atlas-local: local mms backend (localhost)
109+
* - atlas-dev: dev mms backend (cloud-dev.mongodb.com)
110+
* - atlas: mms backend (cloud.mongodb.com)
111+
* - web-sandbox-atlas-local: local mms backend + proxy (localhost / proxy prefix)
112+
* - web-sandbox-atlas-dev: dev mms backend + proxy (cloud-dev.mongodb.com / proxy prefix)
113+
* - web-sandbox-atlas: mms backend + proxy (cloud.mongodb.com / proxy prefix)
97114
*/
98115
const config = {
99-
'compass-dev': {
100-
atlasApiBaseUrl: 'http://localhost:8080',
101-
atlasApiUnauthBaseUrl: 'http://localhost:8080',
116+
'atlas-local': {
117+
wsBaseUrl: 'ws://localhost:61001/ws',
118+
cloudBaseUrl: '',
119+
atlasApiBaseUrl: 'http://localhost:8080/api/private',
102120
atlasLogin: {
103-
clientId: '0oajzdcznmE8GEyio297',
104-
issuer: 'https://auth.mongodb.com/oauth2/default',
121+
clientId: '0oaq1le5jlzxCuTbu357',
122+
issuer: 'https://auth-qa.mongodb.com/oauth2/default',
105123
},
106-
authPortalUrl: 'https://account.mongodb.com/account/login',
124+
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
107125
},
108-
compass: {
109-
atlasApiBaseUrl: 'https://compass.mongodb.com',
110-
atlasApiUnauthBaseUrl: 'https://compass.mongodb.com',
126+
'atlas-dev': {
127+
wsBaseUrl: '',
128+
cloudBaseUrl: '',
129+
atlasApiBaseUrl: 'https://cloud-dev.mongodb.com/api/private',
130+
atlasLogin: {
131+
clientId: '0oaq1le5jlzxCuTbu357',
132+
issuer: 'https://auth-qa.mongodb.com/oauth2/default',
133+
},
134+
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
135+
},
136+
atlas: {
137+
wsBaseUrl: '',
138+
cloudBaseUrl: '',
139+
atlasApiBaseUrl: 'https://cloud.mongodb.com/api/private',
111140
atlasLogin: {
112141
clientId: '0oajzdcznmE8GEyio297',
113142
issuer: 'https://auth.mongodb.com/oauth2/default',
114143
},
115144
authPortalUrl: 'https://account.mongodb.com/account/login',
116145
},
117-
'atlas-local': {
146+
'web-sandbox-atlas-local': {
147+
wsBaseUrl: 'ws://localhost:1337',
148+
cloudBaseUrl: '/cloud-mongodb-com',
118149
atlasApiBaseUrl: 'http://localhost:8080/api/private',
119-
atlasApiUnauthBaseUrl: 'http://localhost:8080/api/private/unauth',
120150
atlasLogin: {
121151
clientId: '0oaq1le5jlzxCuTbu357',
122152
issuer: 'https://auth-qa.mongodb.com/oauth2/default',
123153
},
124154
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
125155
},
126-
'atlas-dev': {
156+
'web-sandbox-atlas-dev': {
157+
wsBaseUrl: 'ws://localhost:1337',
158+
cloudBaseUrl: '/cloud-mongodb-com',
127159
atlasApiBaseUrl: 'https://cloud-dev.mongodb.com/api/private',
128-
atlasApiUnauthBaseUrl: 'https://cloud-dev.mongodb.com/api/private/unauth',
129160
atlasLogin: {
130161
clientId: '0oaq1le5jlzxCuTbu357',
131162
issuer: 'https://auth-qa.mongodb.com/oauth2/default',
132163
},
133164
authPortalUrl: 'https://account-dev.mongodb.com/account/login',
134165
},
135-
atlas: {
166+
'web-sandbox-atlas': {
167+
wsBaseUrl: 'ws://localhost:1337',
168+
cloudBaseUrl: '/cloud-mongodb-com',
136169
atlasApiBaseUrl: 'https://cloud.mongodb.com/api/private',
137-
atlasApiUnauthBaseUrl: 'https://cloud.mongodb.com/api/private/unauth',
138170
atlasLogin: {
139171
clientId: '0oajzdcznmE8GEyio297',
140172
issuer: 'https://auth.mongodb.com/oauth2/default',
@@ -148,9 +180,7 @@ export function getAtlasConfig(
148180
) {
149181
const { atlasServiceBackendPreset } = preferences.getPreferences();
150182
const envConfig = {
151-
atlasApiBaseUrl: process.env.COMPASS_ATLAS_SERVICE_BASE_URL_OVERRIDE,
152-
atlasApiUnauthBaseUrl:
153-
process.env.COMPASS_ATLAS_SERVICE_UNAUTH_BASE_URL_OVERRIDE,
183+
atlasApiBaseUrl: process.env.COMPASS_ATLAS_SERVICE_UNAUTH_BASE_URL_OVERRIDE,
154184
atlasLogin: {
155185
clientId: process.env.COMPASS_CLIENT_ID_OVERRIDE,
156186
issuer: process.env.COMPASS_OIDC_ISSUER_OVERRIDE,
@@ -160,7 +190,7 @@ export function getAtlasConfig(
160190
return defaultsDeep(
161191
envConfig,
162192
config[atlasServiceBackendPreset]
163-
) as typeof envConfig & typeof config[keyof typeof config];
193+
) as AtlasServiceConfig;
164194
}
165195

166196
export function getTrackingUserInfo(userInfo: AtlasUserInfo) {

packages/compass-generative-ai/src/atlas-ai-service.spec.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class MockAtlasAuthService extends AtlasAuthService {
4343

4444
class MockAtlasService {
4545
getCurrentUser = () => Promise.resolve(ATLAS_USER);
46-
privateUnAuthEndpoint = (url: string) => [BASE_URL, url].join('/');
47-
privateAtlasEndpoint = (url: string, requestId?: string) =>
46+
adminApiEndpoint = (url: string, requestId?: string) =>
4847
`${[BASE_URL, url].join('/')}${
4948
requestId ? `?request_id=${requestId}` : ''
5049
}`;

packages/compass-generative-ai/src/atlas-ai-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type GenerativeAiInput = {
2626
// want to ensure we're not uploading massive documents (some folks have documents > 1mb).
2727
const AI_MAX_REQUEST_SIZE = 100000;
2828
const AI_MIN_SAMPLE_DOCUMENTS = 1;
29-
const USER_AI_URI = (userId: string) => `ai/api/v1/hello/${userId}`;
29+
const USER_AI_URI = (userId: string) => `unauth/ai/api/v1/hello/${userId}`;
3030
const AGGREGATION_URI = 'ai/api/v1/mql-aggregation';
3131
const QUERY_URI = 'ai/api/v1/mql-query';
3232

@@ -227,7 +227,7 @@ export class AtlasAiService {
227227

228228
private async getAIFeatureEnablement(): Promise<AIFeatureEnablement> {
229229
const userId = this.preferences.getPreferencesUser().id;
230-
const url = this.atlasService.privateUnAuthEndpoint(USER_AI_URI(userId));
230+
const url = this.atlasService.adminApiEndpoint(USER_AI_URI(userId));
231231
const res = await this.atlasService.fetch(url, {
232232
headers: {
233233
Accept: 'application/json',
@@ -282,7 +282,7 @@ export class AtlasAiService {
282282
const { signal, requestId, ...rest } = input;
283283
const msgBody = buildQueryOrAggregationMessageBody(rest);
284284

285-
const url = this.atlasService.privateAtlasEndpoint(uri, requestId);
285+
const url = this.atlasService.adminApiEndpoint(uri, requestId);
286286

287287
this.logger.log.info(
288288
this.logger.mongoLogId(1_001_000_308),

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ export type UserConfigurablePreferences = PermanentFeatureFlags &
4242
// except for user preferences doesn't allow required preferences to be
4343
// defined, so we are sticking it here
4444
atlasServiceBackendPreset:
45-
| 'compass-dev'
46-
| 'compass'
4745
| 'atlas-local'
4846
| 'atlas-dev'
49-
| 'atlas';
47+
| 'atlas'
48+
| 'web-sandbox-atlas-local'
49+
| 'web-sandbox-atlas-dev'
50+
| 'web-sandbox-atlas';
5051
// Features that are enabled by default in Compass, but are disabled in Data
5152
// Explorer
5253
enableExplainPlan: boolean;
@@ -631,8 +632,6 @@ export const storedUserPreferencesProps: Required<{
631632

632633
/**
633634
* Chooses atlas service backend configuration from preset
634-
* - compass-dev: locally running compass kanopy backend (localhost)
635-
* - compass: compass kanopy backend (compass.mongodb.com)
636635
* - atlas-local: local mms backend (http://localhost:8080)
637636
* - atlas-dev: dev mms backend (cloud-dev.mongodb.com)
638637
* - atlas: mms backend (cloud.mongodb.com)
@@ -645,7 +644,14 @@ export const storedUserPreferencesProps: Required<{
645644
short: 'Configuration used by atlas service',
646645
},
647646
validator: z
648-
.enum(['compass-dev', 'compass', 'atlas-dev', 'atlas-local', 'atlas'])
647+
.enum([
648+
'atlas-dev',
649+
'atlas-local',
650+
'atlas',
651+
'web-sandbox-atlas-dev',
652+
'web-sandbox-atlas-local',
653+
'web-sandbox-atlas',
654+
])
649655
.default('atlas'),
650656
type: 'string',
651657
},

packages/compass-web/sandbox/atlas-cluster-connections.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,6 @@ export function useAtlasClusterConnectionsList(): AtlasClusterConnectionsListRet
6767
id: cluster.uniqueId,
6868
connectionOptions: {
6969
connectionString: connectionString.toString(),
70-
lookup() {
71-
return {
72-
wsURL: 'ws://localhost:1337',
73-
projectId: projectId,
74-
clusterName: cluster.name,
75-
srvAddress: cluster.srvAddress,
76-
};
77-
},
7870
},
7971
atlasMetadata: {
8072
orgId: '',

0 commit comments

Comments
 (0)