diff --git a/src/config/index.js b/src/config/index.js index 109865ab0..d690d8099 100644 --- a/src/config/index.js +++ b/src/config/index.js @@ -8,6 +8,7 @@ module.exports = (arg) => { return { get: require('./get')(send), set: require('./set')(send), - replace: require('./replace')(send) + replace: require('./replace')(send), + profile: require('./profile')(send) } } diff --git a/src/config/profile.js b/src/config/profile.js new file mode 100644 index 000000000..809adb5d4 --- /dev/null +++ b/src/config/profile.js @@ -0,0 +1,41 @@ +'use strict' + +const promisify = require('promisify-es6') + +const toObject = function (res, callback) { + if (Buffer.isBuffer(res)) { + callback(null, JSON.parse(res.toString())) + } else { + callback(null, res) + } +} + +module.exports = (send) => { + return promisify((profile, opts, callback) => { + if (typeof opts === 'function') { + callback = opts + opts = {} + } + + opts = normalizeOpts(opts) + + send.andTransform({ + path: 'config/profile/apply', + args: profile, + qs: opts + }, toObject, (err, response) => { + if (err) { + return callback(err) + } + callback(null, { oldCfg: response.OldCfg, newCfg: response.NewCfg }) + }) + }) +} + +function normalizeOpts (opts) { + opts = opts || {} + if (typeof opts.dryRun !== 'undefined') { + opts['dry-run'] = opts.dryRun + } + return opts +} diff --git a/test/interface.spec.js b/test/interface.spec.js index 32c6f6749..c51fc7e39 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -49,11 +49,6 @@ describe('interface-ipfs-core tests', () => { { name: 'replace', reason: 'FIXME Waiting for fix on go-ipfs https://github.com/ipfs/js-ipfs-http-client/pull/307#discussion_r69281789 and https://github.com/ipfs/go-ipfs/issues/2927' - }, - // config.profile - { - name: 'profile', - reason: 'TODO not yet implemented https://github.com/ipfs/js-ipfs-http-client/pull/1030' } ] }) diff --git a/test/sub-modules.spec.js b/test/sub-modules.spec.js index cabd09b55..b066b6278 100644 --- a/test/sub-modules.spec.js +++ b/test/sub-modules.spec.js @@ -42,6 +42,7 @@ describe('submodules', () => { expect(cfg.get).to.be.a('function') expect(cfg.set).to.be.a('function') expect(cfg.replace).to.be.a('function') + expect(cfg.profile).to.be.a('function') }) it('dht', () => {