@watchtowerobservability/cli 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/wtctl.js +12 -0
- package/install.js +24 -0
- package/lib.js +28 -0
- package/package.json +10 -4
- package/README.md +0 -3
package/bin/wtctl.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { spawnSync } = require('node:child_process');
|
|
5
|
+
|
|
6
|
+
const exe = path.join(__dirname, process.platform === 'win32' ? 'wtctl-bin.exe' : 'wtctl-bin');
|
|
7
|
+
const r = spawnSync(exe, process.argv.slice(2), { stdio: 'inherit' });
|
|
8
|
+
if (r.error) {
|
|
9
|
+
console.error(`wtctl: ${r.error.message}`);
|
|
10
|
+
process.exit(1);
|
|
11
|
+
}
|
|
12
|
+
process.exit(r.status ?? 1);
|
package/install.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { assetName, verify } = require('./lib');
|
|
5
|
+
|
|
6
|
+
async function get(url) {
|
|
7
|
+
const r = await fetch(url);
|
|
8
|
+
if (!r.ok) throw new Error(`${url}: ${r.status}`);
|
|
9
|
+
return Buffer.from(await r.arrayBuffer());
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
(async () => {
|
|
13
|
+
const name = assetName(process.platform, process.arch);
|
|
14
|
+
if (!name) throw new Error(`unsupported platform ${process.platform}/${process.arch}`);
|
|
15
|
+
const v = require('./package.json').version;
|
|
16
|
+
const base = `https://github.com/watchtowerobservability/watchtower-cli/releases/download/v${v}`;
|
|
17
|
+
const [bin, sums] = await Promise.all([get(`${base}/${name}`), get(`${base}/SHA256SUMS`)]);
|
|
18
|
+
verify(bin, sums.toString(), name);
|
|
19
|
+
const dest = path.join(__dirname, 'bin', process.platform === 'win32' ? 'wtctl-bin.exe' : 'wtctl-bin');
|
|
20
|
+
fs.writeFileSync(dest, bin, { mode: 0o755 });
|
|
21
|
+
})().catch((e) => {
|
|
22
|
+
console.error(`wtctl install failed: ${e.message}`);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
});
|
package/lib.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const crypto = require('node:crypto');
|
|
3
|
+
|
|
4
|
+
// Release asset name for a Node platform/arch, or null when unsupported.
|
|
5
|
+
function assetName(platform, arch) {
|
|
6
|
+
const os = { linux: 'linux', darwin: 'darwin', win32: 'windows' }[platform];
|
|
7
|
+
const cpu = { x64: 'amd64', arm64: 'arm64' }[arch];
|
|
8
|
+
if (!os || !cpu) return null;
|
|
9
|
+
return `wtctl_${os}_${cpu}${os === 'windows' ? '.exe' : ''}`;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// The SHA256 listed for name in a `sha256sum` style file, or null.
|
|
13
|
+
function expectedSum(sums, name) {
|
|
14
|
+
for (const line of sums.split('\n')) {
|
|
15
|
+
const [h, n] = line.trim().split(/\s+/);
|
|
16
|
+
if (n === name) return h;
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function verify(buf, sums, name) {
|
|
22
|
+
const want = expectedSum(sums, name);
|
|
23
|
+
if (!want) throw new Error(`no checksum for ${name}`);
|
|
24
|
+
const got = crypto.createHash('sha256').update(buf).digest('hex');
|
|
25
|
+
if (got !== want) throw new Error(`checksum mismatch for ${name}`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = { assetName, expectedSum, verify };
|
package/package.json
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@watchtowerobservability/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Watchtower command line client (downloads and verifies the release binary)",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": "github:watchtowerobservability/watchtower-cli",
|
|
7
|
+
"bin": { "wtctl": "bin/wtctl.js" },
|
|
8
|
+
"scripts": { "postinstall": "node install.js", "test": "node --test test.js" },
|
|
9
|
+
"files": ["bin", "install.js", "lib.js"],
|
|
10
|
+
"publishConfig": { "registry": "https://registry.npmjs.org/", "access": "public" },
|
|
11
|
+
"engines": { "node": ">=20" }
|
|
12
|
+
}
|
package/README.md
DELETED