-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (43 loc) · 1.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Updater } from 'tuf-js';
import fs from 'fs';
import path from 'path';
const target = 'ctfe.pub';
const metadataBaseUrl = 'https://sigstore-tuf-root.storage.googleapis.com';
const metadataDir = './metadata';
const targetDir = './targets';
const targetBaseUrl =
'https://sigstore-tuf-root.storage.googleapis.com/targets';
function initDir() {
if (!fs.existsSync(metadataDir)) {
fs.mkdirSync(metadataDir);
}
if (!fs.existsSync(path.join(metadataDir, 'root.json'))) {
fs.copyFileSync('./1.root.json', path.join(metadataDir, 'root.json'));
}
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
}
}
async function downloadTarget() {
const updater = new Updater({
metadataBaseUrl,
metadataDir,
targetDir,
targetBaseUrl,
});
await updater.refresh();
const targetInfo = await updater.getTargetInfo(target);
if (!targetInfo) {
console.log(`Target ${target} doesn't exist`);
return;
}
const targetPath = await updater.findCachedTarget(targetInfo);
if (targetPath) {
console.log(`Target ${target} is cached at ${targetPath}`);
return;
}
const targetFile = await updater.downloadTarget(targetInfo);
console.log(`Target ${target} downloaded to ${targetFile}`);
}
initDir();
downloadTarget();