-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-certs-cli.js
executable file
·46 lines (37 loc) · 1.1 KB
/
create-certs-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
#!/usr/bin/env node
/*global require,__dirname,process*/
(function withNode() {
'use strict';
const certificates = require('./index')
, args = require('minimist')(process.argv.slice(2))
, fs = require('fs')
, path = require('path');
if (!args.where) {
throw new Error('You must provide a path');
}
let certificatesConfiguration = require(path.resolve(__dirname, 'config.json'))
, toStore
, keyStream = fs.createWriteStream(path.resolve(args.where, 'key.pem'))
, certStream = fs.createWriteStream(path.resolve(args.where, 'cert.pem'));
if (args &&
args.name &&
args.country &&
args.state &&
args.locality &&
args.organization &&
args['org-min']) {
certificatesConfiguration = {
'commonName': args.name,
'countryName': args.country,
'ST': args.state,
'localityName': args.locality,
'organizationName': args.organization,
'OU': args['org-min']
};
}
toStore = certificates(certificatesConfiguration);
keyStream.write(toStore.key);
keyStream.end();
certStream.write(toStore.cert);
certStream.end();
}());