-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
285 additions
and
4 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 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,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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// @flow | ||
|
||
const RestClient = require('../../../api/RestClient') | ||
const { subcommand, println } = require('../../util') | ||
|
||
module.exports = { | ||
command: 'self', | ||
description: `Get the unsigned "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,54 @@ | ||
// @flow | ||
|
||
const fs = require('fs') | ||
const RestClient = require('../../../api/RestClient') | ||
const { subcommand, println } = require('../../util') | ||
const { consumeStream } = require('../../../../common/util') | ||
|
||
module.exports = { | ||
command: 'set [filename]', | ||
description: `Set the signed manifests for the local node, replacing any existing manifests. ` + | ||
'If `filename is not given, will read from stdin`\n', | ||
builder: { | ||
ndjson: { | ||
type: 'boolean', | ||
description: 'If present, input should be newline-delimited json, one object per line. ' + | ||
'Otherwise, input can be either a single json object, or an array of objects.', | ||
default: 'false' | ||
} | ||
}, | ||
handler: subcommand((opts: {client: RestClient, filename?: string, ndjson: boolean}) => { | ||
const {client, filename, ndjson} = opts | ||
let streamName = 'standard input' | ||
let inputStream = process.stdin | ||
if (filename != null) { | ||
streamName = filename | ||
inputStream = fs.createReadStream(filename) | ||
} | ||
|
||
return consumeStream(inputStream) | ||
.catch(err => { | ||
throw new Error(`Error reading from ${streamName}: ${err.message}`) | ||
}) | ||
.then(contents => { | ||
let manifests = [] | ||
if (ndjson) { | ||
manifests = contents.split('\n') | ||
.filter(line => line && line.length > 0) | ||
.map(line => JSON.parse(line)) | ||
} else { | ||
const parsed = JSON.parse(contents) | ||
if (Array.isArray(parsed)) { | ||
manifests = parsed | ||
} else { | ||
manifests = [parsed] | ||
} | ||
} | ||
return manifests | ||
}) | ||
.then(manifests => client.setManifests(...manifests)) | ||
.then(() => { | ||
println('Manifests set 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
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 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,21 @@ | ||
syntax = "proto3"; | ||
package proto; | ||
|
||
message Manifest { | ||
string entity = 1; | ||
string keyId = 2; | ||
ManifestBody body = 3; | ||
int64 timestamp = 4; | ||
bytes signature = 5; | ||
} | ||
|
||
message ManifestBody { | ||
oneof body { | ||
NodeManifest node = 1; | ||
} | ||
} | ||
|
||
message NodeManifest { | ||
string peer = 1; | ||
string publisher = 2; | ||
} |
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