From a0c88dd0f5c89907effca9c279d4a8e50d3f4468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=AD=E5=B3=B6=20=E6=8B=93=E5=93=89?= Date: Wed, 21 Feb 2024 15:54:50 +0900 Subject: [PATCH] Bump v0.0.4 --- README.md | 2 ++ lib/credential.js | 18 ++++++++++++++++-- package.json | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2f1e377..3dbfba1 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ The following file is generated when this command is executed. Be careful not to publish the generated config/master.key in git. +The key used for encryption/decryption is the `config/master.key` generated here, or if not available, the `$MASTER_KEY` environment variable. + ## edit ```sh diff --git a/lib/credential.js b/lib/credential.js index d06a91c..52326a9 100644 --- a/lib/credential.js +++ b/lib/credential.js @@ -27,7 +27,16 @@ class Credential { } get masterKeyAndIv() { - return process.env.MASTER_KEY || fs.readFileSync(this.masterKeyFile, 'utf-8'); + try { + return fs.readFileSync(this.masterKeyFile, 'utf-8') + } catch(err) { + if (process.env.MASTER_KEY) { + return process.env.MASTER_KEY; + } + + log.error(`config/masterkey (or $MASTER_KEY) is not found`); + throw err; + } } get masterKeyFile() { @@ -105,7 +114,12 @@ class Credential { } reset() { - let body = this.read(); + try { + let body = this.read(); + } catch(err) { + log.error('The current master.key is not present, so the contents cannot be retained. If you still wish, try the setup command.'); + throw err; + } this.constructor.createMasterKey(this.configDir); this.write(body); } diff --git a/package.json b/package.json index 32a67c0..4d145d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@lifull/sesame-keeper", - "version": "0.0.3", + "version": "0.0.4", "description": "rails-like credential management mechanism.", "keywords": [ "credentials",