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

feat: add methods for listing config profiles #1119

Merged
merged 5 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
6 changes: 2 additions & 4 deletions 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 @@ -104,12 +105,9 @@
"devDependencies": {
"aegir": "^20.3.1",
"browser-process-platform": "~0.1.1",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"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#30118c715d95582eaf65fdf8cb0ee240c504cb1e",
"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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just pass an object { 'stream-channels': true } ky will do the rest, no need to manually instantiate URLSearchParams

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I just copy/pasted that from ipfs.add..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, you can only set strings or numbers as values if you use a plain object (e.g. no booleans), otherwise you get:

Error: The `searchParams` option must be either a string, `URLSearchParams` instance or an object with string and number values

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like they're going to fix this in [email protected]

})

const parsed = await res.json()

return parsed
.map(profile => toCamel(profile))
})
})
7 changes: 1 addition & 6 deletions test/commands.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const ipfsClient = require('../src')

const f = require('./utils/factory')

describe('.commands', function () {
Expand Down
6 changes: 1 addition & 5 deletions test/constructor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
'use strict'

const multiaddr = require('multiaddr')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const f = require('./utils/factory')
const ipfsClient = require('../src/index.js')

Expand Down
6 changes: 1 addition & 5 deletions test/custom-headers.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
'use strict'

const isNode = require('detect-node')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const ipfsClient = require('../src')
const f = require('./utils/factory')

Expand Down
7 changes: 1 addition & 6 deletions test/dag.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@

'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const chaiAsPromised = require('chai-as-promised')
const expect = chai.expect
chai.use(dirtyChai)
chai.use(chaiAsPromised)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const { DAGNode } = require('ipld-dag-pb')
const CID = require('cids')
const ipfsClient = require('../src')
Expand Down
6 changes: 1 addition & 5 deletions test/diag.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const platform = require('browser-process-platform')

const ipfsClient = require('../src')
const f = require('./utils/factory')

Expand Down
6 changes: 1 addition & 5 deletions test/endpoint-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const isNode = require('detect-node')

const ipfsClient = require('../src')
const f = require('./utils/factory')

Expand Down
5 changes: 1 addition & 4 deletions test/exports.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ const multicodec = require('multicodec')
const multihash = require('multihashes')
const PeerId = require('peer-id')
const PeerInfo = require('peer-info')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('interface-ipfs-core/src/utils/mocha')

const IpfsHttpClient = require('../')

Expand Down
7 changes: 1 addition & 6 deletions test/files-mfs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const chaiAsPromised = require('chai-as-promised')
const expect = chai.expect
chai.use(dirtyChai)
chai.use(chaiAsPromised)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const loadFixture = require('aegir/fixtures')
const mh = require('multihashes')
const CID = require('cids')
Expand Down
7 changes: 1 addition & 6 deletions test/get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@

'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const chaiAsPromised = require('chai-as-promised')
const expect = chai.expect
chai.use(dirtyChai)
chai.use(chaiAsPromised)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const loadFixture = require('aegir/fixtures')

const ipfsClient = require('../src')
Expand Down
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
6 changes: 1 addition & 5 deletions test/key.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const ipfsClient = require('../src')
const f = require('./utils/factory')

Expand Down
6 changes: 1 addition & 5 deletions test/lib.configure.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
/* eslint-env mocha, browser */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const Multiaddr = require('multiaddr')
const { isBrowser, isWebWorker } = require('ipfs-utils/src/env')

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

describe('lib/configure', () => {
Expand Down
5 changes: 1 addition & 4 deletions test/lib.error-handler.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const { HTTPError } = require('ky-universal')
const expect = chai.expect
chai.use(dirtyChai)
const throwsAsync = require('./utils/throws-async')
const errorHandler = require('../src/lib/error-handler')

Expand Down
5 changes: 1 addition & 4 deletions test/lib.stream-to-iterable.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const toIterable = require('../src/lib/stream-to-iterable')

describe('lib/stream-to-iterable', () => {
Expand Down
6 changes: 1 addition & 5 deletions test/log.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
/* eslint max-nested-callbacks: ["error", 8] */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const ipfsClient = require('../src')
const f = require('./utils/factory')

Expand Down
8 changes: 1 addition & 7 deletions test/node/swarm.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
/* eslint-env mocha */
'use strict'

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const nock = require('nock')
const chai = require('chai')
const dirtyChai = require('dirty-chai')
const chaiAsPromised = require('chai-as-promised')
const expect = chai.expect
chai.use(dirtyChai)
chai.use(chaiAsPromised)

const ipfsClient = require('../../src')

describe('.swarm.peers', function () {
Expand Down
7 changes: 1 addition & 6 deletions test/ping.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const chaiAsPromised = require('chai-as-promised')
const expect = chai.expect
chai.use(dirtyChai)
chai.use(chaiAsPromised)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const pull = require('pull-stream/pull')
const collect = require('pull-stream/sinks/collect')

Expand Down
6 changes: 1 addition & 5 deletions test/repo.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const ipfsClient = require('../src')
const f = require('./utils/factory')

Expand Down
5 changes: 1 addition & 4 deletions test/request-api.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)
const { expect } = require('interface-ipfs-core/src/utils/mocha')
const isNode = require('detect-node')
const ipfsClient = require('../src/index.js')
const ndjson = require('ndjson')
Expand Down
6 changes: 1 addition & 5 deletions test/stats.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const ipfsClient = require('../src')
const f = require('./utils/factory')

Expand Down
10 changes: 4 additions & 6 deletions test/sub-modules.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/* eslint-env mocha */
'use strict'

const chai = require('chai')
const dirtyChai = require('dirty-chai')
const expect = chai.expect
chai.use(dirtyChai)

const { expect } = require('interface-ipfs-core/src/utils/mocha')
const defaultConfig = require('../src/utils/default-config.js')
const config = defaultConfig()
config.host = 'test'
Expand Down Expand Up @@ -42,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