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

feat: add config profile endpoint #1030

Merged
merged 2 commits into from
Sep 4, 2019
Merged
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
3 changes: 2 additions & 1 deletion src/config/index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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