diff --git a/src/cli/commands/key/gen.js b/src/cli/commands/key/gen.js index a3f108eeaa..20ab31a915 100644 --- a/src/cli/commands/key/gen.js +++ b/src/cli/commands/key/gen.js @@ -29,7 +29,7 @@ module.exports = { if (err) { throw err } - print(`generated ${key.id} ${key.name}`) + print(key.id) }) } } diff --git a/src/cli/commands/key/list.js b/src/cli/commands/key/list.js index d50db99697..205befda56 100644 --- a/src/cli/commands/key/list.js +++ b/src/cli/commands/key/list.js @@ -7,14 +7,25 @@ module.exports = { describe: 'List all local keys', - builder: {}, + builder: { + long: { + alias: 'l', + describe: 'Show extra information about keys', + default: false + } + }, handler (argv) { argv.ipfs.key.list((err, keys) => { if (err) { throw err } - keys.forEach((ki) => print(`${ki.id} ${ki.name}`)) + + if (argv.long) { + keys.forEach((ki) => print(`${ki.id} ${ki.name}`)) + } else { + keys.forEach((ki) => print(ki.name)) + } }) } } diff --git a/src/core/components/init.js b/src/core/components/init.js index eb91a09979..11ee38f61b 100644 --- a/src/core/components/init.js +++ b/src/core/components/init.js @@ -83,9 +83,9 @@ module.exports = function init (self) { PrivKey: peerId.privKey.bytes.toString('base64') } privateKey = peerId.privKey - if (opts.pass) { - config.Keychain = Keychain.generateOptions() - } + + config.Keychain = Keychain.generateOptions() + opts.log('done') opts.log('peer identity: ' + config.Identity.PeerID) @@ -94,14 +94,10 @@ module.exports = function init (self) { (_, cb) => self._repo.open(cb), (cb) => { self.log('repo opened') - if (opts.pass) { - self.log('creating keychain') - const keychainOptions = Object.assign({passPhrase: opts.pass}, config.Keychain) - self._keychain = new Keychain(self._repo.keys, keychainOptions) - self._keychain.importPeer('self', { privKey: privateKey }, cb) - } else { - cb(null, true) - } + self.log('creating keychain') + const keychainOptions = Object.assign({passPhrase: opts.pass}, config.Keychain) + self._keychain = new Keychain(self._repo.keys, keychainOptions) + self._keychain.importPeer('self', { privKey: privateKey }, cb) }, // add empty unixfs dir object (go-ipfs assumes this exists) (_, cb) => { diff --git a/src/core/components/no-keychain.js b/src/core/components/no-keychain.js deleted file mode 100644 index 6f07f4068e..0000000000 --- a/src/core/components/no-keychain.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict' - -function fail () { - throw new Error('Key management requires \'--pass ...\' option') -} - -class NoKeychain { - static get options () { fail() } - static generateOptions () { fail() } - - createKey () { fail() } - listKeys () { fail() } - findKeyById () { fail() } - findKeyByName () { fail() } - renameKey () { fail() } - removeKey () { fail() } - exportKey () { fail() } - importKey () { fail() } - importPeer () { fail() } - - get cms () { fail() } -} - -module.exports = NoKeychain diff --git a/src/core/components/pre-start.js b/src/core/components/pre-start.js index ed30190a0a..766dd8505b 100644 --- a/src/core/components/pre-start.js +++ b/src/core/components/pre-start.js @@ -6,7 +6,6 @@ const multiaddr = require('multiaddr') const waterfall = require('async/waterfall') const Keychain = require('libp2p-keychain') const extend = require('deep-extend') -const NoKeychain = require('./no-keychain') /* * Load stuff from Repo into memory */ @@ -45,15 +44,10 @@ module.exports = function preStart (self) { }, (config, cb) => { // Construct the keychain - if (self._keychain) { - // most likely an init or upgrade has happened - } else if (pass) { + if (!self._keychain) { const keychainOptions = Object.assign({passPhrase: pass}, config.Keychain) self._keychain = new Keychain(self._repo.keys, keychainOptions) self.log('keychain constructed') - } else { - self._keychain = new NoKeychain() - self.log('no keychain, use --pass') } cb(null, config) }, diff --git a/test/cli/key.js b/test/cli/key.js index 8a39c4919c..b365905c0c 100644 --- a/test/cli/key.js +++ b/test/cli/key.js @@ -5,7 +5,7 @@ const expect = require('chai').expect const runOnAndOff = require('../utils/on-and-off') const hat = require('hat') -describe('key', () => runOnAndOff.off((thing) => { +describe.only('key', () => runOnAndOff.off((thing) => { const name = 'test-key-' + hat() const newName = 'test-key-' + hat() const pass = '--pass ' + hat() @@ -19,6 +19,7 @@ describe('key', () => runOnAndOff.off((thing) => { this.timeout(40 * 1000) return ipfs(`${pass} key gen ${name} --type rsa --size 2048`) + .then(() => ipfs(`${pass} key list -l`)) .then((out) => { expect(out).to.include(name) }) @@ -33,6 +34,15 @@ describe('key', () => runOnAndOff.off((thing) => { }) }) + it('list without password', function () { + this.timeout(20 * 1000) + + return ipfs(`key list`) + .then((out) => { + expect(out).to.include(name) + }) + }) + it('rename', function () { this.timeout(20 * 1000)