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

Commit 333c575

Browse files
authored
Merge pull request #1119 from ipfs/add-listing-config-profiles
feat: add methods for listing config profiles
2 parents aca704b + 08561d0 commit 333c575

File tree

7 files changed

+63
-49
lines changed

7 files changed

+63
-49
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"bl": "^3.0.0",
4949
"bs58": "^4.0.1",
5050
"buffer": "^5.4.2",
51+
"callbackify": "^1.1.0",
5152
"cids": "~0.7.1",
5253
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
5354
"debug": "^4.1.0",
@@ -106,7 +107,7 @@
106107
"browser-process-platform": "~0.1.1",
107108
"cross-env": "^6.0.0",
108109
"go-ipfs-dep": "^0.4.22",
109-
"interface-ipfs-core": "^0.115.3",
110+
"interface-ipfs-core": "^0.117.0",
110111
"ipfsd-ctl": "^0.47.1",
111112
"nock": "^11.3.2",
112113
"stream-equal": "^1.1.1"

src/config/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
'use strict'
22

3-
const moduleConfig = require('../utils/module-config')
4-
5-
module.exports = (arg) => {
6-
const send = moduleConfig(arg)
7-
3+
module.exports = (send, config) => {
84
return {
95
get: require('./get')(send),
106
set: require('./set')(send),
117
replace: require('./replace')(send),
12-
profile: require('./profile')(send)
8+
profiles: {
9+
apply: require('./profiles/apply')(config),
10+
list: require('./profiles/list')(config)
11+
}
1312
}
1413
}

src/config/profile.js

-41
This file was deleted.

src/config/profiles/apply.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict'
2+
3+
const callbackify = require('callbackify')
4+
const configure = require('../../lib/configure')
5+
6+
module.exports = configure(({ ky }) => {
7+
return callbackify.variadic(async (profile, options) => {
8+
options = options || {}
9+
10+
const res = await ky.post('config/profile/apply', {
11+
timeout: options.timeout,
12+
signal: options.signal,
13+
headers: options.headers,
14+
searchParams: {
15+
arg: profile,
16+
// can only pass strings or numbers as values https://github.com/sindresorhus/ky/issues/182
17+
'dry-run': options.dryRun ? 'true' : 'false'
18+
}
19+
})
20+
21+
const parsed = await res.json()
22+
23+
return {
24+
original: parsed.OldCfg, updated: parsed.NewCfg
25+
}
26+
})
27+
})

src/config/profiles/list.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const callbackify = require('callbackify')
4+
const configure = require('../../lib/configure')
5+
const toCamel = require('../../lib/object-to-camel')
6+
7+
module.exports = configure(({ ky }) => {
8+
return callbackify.variadic(async (options) => {
9+
options = options || {}
10+
11+
const res = await ky.get('config/profile/list', {
12+
timeout: options.timeout,
13+
signal: options.signal,
14+
headers: options.headers
15+
})
16+
17+
const parsed = await res.json()
18+
19+
return parsed
20+
.map(profile => toCamel(profile))
21+
})
22+
})

test/interface.spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ describe('interface-ipfs-core tests', () => {
4848
{
4949
name: 'replace',
5050
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'
51+
},
52+
{
53+
name: 'should list config profiles',
54+
reason: 'TODO: Not implemented in go-ipfs'
5155
}
5256
]
5357
})

test/sub-modules.spec.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ describe('submodules', () => {
3838
expect(cfg.get).to.be.a('function')
3939
expect(cfg.set).to.be.a('function')
4040
expect(cfg.replace).to.be.a('function')
41-
expect(cfg.profile).to.be.a('function')
41+
expect(cfg).to.have.a.property('profiles')
42+
expect(cfg.profiles.list).to.be.a('function')
43+
expect(cfg.profiles.apply).to.be.a('function')
4244
})
4345

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

0 commit comments

Comments
 (0)