Skip to content

Commit c8fd5fe

Browse files
committed
chore: refoactor downstream to work with the new upstream version
1 parent 914397e commit c8fd5fe

9 files changed

Lines changed: 1139 additions & 632 deletions

File tree

packages/osv-offline-db/src/lib/db.int.spec.ts

Lines changed: 607 additions & 614 deletions
Large diffs are not rendered by default.

packages/osv-offline-db/src/lib/db.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,47 @@ export class OsvOfflineDb {
245245
}
246246
}
247247

248-
async query_containers(
249-
repository: string
250-
): Promise<Osv.Vulnerability[]> {
251-
return await this.db["Docker" as Ecosystem].findAsync({
252-
'affected.package.name': repository,
253-
'affected.package.ecosystem': 'Docker'
254-
});
248+
async query_containers(repository: string): Promise<Vulnerability[]> {
249+
if (this.disposed) {
250+
throw new Error('Database disposed');
251+
}
252+
const data = await this._load('Docker');
253+
254+
if (!data) {
255+
return [];
256+
}
257+
258+
const pointers = data.index.get(repository);
259+
260+
if (!pointers || pointers.length === 0) {
261+
return [];
262+
}
263+
264+
const advisories = await Promise.all(
265+
pointers.map(async ({ offset, length }) => {
266+
const buffer = Buffer.allocUnsafe(length);
267+
const { bytesRead } = await readAsync(
268+
data.fd,
269+
buffer,
270+
0,
271+
length,
272+
offset
273+
);
274+
return JSON.parse(
275+
buffer.toString('utf8', 0, bytesRead)
276+
) as Vulnerability;
277+
})
278+
);
279+
280+
if (this.disposed) return [];
281+
282+
return advisories.filter((vuln) =>
283+
vuln.affected?.some(
284+
(a) =>
285+
a.package?.name === repository &&
286+
(a.package.ecosystem === 'Docker' ||
287+
a.package.ecosystem.startsWith(`Docker:`))
288+
)
289+
);
255290
}
256291
}

packages/osv-offline-updater/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"start": "tsx ./src/index.ts"
1414
},
1515
"dependencies": {
16-
"@mintmaker/osv-offline-db": "0.0.0-semantic-release",
16+
"@mintmaker/osv-offline-db": "workspace:*",
1717
"@octokit/rest": "22.0.1",
1818
"adm-zip": "0.5.17",
1919
"fs-extra": "11.3.5",

packages/osv-offline-updater/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs-extra';
22
import { createWriteStream } from 'node:fs';
33
import { randomBytes } from 'node:crypto';
44
import { finished } from 'node:stream/promises';
5-
import { Osv, OsvOfflineDb, ecosystems } from '@mintmaker/osv-offline-db';
5+
import { OsvOfflineDb, ecosystems } from '@mintmaker/osv-offline-db';
66
import { GitHub } from './client/github.ts';
77
import signale from 'signale';
88
import { OsvDownloader } from './client/osv.ts';

packages/osv-offline/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"url": "https://github.com/redhat-exd-rebuilds/osv-offline.git"
1313
},
1414
"dependencies": {
15-
"@mintmaker/osv-offline-db": "0.0.0-semantic-release",
15+
"@mintmaker/osv-offline-db": "workspace:*",
1616
"adm-zip": "~0.5.17",
1717
"debug": "^4.4.3",
1818
"fs-extra": "^11.3.5",

packages/osv-offline/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { Osv, Ecosystem } from '@mintmaker/osv-offline-db';
2-
export { OsvOffline } from './lib/osv-offline';
2+
export { OsvOffline } from './lib/osv-offline.ts';

packages/osv-offline/src/lib/download.unit.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OsvOfflineDb } from '@renovatebot/osv-offline-db';
1+
import { OsvOfflineDb } from '@mintmaker/osv-offline-db';
22
import fs from 'fs-extra';
33
import path from 'path';
44
import { beforeEach, describe, expect, it, vi } from 'vitest';

packages/osv-offline/src/lib/osv-offline.int.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ describe('packages/osv-offline/src/lib/osv-offline.int', () => {
3434

3535
describe('getContainerVulnerabilities', () => {
3636
it('returns empty array for invalid package', async () => {
37-
const result = await osvOffline.getContainerVulnerabilities("quay.io/some/repo");
37+
const result =
38+
await osvOffline.getContainerVulnerabilities('quay.io/some/repo');
3839

39-
expect(result).toBeEmptyArray();
40+
expect(result).toEqual([]);
4041
});
4142
});
4243
});

0 commit comments

Comments
 (0)