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

Commit

Permalink
feat: add methods for listing config profiles
Browse files Browse the repository at this point in the history
New method:

```javascript
Promise<Array<{ name, description }>> ipfs.config.profiles.list()
```

BREAKING CHANGE:

```javascript
Promise<{oldCfg, newCfg}> ipfs.config.profile(name, opts)

// is now
Promise<{old, new}> ipfs.config.profiles.apply(name, opts)
```

Possibly contentious;

Adds `callbackify` as a dependency, see ipfs/js-ipfs#2506
for discussion.
  • Loading branch information
achingbrain committed Oct 3, 2019
1 parent 55e64d4 commit 1c3d92a
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"bl": "^3.0.0",
"bs58": "^4.0.1",
"buffer": "^5.4.2",
"callbackify": "^1.1.0",
"cids": "~0.7.1",
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
"debug": "^4.1.0",
Expand Down Expand Up @@ -109,7 +110,7 @@
"cross-env": "^6.0.0",
"dirty-chai": "^2.0.1",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "^0.115.0",
"interface-ipfs-core": "ipfs/interface-js-ipfs-core#add-listing-config-profiles",
"ipfsd-ctl": "^0.47.1",
"nock": "^11.3.2",
"stream-equal": "^1.1.1"
Expand Down
11 changes: 5 additions & 6 deletions src/config/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
'use strict'

const moduleConfig = require('../utils/module-config')

module.exports = (arg) => {
const send = moduleConfig(arg)

module.exports = (send, config) => {
return {
get: require('./get')(send),
set: require('./set')(send),
replace: require('./replace')(send),
profile: require('./profile')(send)
profiles: {
apply: require('./profiles/apply')(send),
list: require('./profiles/list')(config)
}
}
}
2 changes: 1 addition & 1 deletion src/config/profile.js → src/config/profiles/apply.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module.exports = (send) => {
if (err) {
return callback(err)
}
callback(null, { oldCfg: response.OldCfg, newCfg: response.NewCfg })
callback(null, { old: response.OldCfg, new: response.NewCfg })
})
})
}
Expand Down
26 changes: 26 additions & 0 deletions src/config/profiles/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const configure = require('../../lib/configure')
const callbackify = require('callbackify')
const toCamel = require('../../lib/object-to-camel')

module.exports = configure(({ ky }) => {
return callbackify.variadic(async (options) => {
options = options || {}

const searchParams = new URLSearchParams(options.searchParams)
searchParams.set('stream-channels', true)

const res = await ky.get('config/profile/list', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
searchParams
})

const parsed = await res.json()

return parsed
.map(profile => toCamel(profile))
})
})
4 changes: 4 additions & 0 deletions test/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ 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'
},
{
name: 'should list config profiles',
reason: 'TODO: Not implemented in go-ipfs'
}
]
})
Expand Down

0 comments on commit 1c3d92a

Please sign in to comment.