-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
executable file
·79 lines (64 loc) · 2.11 KB
/
main.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
#!/usr/bin/env node
'use strict';
//process.env.BEAME_LOG_LEVEL = "DEBUG";
// Ensure correct NodeJS version - start
const process = require('process');
const semver = require('semver');
const pjson = require('./package.json');
if (!semver.satisfies(process.versions.node, pjson.engines.node)) {
console.error(`Beame-gatekeeper requires NodeJS version ${pjson.engines.node}. Running with version ${process.versions.node}. Exiting.`);
process.exit(2);
}
// Ensure correct NodeJS version - end
const Bootstrapper = require('./src/bootstrapper');
const bootstrapper = Bootstrapper.getInstance();
bootstrapper.assertProxySettings();
bootstrapper.setExternalOcspEnv();
/**
* Should be synchronized with token from Auth Server
* @typedef {Object} EmailRegistrationData
* @property {String} name
* @property {String} email
* @property {String} authToken
* @property {String} authSrvFqdn
* @property {Number} src
*/
const fs = require('fs');
const path = require('path');
const beameSDK = require('beame-sdk');
const BeameStore = new beameSDK.BeameStore();
//init service manager instance
new (require('./src/serviceManager'))();
function getHelpMessage(fileName) {
return fs.readFileSync(path.join(__dirname, 'help-messages', fileName), {'encoding': 'utf-8'});
}
// There will be automatically imported certificates in the store.
// Filtering them out.
function list() {
return BeameStore.list(null, {hasPrivateKey: true});
}
const parametersSchema = {
'format': {required: false, options: ['text', 'json'], default: 'text'},
};
const BeameCli = require('beame-cli');
const cli = new BeameCli('beame-gatekeeper', path.join(__dirname, 'src', 'cli'), [
'creds',
'config',
'server',
]);
cli.setGlobalSchema(parametersSchema);
cli.approveCommand = (cmdName, subCmdName) => {
if(((cmdName == 'creds') && (subCmdName == 'getCreds')) || ((cmdName == 'server') && (subCmdName == 'config'))) {
return true;
}
let credsCount = list().length;
if (!credsCount) {
console.log(getHelpMessage('no-certificates.txt'));
return false;
}
return true;
};
cli.usage = () => {
console.log(getHelpMessage('no-command.txt'));
};
cli.run();