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

Commit 3aaa3ee

Browse files
dirkmcAlan Shaw
authored and
Alan Shaw
committed
feat: add config profile endpoint (#1030)
License: MIT Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
1 parent eb31b6c commit 3aaa3ee

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

src/config/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module.exports = (arg) => {
88
return {
99
get: require('./get')(send),
1010
set: require('./set')(send),
11-
replace: require('./replace')(send)
11+
replace: require('./replace')(send),
12+
profile: require('./profile')(send)
1213
}
1314
}

src/config/profile.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict'
2+
3+
const promisify = require('promisify-es6')
4+
5+
const toObject = function (res, callback) {
6+
if (Buffer.isBuffer(res)) {
7+
callback(null, JSON.parse(res.toString()))
8+
} else {
9+
callback(null, res)
10+
}
11+
}
12+
13+
module.exports = (send) => {
14+
return promisify((profile, opts, callback) => {
15+
if (typeof opts === 'function') {
16+
callback = opts
17+
opts = {}
18+
}
19+
20+
opts = normalizeOpts(opts)
21+
22+
send.andTransform({
23+
path: 'config/profile/apply',
24+
args: profile,
25+
qs: opts
26+
}, toObject, (err, response) => {
27+
if (err) {
28+
return callback(err)
29+
}
30+
callback(null, { oldCfg: response.OldCfg, newCfg: response.NewCfg })
31+
})
32+
})
33+
}
34+
35+
function normalizeOpts (opts) {
36+
opts = opts || {}
37+
if (typeof opts.dryRun !== 'undefined') {
38+
opts['dry-run'] = opts.dryRun
39+
}
40+
return opts
41+
}

test/interface.spec.js

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ describe('interface-ipfs-core tests', () => {
4949
{
5050
name: 'replace',
5151
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'
52-
},
53-
// config.profile
54-
{
55-
name: 'profile',
56-
reason: 'TODO not yet implemented https://github.com/ipfs/js-ipfs-http-client/pull/1030'
5752
}
5853
]
5954
})

test/sub-modules.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('submodules', () => {
4242
expect(cfg.get).to.be.a('function')
4343
expect(cfg.set).to.be.a('function')
4444
expect(cfg.replace).to.be.a('function')
45+
expect(cfg.profile).to.be.a('function')
4546
})
4647

4748
it('dht', () => {

0 commit comments

Comments
 (0)