-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·73 lines (65 loc) · 2.61 KB
/
cli.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
#!/usr/bin/env node
'use strict';
const packageDetails = require('./package');
const program = require('commander');
const helper = require('./lib/helper');
process.title = packageDetails.name;
console.info(packageDetails.name, packageDetails.version);
console.info('');
program.version(packageDetails.version).description(packageDetails.description);
/**
* Command that decrypts SFCC credentials file
* @alias module:cli
* @param {String} decrypt The command name
*/
program.command('decrypt')
.description('decrypts intellij-sfcc-credentials.creds file')
.option('-s, --source <key>', 'Path to intellij-sfcc-credentials.creds file.')
.option('-t, --target <key>', 'Path to intellij-sfcc-credentials.json file.')
.option('-k, --key <key>', 'The secret key to decrypt the file.')
.option('-h, --host <key>', 'Optional. The host to retrieve access tokens for. Full name or just realm-instance (e.g.: abcd-001)')
.option('-u, --username <key>', 'Optional. The username to retrieve access tokens for.')
.action((options) => {
const { source, target, key, host, username } = options;
Promise.resolve().then(() => helper.decrypt(source, target, key, host, username))
.then(({ decryptedJson, hostKeys }) => {
if (hostKeys && Object.keys(hostKeys).length) {
console.info(`${JSON.stringify(hostKeys, null, 2)}`);
} else {
console.info(`${decryptedJson}`);
}
process.exit(0);
})
.catch(e => {
console.error(e);
process.exit(-1);
});
});
/**
* Command that encrypts and writes SFCC credentials file
* @alias module:cli
* @param {String} encrypt The command name
*/
program.command('encrypt')
.description('encrypts intellij-sfcc-credentials.creds file')
.option('-s, --source <key>', 'The SFCC json file.')
.option('-t, --target <key>', 'Path to intellij-sfcc-credentials.json file.')
.option('-k, --key <key>', 'The secret key to encrypt the file.')
.action((options) => {
const { source, target, key } = options;
Promise.resolve().then(() => helper.encrypt(source, target, key))
.then(({ encryptedText }) => {
console.info(`${encryptedText}`);
process.exit(0);
})
.catch(e => {
console.error(e);
process.exit(-1);
});
});
// parse CLI arguments
program.parse(process.argv);
// output help message if no arguments provided
if (!process.argv.slice(2).length) {
program.help();
}