Skip to content

Commit 669658f

Browse files
authored
chore: update mongodb-cloud-info (#5383)
* chore: update mongodb-cloud-info * cloud info values should be undefined on exception
1 parent b6dad2f commit 669658f

File tree

4 files changed

+43
-36
lines changed

4 files changed

+43
-36
lines changed

package-lock.json

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

packages/compass-connections/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
"lodash": "^4.17.21",
9191
"mocha": "^10.2.0",
9292
"mongodb-build-info": "^1.7.0",
93-
"mongodb-cloud-info": "^2.0.1",
93+
"mongodb-cloud-info": "^2.1.1",
9494
"mongodb-connection-string-url": "^2.6.0",
9595
"mongodb-data-service": "^22.17.4",
9696
"nyc": "^15.1.0",

packages/compass-connections/src/modules/telemetry.ts

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,36 @@ type HostInformation = {
1818
public_cloud_name?: string;
1919
};
2020

21+
async function getPublicCloudInfo(host: string): Promise<{
22+
public_cloud_name?: string;
23+
is_public_cloud?: boolean;
24+
}> {
25+
try {
26+
const { isAws, isAzure, isGcp } = await getCloudInfo(host);
27+
28+
const public_cloud_name = isAws
29+
? 'AWS'
30+
: isAzure
31+
? 'Azure'
32+
: isGcp
33+
? 'GCP'
34+
: undefined;
35+
36+
if (public_cloud_name === undefined) {
37+
return { is_public_cloud: false };
38+
}
39+
40+
return {
41+
is_public_cloud: true,
42+
public_cloud_name,
43+
};
44+
} catch (err) {
45+
debug('getCloudInfo failed', err);
46+
47+
return {};
48+
}
49+
}
50+
2151
async function getHostInformation(
2252
host: string | null
2353
): Promise<HostInformation> {
@@ -47,36 +77,14 @@ async function getHostInformation(
4777
};
4878
}
4979

50-
const { isAws, isAzure, isGcp } = await getCloudInfo(host).catch(
51-
(err: Error) => {
52-
debug('getCloudInfo failed', err);
53-
return {};
54-
}
55-
);
56-
const isPublicCloud = isAws || isAzure || isGcp;
57-
const publicCloudName = isAws
58-
? 'AWS'
59-
: isAzure
60-
? 'Azure'
61-
: isGcp
62-
? 'GCP'
63-
: undefined;
64-
65-
const result: HostInformation = {
80+
const publicCloudInfo = await getPublicCloudInfo(host);
81+
82+
return {
6683
is_localhost: false,
6784
is_do_url: false,
6885
is_atlas_url: isAtlas(host),
86+
...publicCloudInfo,
6987
};
70-
71-
if (typeof isPublicCloud !== 'undefined') {
72-
result.is_public_cloud = isPublicCloud;
73-
}
74-
75-
if (typeof publicCloudName !== 'undefined') {
76-
result.public_cloud_name = publicCloudName;
77-
}
78-
79-
return result;
8088
}
8189

8290
function getCsfleInformation(

packages/compass-connections/src/typings.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)