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

Commit

Permalink
Merge pull request #1119 from ipfs/add-listing-config-profiles
Browse files Browse the repository at this point in the history
feat: add methods for listing config profiles
  • Loading branch information
achingbrain committed Oct 4, 2019
2 parents aca704b + 08561d0 commit 333c575
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 49 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 @@ -106,7 +107,7 @@
"browser-process-platform": "~0.1.1",
"cross-env": "^6.0.0",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "^0.115.3",
"interface-ipfs-core": "^0.117.0",
"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')(config),
list: require('./profiles/list')(config)
}
}
}
41 changes: 0 additions & 41 deletions src/config/profile.js

This file was deleted.

27 changes: 27 additions & 0 deletions src/config/profiles/apply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

const callbackify = require('callbackify')
const configure = require('../../lib/configure')

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

const res = await ky.post('config/profile/apply', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
searchParams: {
arg: profile,
// can only pass strings or numbers as values https://github.com/sindresorhus/ky/issues/182
'dry-run': options.dryRun ? 'true' : 'false'
}
})

const parsed = await res.json()

return {
original: parsed.OldCfg, updated: parsed.NewCfg
}
})
})
22 changes: 22 additions & 0 deletions src/config/profiles/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

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

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

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

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
4 changes: 3 additions & 1 deletion test/sub-modules.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ 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')
expect(cfg).to.have.a.property('profiles')
expect(cfg.profiles.list).to.be.a('function')
expect(cfg.profiles.apply).to.be.a('function')
})

it('dht', () => {
Expand Down

0 comments on commit 333c575

Please sign in to comment.