UNPKG

k2hr3-api

Version:

K2HR3 REST API is K2hdkc based Resource and Roles and policy Rules

114 lines (113 loc) 3.76 kB
#!/usr/bin/env node "use strict"; /* * K2HR3 REST API * * Copyright 2017 Yahoo Japan Corporation. * * K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers * common management information for the cloud. * K2HR3 can dynamically manage information as "who", "what", "operate". * These are stored as roles, resources, policies in K2hdkc, and the * client system can dynamically read and modify these information. * * For the full copyright and license information, please view * the license file that was distributed with this source code. * * AUTHOR: Takeshi Nakatani * CREATE: Wed Oct 24 2018 * REVISION: * */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); // // Module dependencies. // const k2hr3apiutil_1 = __importDefault(require("../lib/k2hr3apiutil")); const ipwatch_1 = __importDefault(require("../lib/ipwatch")); const dbglogging_1 = __importDefault(require("../lib/dbglogging")); const k2hr3config_1 = require("../lib/k2hr3config"); const apiConf = new k2hr3config_1.r3ApiConfig(); // // Setup console logging // apiConf.setConsoleLogging(__dirname + '/..', true); // replace output from stdout/stderr to file if set in config // Globals let intervalobj = null; // // Process/Signal handlering // const procSignal = (reason, code) => { if (k2hr3apiutil_1.default.compareCaseString(reason, 'exit')) { dbglogging_1.default.elog('K2HR3 watcher exit with status code : ' + (k2hr3apiutil_1.default.isSafeNumber(code) ? code.toString() : 'unknown')); } else { dbglogging_1.default.elog('K2HR3 watcher caught signal : ' + k2hr3apiutil_1.default.getSafeString(reason)); } if (intervalobj) { clearInterval(intervalobj); intervalobj = null; } }; process.on('exit', (code) => { procSignal('exit', code); }); process.on('SIGHUP', () => { procSignal('SIGHUP'); }); process.on('SIGINT', () => { procSignal('SIGINT'); }); process.on('SIGBREAK', () => { procSignal('SIGBREAK'); }); process.on('SIGTERM', () => { procSignal('SIGTERM'); }); // // OneShot callback // const oneshotCallback = (result) => { if (k2hr3apiutil_1.default.isBoolean(result) && result) { dbglogging_1.default.dlog('K2HR3 watcher oneshot result : Succeed'); process.exit(0); } else { dbglogging_1.default.elog('K2HR3 watcher oneshot result : Failed'); process.exit(1); } }; // // Process parameter // let oneshotCB = null; if (k2hr3apiutil_1.default.isNotEmptyArray(process.argv)) { for (let cnt = 2; cnt < process.argv.length; ++cnt) { // argv[0] = 'node', argv[1] = 'this program' if (k2hr3apiutil_1.default.isSafeString(process.argv[cnt]) || k2hr3apiutil_1.default.compareCaseString(process.argv[cnt], '--oneshot') || k2hr3apiutil_1.default.compareCaseString(process.argv[cnt], '-os')) { oneshotCB = oneshotCallback; } } } // // Check wathcer type // if (ipwatch_1.default.isNocheckType() || ipwatch_1.default.isListenerType()) { dbglogging_1.default.elog('K2HR3 watcher type defined ' + ipwatch_1.default.getType() + ' in configuration, thus could not run watcher.'); process.exit(1); } // // Run watcher interval loop // intervalobj = ipwatch_1.default.watchAddressesAlive(oneshotCB); if (!intervalobj) { if (null != oneshotCB) { // nothig to do here } else { dbglogging_1.default.elog('K2HR3 watcher could not run.'); process.exit(1); } } /* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: * vim600: noexpandtab sw=4 ts=4 fdm=marker * vim<600: noexpandtab sw=4 ts=4 */