Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
feat: add config profile endpoint (#1030)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
dirkmc authored and alanshaw committed Sep 4, 2019
1 parent eb31b6c commit 3aaa3ee
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/config/index.js
Expand Up @@ -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)
}
}
41 changes: 41 additions & 0 deletions 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
}
5 changes: 0 additions & 5 deletions test/interface.spec.js
Expand Up @@ -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'
}
]
})
Expand Down
1 change: 1 addition & 0 deletions test/sub-modules.spec.js
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 3aaa3ee

Please sign in to comment.