Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mcclient get/add/remove commands for manifests
- Loading branch information
1 parent
0ce123e
commit 7464300
Showing
8 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @flow | ||
|
||
const path = require('path') | ||
|
||
module.exports = { | ||
command: 'manifest <subcommand>', | ||
describe: 'Commands for setting and retrieving identity manifests. Use "manifest --help" to see subcommands.\n', | ||
builder: (yargs: Function) => { | ||
return yargs | ||
.commandDir(path.join(__dirname, './manifest')) | ||
.help() | ||
.strict() | ||
}, | ||
handler: () => {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// @flow | ||
|
||
const fs = require('fs') | ||
const _ = require('lodash') | ||
const RestClient = require('../../../api/RestClient') | ||
const { subcommand, println } = require('../../util') | ||
const { consumeStream } = require('../../../../common/util') | ||
|
||
module.exports = { | ||
command: 'add [filename]', | ||
description: 'Add a signed manifest to the local node. ' + | ||
'If `filename` is not given, will read from standard input.\n', | ||
handler: subcommand((opts: {client: RestClient, filename?: string}) => { | ||
const {client, filename} = opts | ||
let streamName = 'standard input' | ||
let inputStream = process.stdin | ||
if (filename != null) { | ||
streamName = filename | ||
inputStream = fs.createReadStream(filename) | ||
} | ||
|
||
let manifest: Object | ||
|
||
return consumeStream(inputStream) | ||
.catch(err => { | ||
throw new Error(`Error reading from ${streamName}: ${err.message}`) | ||
}) | ||
.then(contents => { | ||
manifest = JSON.parse(contents) | ||
}) | ||
.then(() => client.getManifests()) | ||
.then(manifests => { | ||
if (_.some(manifests, m => _.isEqual(m, manifest))) { | ||
println('Node already contains manifest, ignoring') | ||
return | ||
} | ||
manifests.push(manifest) | ||
return client.setManifests(...manifests) | ||
.then(() => { | ||
println('Manifest added successfully') | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @flow | ||
|
||
const RestClient = require('../../../api/RestClient') | ||
const { subcommand, printJSON } = require('../../util') | ||
|
||
module.exports = { | ||
command: 'get [remotePeer]', | ||
description: `Get the signed manifests for the local node or a remote peer.\n`, | ||
handler: subcommand((opts: {client: RestClient, remotePeer?: string}) => { | ||
const {client, remotePeer} = opts | ||
return client.getManifests(remotePeer) | ||
.then(m => printJSON(m)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// @flow | ||
|
||
const RestClient = require('../../../api/RestClient') | ||
const { subcommand, println } = require('../../util') | ||
|
||
module.exports = { | ||
command: 'node', | ||
description: `Get the "node manifest" for the local node, suitable for signing by mcid to produce a manifest.\n`, | ||
handler: subcommand((opts: {client: RestClient}) => { | ||
const {client} = opts | ||
return client.getNodeManifest() | ||
.then(m => println(m)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// @flow | ||
|
||
const fs = require('fs') | ||
const _ = require('lodash') | ||
const RestClient = require('../../../api/RestClient') | ||
const { subcommand, println } = require('../../util') | ||
const { consumeStream } = require('../../../../common/util') | ||
|
||
module.exports = { | ||
command: 'remove [filename]', | ||
description: 'Remove a signed manifest from the local node. ' + | ||
'If `filename` is not given, will read from standard input.\n', | ||
handler: subcommand((opts: {client: RestClient, filename?: string}) => { | ||
const {client, filename} = opts | ||
let streamName = 'standard input' | ||
let inputStream = process.stdin | ||
if (filename != null) { | ||
streamName = filename | ||
inputStream = fs.createReadStream(filename) | ||
} | ||
|
||
let manifest: Object | ||
|
||
return consumeStream(inputStream) | ||
.catch(err => { | ||
throw new Error(`Error reading from ${streamName}: ${err.message}`) | ||
}) | ||
.then(contents => { | ||
manifest = JSON.parse(contents) | ||
}) | ||
.then(() => client.getManifests()) | ||
.then(manifests => { | ||
const without = _.filter(manifests, m => !_.isEqual(m, manifest)) | ||
if (without.length === manifests.length) { | ||
println('Node does not contain manifest, ignoring') | ||
return | ||
} | ||
return client.setManifests(...without) | ||
.then(() => { | ||
println('Manifest removed successfully') | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters