Skip to content

feat: migrate to read@v3 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/commands/hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/

var prompt = require("../prompt");
const prompt = require("../prompt");
try { bcrypt = require('bcrypt'); }
catch(e) { bcrypt = require('bcryptjs'); }

Expand All @@ -23,14 +22,16 @@ function command(argv,result) {
console.warn("hash-pw command does not support json format output");
}
return new Promise(resolve => {
prompt.read({prompt:"Password:",silent: true},function(err, password) {
if (password) {
result.log(bcrypt.hashSync(password, 8));
}
resolve();
});
prompt.read({prompt: "Password:", silent: true})
.then(password => {
if(password) {
result.log(bcrypt.hashSync(password, 8));
}
})
.finally(() => resolve());
});
}

command.alias = "hash-pw";
command.usage = command.alias;
command.description = "Creates a password hash suitable for use with adminAuth or httpNodeAuth";
Expand Down
6 changes: 3 additions & 3 deletions lib/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@

var request = require("../request");
var config = require("../config");
var prompt = require("../prompt");
const prompt = require("../prompt");

function command(argv,result) {
config.tokens(null);
return request.request('/auth/login',{}).then(function(resp) {
return new Promise((resolve,reject) => {
if (resp.type) {
if (resp.type == "credentials") {
prompt.read({prompt:"Username:"},function(err, username) {
prompt.read({prompt:"Password:",silent: true},function(err, password) {
prompt.read({prompt:"Username:"}).then(function(username) {
prompt.read({prompt:"Password:",silent: true}).then(function(password) {
request.request('/auth/token', {
method: "POST",
data: {
Expand Down
4 changes: 2 additions & 2 deletions lib/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
**/

var read = require("read");
const {read} = require("read")

// This exists purely to provide a place to hook in a unit test mock of the
// read module

module.exports = {
read: read
read: read,
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"main": "lib/index.js",
"engines": {
"node": ">=14"
"node": ">=14.17"
},
"contributors": [
{
Expand All @@ -35,7 +35,7 @@
"enquirer": "^2.3.6",
"minimist": "^1.2.8",
"mustache": "^4.2.0",
"read": "^1.0.7"
"read": "^3.0.1"
},
"devDependencies": {
"mocha": "^10.2.0",
Expand Down
14 changes: 7 additions & 7 deletions test/lib/commands/hash_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

var command = require("../../../lib/commands/hash");

var prompt = require("../../../lib/prompt");
const prompt = require("../../../lib/prompt");

var should = require("should");
var sinon = require("sinon");
Expand All @@ -34,8 +34,8 @@ describe("commands/hash-pw", function() {
prompt.read.restore();
});
it('generates a bcrypt hash of provided password',function(done) {
sinon.stub(prompt,"read").callsFake(function(opts,callback) {
callback(null,"a-test-password");
sinon.stub(prompt, "read").callsFake(function(opts) {
return Promise.resolve("a-test-password");
});

command({},result).then(function() {
Expand All @@ -48,8 +48,8 @@ describe("commands/hash-pw", function() {
});
});
it('ignores blank password',function(done) {
sinon.stub(prompt,"read").callsFake(function(opts,callback) {
callback(null,"");
sinon.stub(prompt, "read").callsFake(function(opts) {
return Promise.resolve("");
});

command({},result).then(function() {
Expand All @@ -58,8 +58,8 @@ describe("commands/hash-pw", function() {
});
});
it('ignores null password',function(done) {
sinon.stub(prompt,"read").callsFake(function(opts,callback) {
callback(null,null);
sinon.stub(prompt, "read").callsFake(function(opts) {
return Promise.resolve(null);
});

command({},result).then(function() {
Expand Down
6 changes: 3 additions & 3 deletions test/lib/commands/login_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ var result = require("./result_helper");
describe("commands/list", function() {
beforeEach(function() {
sinon.stub(config,"tokens").callsFake(function(token) {});
sinon.stub(prompt,"read").callsFake(function(opts,callback) {
sinon.stub(prompt, "read").callsFake(function(opts) {
if (/Username/.test(opts.prompt)) {
callback(null,"username");
return Promise.resolve("username");
} else if (/Password/.test(opts.prompt)) {
callback(null,"password");
return Promise.resolve("password");
}
});
});
Expand Down