-
Notifications
You must be signed in to change notification settings - Fork 92
/
keys.js
104 lines (93 loc) · 3.19 KB
/
keys.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
module.exports = ({ commandProcessor, root }) => {
const keys = commandProcessor.createCategory(root, 'keys', "Manage your device's key pair and server public key");
const protocolOption = {
'protocol': {
description: 'Communication protocol for the device using the key. tcp or udp'
}
};
commandProcessor.createCommand(keys, 'new', 'Generate a new set of keys for your device', {
params: '[filename]',
options: protocolOption,
handler: (args) => {
const KeysCommand = require('../cmd/keys');
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);
}
});
commandProcessor.createCommand(keys, 'save', 'Save a key from your device to a file', {
params: '<filename>',
options: {
'force': {
boolean: true,
default: false,
description: 'Force overwriting of <filename> if it exists',
}
},
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().saveKeyFromDevice(args);
}
});
commandProcessor.createCommand(keys, 'send', "Tell a server which key you'd like to use by sending your public key in PEM format", {
params: '<deviceID> <filename>',
options: {
'product_id': {
number: true,
description: 'The product ID to use when provisioning a new device'
}
},
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().sendPublicKeyToServer(args);
}
});
commandProcessor.createCommand(keys, 'doctor', 'Creates and assigns a new key to your device, and uploads it to the cloud', {
params: '<deviceID>',
options: protocolOption,
handler: (args) => {
const KeysCommand = require('../cmd/keys');
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] [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);
}
});
commandProcessor.createCommand(keys, 'address', 'Read server configured in device server public key', {
options: protocolOption,
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().readServerAddress(args);
}
});
commandProcessor.createCommand(keys, 'protocol', 'Retrieve or change transport protocol the device uses to communicate with the cloud', {
options: protocolOption,
handler: (args) => {
const KeysCommand = require('../cmd/keys');
return new KeysCommand().transportProtocol(args);
}
});
return keys;
};