From 9b75277e1dbcbc8b7f43b16b183748fc858d2f64 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Thu, 7 Sep 2023 15:26:11 +0200 Subject: [PATCH 1/3] refactor: read version from package.json and used source and out dirs --- .gitignore | 3 ++- package.json | 5 ++--- src/lib/version.ts | 4 +++- tsconfig.json | 3 ++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index ab12063..a70c47e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ dist/ .vscode/ .DS_Store -manifest.json \ No newline at end of file +manifest.json +*.sig \ No newline at end of file diff --git a/package.json b/package.json index f50a07c..127d575 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,14 @@ { "name": "@golem-sdk/cli", - "version": "0.1.0", + "version": "1.0.0", "description": "CLI for Golem SDK", - "main": "dist/main.js", "repository": { "type": "github", "url": "github:GolemFactory/golem-sdk-cli" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "build": "tsc", + "build": "tsc --build", "watch": "tsc --watch", "lint": "npm run lint:ts && npm run lint:eslint", "lint:ts": "tsc --project tsconfig.json --noEmit", diff --git a/src/lib/version.ts b/src/lib/version.ts index 094c1c8..4108d63 100644 --- a/src/lib/version.ts +++ b/src/lib/version.ts @@ -1,3 +1,5 @@ -import * as json from "../../package.json"; +import * as fs from "fs"; + +const json = JSON.parse(fs.readFileSync(__dirname + "/../../package.json").toString()); export const version = json.version; diff --git a/tsconfig.json b/tsconfig.json index 4076629..31c13dc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,8 @@ } }, "compilerOptions": { - "outDir": "dist", + "outDir": "dist/", + "rootDir": "src/", "experimentalDecorators": true, "resolveJsonModule": true, "moduleResolution": "node16" From e9d51b1c0fd50edfdc23954675afe715c7be28e4 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Thu, 7 Sep 2023 16:01:02 +0200 Subject: [PATCH 2/3] refactor: be more verbose about actions and look for the last index of a certificate --- src/manifest/manifest-create.action.ts | 2 ++ src/manifest/manifest-sign.action.ts | 2 ++ src/manifest/manifest-verify.action.ts | 15 +++++++-------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/manifest/manifest-create.action.ts b/src/manifest/manifest-create.action.ts index fa9910d..b5d0630 100644 --- a/src/manifest/manifest-create.action.ts +++ b/src/manifest/manifest-create.action.ts @@ -143,4 +143,6 @@ export async function manifestCreateAction(name: string, image: string, options: if (!imageData.hash) { console.log("Warning: Image hash is not specified. You won't be able to start an activity before you fill it out."); } + + console.log("Created manifest in %s file", options.manifest); } diff --git a/src/manifest/manifest-sign.action.ts b/src/manifest/manifest-sign.action.ts index 2825551..54b79d1 100644 --- a/src/manifest/manifest-sign.action.ts +++ b/src/manifest/manifest-sign.action.ts @@ -24,4 +24,6 @@ export async function manifestSignAction(options: ManifestSignOptions): Promise< // write signature to options.signatureFile. await writeFile(options.signatureFile, Buffer.from(signature).toString("base64"), "ascii"); + + console.log("Signed the manifest file and stored the signature in %s", options.signatureFile); } diff --git a/src/manifest/manifest-verify.action.ts b/src/manifest/manifest-verify.action.ts index 68f2219..abbb748 100644 --- a/src/manifest/manifest-verify.action.ts +++ b/src/manifest/manifest-verify.action.ts @@ -18,7 +18,13 @@ export async function manifestVerifyAction(options: ManifestVerifyOptions) { // FIXME: Find better way to get the second (or last?) certificate. const certInput = certFile.toString(); - const i = certInput.indexOf("-----BEGIN CERTIFICATE-----", 2); + const i = certInput.lastIndexOf("-----BEGIN CERTIFICATE-----"); + + if (i === -1) { + console.error("Could not locate the certificate to use for validation. Certificate file contents:", certFile.toString()); + process.exit(1); + } + const certSecond = certInput.substring(i); // const cert = new X509Certificate(certFile); @@ -33,12 +39,5 @@ export async function manifestVerifyAction(options: ManifestVerifyOptions) { } // TODO: Check if the certificate is not expired. - console.log("Manifest matches signature."); - /* - console.log('Certificate:', cert.publicKey.export({ - format: 'pem', - type: 'pkcs1', - })); -*/ } From bc6cba1251220d6cb3e185d3781ef39300c41401 Mon Sep 17 00:00:00 2001 From: Grzegorz Godlewski Date: Fri, 8 Sep 2023 09:12:05 +0200 Subject: [PATCH 3/3] chore: fixed formatting and introduced a pre-commit format check --- package-lock.json | 4 ++-- src/manifest/manifest-verify.action.ts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3d52592..4fdcbb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@golem-sdk/cli", - "version": "0.1.0", + "version": "1.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@golem-sdk/cli", - "version": "0.1.0", + "version": "1.0.0", "license": "LGPL-3.0", "dependencies": { "@golem-sdk/golem-js": "^0.10.1", diff --git a/src/manifest/manifest-verify.action.ts b/src/manifest/manifest-verify.action.ts index abbb748..62b921b 100644 --- a/src/manifest/manifest-verify.action.ts +++ b/src/manifest/manifest-verify.action.ts @@ -21,7 +21,10 @@ export async function manifestVerifyAction(options: ManifestVerifyOptions) { const i = certInput.lastIndexOf("-----BEGIN CERTIFICATE-----"); if (i === -1) { - console.error("Could not locate the certificate to use for validation. Certificate file contents:", certFile.toString()); + console.error( + "Could not locate the certificate to use for validation. Certificate file contents:", + certFile.toString(), + ); process.exit(1); }