Skip to content

Commit

Permalink
chore: update mongodb-cloud-info (#5383)
Browse files Browse the repository at this point in the history
* chore: update mongodb-cloud-info

* cloud info values should be undefined on exception
  • Loading branch information
mcasimir authored Jan 29, 2024
1 parent b6dad2f commit 669658f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/compass-connections/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"lodash": "^4.17.21",
"mocha": "^10.2.0",
"mongodb-build-info": "^1.7.0",
"mongodb-cloud-info": "^2.0.1",
"mongodb-cloud-info": "^2.1.1",
"mongodb-connection-string-url": "^2.6.0",
"mongodb-data-service": "^22.17.4",
"nyc": "^15.1.0",
Expand Down
60 changes: 34 additions & 26 deletions packages/compass-connections/src/modules/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,36 @@ type HostInformation = {
public_cloud_name?: string;
};

async function getPublicCloudInfo(host: string): Promise<{
public_cloud_name?: string;
is_public_cloud?: boolean;
}> {
try {
const { isAws, isAzure, isGcp } = await getCloudInfo(host);

const public_cloud_name = isAws
? 'AWS'
: isAzure
? 'Azure'
: isGcp
? 'GCP'
: undefined;

if (public_cloud_name === undefined) {
return { is_public_cloud: false };
}

return {
is_public_cloud: true,
public_cloud_name,
};
} catch (err) {
debug('getCloudInfo failed', err);

return {};
}
}

async function getHostInformation(
host: string | null
): Promise<HostInformation> {
Expand Down Expand Up @@ -47,36 +77,14 @@ async function getHostInformation(
};
}

const { isAws, isAzure, isGcp } = await getCloudInfo(host).catch(
(err: Error) => {
debug('getCloudInfo failed', err);
return {};
}
);
const isPublicCloud = isAws || isAzure || isGcp;
const publicCloudName = isAws
? 'AWS'
: isAzure
? 'Azure'
: isGcp
? 'GCP'
: undefined;

const result: HostInformation = {
const publicCloudInfo = await getPublicCloudInfo(host);

return {
is_localhost: false,
is_do_url: false,
is_atlas_url: isAtlas(host),
...publicCloudInfo,
};

if (typeof isPublicCloud !== 'undefined') {
result.is_public_cloud = isPublicCloud;
}

if (typeof publicCloudName !== 'undefined') {
result.public_cloud_name = publicCloudName;
}

return result;
}

function getCsfleInformation(
Expand Down
1 change: 0 additions & 1 deletion packages/compass-connections/src/typings.d.ts

This file was deleted.

0 comments on commit 669658f

Please sign in to comment.