Skip to content

Commit

Permalink
Merge pull request #556 from particle-iot/ch48657/add-option-to-serve…
Browse files Browse the repository at this point in the history
…r-keys-command-that-creates

Add option to server keys command that creates formatted key files without a device being connected
  • Loading branch information
JamesHagerman committed Apr 23, 2020
2 parents 915f933 + 4373224 commit 8e5201e
Show file tree
Hide file tree
Showing 9 changed files with 832 additions and 293 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: node_js
sudo: false

node_js:
- 8
- 10
- 12
- node

os:
- osx
Expand All @@ -19,9 +19,13 @@ before_install:

script:
- npm run test:ci

after_success:
- npm run coverage

jobs:
allow_failures:
- node_js: node
include:
- stage: npm release
script: echo "Deploying to npm..."
Expand Down
21 changes: 10 additions & 11 deletions src/app/command-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,16 +704,6 @@ function unknownParametersError(params){
);
}

const errors = {
unknownCommandError,
unknownArgumentError,
requiredParameterError,
variadicParameterRequiredError,
variadicParameterPositionError,
requiredParameterPositionError,
unknownParametersError
};

function showHelp(cb){
Yargs.showHelp(cb);
}
Expand All @@ -725,7 +715,16 @@ module.exports = {
createAppCategory,
createErrorHandler,
showHelp,
errors,
errors: {
usageError,
unknownCommandError,
unknownArgumentError,
requiredParameterError,
variadicParameterRequiredError,
variadicParameterPositionError,
requiredParameterPositionError,
unknownParametersError
},
test: {
consoleErrorLogger
}
Expand Down
17 changes: 10 additions & 7 deletions src/cli/keys.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ module.exports = ({ commandProcessor, root }) => {
options: protocolOption,
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().makeNewKey(args.params.filename, args);
return new KeysCommand().makeNewKey(args);
}
});

commandProcessor.createCommand(keys, 'load', 'Load a key saved in a file onto your device', {
params: '<filename>',
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().writeKeyToDevice(args.params.filename);
return new KeysCommand().writeKeyToDevice(args);
}
});

Expand All @@ -35,7 +35,7 @@ module.exports = ({ commandProcessor, root }) => {
},
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().saveKeyFromDevice(args.params.filename, args);
return new KeysCommand().saveKeyFromDevice(args);
}
});

Expand All @@ -49,7 +49,7 @@ module.exports = ({ commandProcessor, root }) => {
},
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().sendPublicKeyToServer(args.params.deviceID, args.params.filename, args);
return new KeysCommand().sendPublicKeyToServer(args);
}
});

Expand All @@ -58,25 +58,28 @@ module.exports = ({ commandProcessor, root }) => {
options: protocolOption,
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().keyDoctor(args.params.deviceID, args);
return new KeysCommand().keyDoctor(args);
}
});

commandProcessor.createCommand(keys, 'server', 'Switch server public keys.', {
epilogue: 'Defaults to the Particle public cloud or you can provide another key in DER format and the server hostname or IP and port',
params: '[filename]',
params: '[filename] [outputFilename]',
options: Object.assign({}, protocolOption, {
'host': {
description: 'Hostname or IP address of the server to add to the key'
},
'port': {
number: true,
description: 'Port number of the server to add to the key'
},
'deviceType': {
description: 'Generate key file for the provided device type'
}
}),
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().writeServerPublicKey(args.params.filename, args);
return new KeysCommand().writeServerPublicKey(args);
}
});

Expand Down
Loading

0 comments on commit 8e5201e

Please sign in to comment.