Skip to content

Commit

Permalink
chore(compass): attach OS metadata to update URL COMPASS-7619 (#5443)
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson authored Feb 20, 2024
1 parent eef7264 commit 38afcff
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 12 additions & 0 deletions packages/compass/src/main/auto-update-manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ describe('CompassAutoUpdateManager', function () {
sandbox.stub(autoUpdater);
});

it('attaches OS metadata as query params to the update request URL', async () => {
const url = await CompassAutoUpdateManager.getUpdateCheckURL();

expect(url.searchParams.get('release')).to.exist;

const isLinux = process.platform === 'linux';
if (isLinux) {
expect(url.searchParams.get('os_linux_dist')).to.exist;
expect(url.searchParams.get('os_linux_release')).to.exist;
}
});

it('should check for update and transition to update not available if backend returned nothing', async function () {
const stub = sandbox
.stub(CompassAutoUpdateManager, 'checkForUpdate')
Expand Down
20 changes: 17 additions & 3 deletions packages/compass/src/main/auto-update-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import autoUpdater, { supportsAutoupdater } from './auto-updater';
import fetch from 'node-fetch';
import dl from 'electron-dl';
import type { CompassApplication } from './application';
import { getOsInfo } from '@mongodb-js/get-os-info';

const { log, mongoLogId, debug, track } = createLoggerAndTelemetry(
'COMPASS-AUTO-UPDATES'
Expand Down Expand Up @@ -447,11 +448,24 @@ class CompassAutoUpdateManager {
};
}

static getUpdateCheckURL() {
static async getUpdateCheckURL() {
const { endpoint, product, channel, platform, arch, version } =
this.autoUpdateOptions;
const {
os_release: release,
os_linux_dist,
os_linux_release,
} = await getOsInfo();
const url = new URL(
`${endpoint}/api/v2/update/${product}/${channel}/${platform}-${arch}/${version}/check`
);

release && url.searchParams.set('release', release);
os_linux_dist && url.searchParams.set('os_linux_dist', os_linux_dist);
os_linux_release &&
url.searchParams.set('os_linux_release', os_linux_release);

return `${endpoint}/api/v2/update/${product}/${channel}/${platform}-${arch}/${version}/check`;
return url;
}

static async checkForUpdate(): Promise<{
Expand All @@ -460,7 +474,7 @@ class CompassAutoUpdateManager {
to: string;
} | null> {
try {
const response = await fetch(this.getUpdateCheckURL());
const response = await fetch(await this.getUpdateCheckURL());
if (response.status !== 200) {
return null;
}
Expand Down

0 comments on commit 38afcff

Please sign in to comment.