UNPKG

k2hr3-api

Version:

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

133 lines (116 loc) 3.18 kB
/* * 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 Jun 8 2017 * REVISION: * */ 'use strict'; var http = require('http'); var https = require('https'); var cacerts = require('../lib/cacerts'); var apiutil = require('../lib/k2hr3apiutil'); var cliutil = require('../lib/k2hr3cliutil'); // Debug logging objects var r3logger = require('../lib/dbglogging'); // // Hostname and port from env // var hostname = apiutil.getSafeString(process.env.APIHOST); var hostport = apiutil.getSafeString(process.env.APIPORT); var is_https = apiutil.compareCaseString('yes', process.env.HTTPS_ENV); // // Request API for test // function deleteV1Policy(token, name) { var headers = { 'Content-Type': 'application/json', 'Content-Length': 0, 'X-Auth-Token': token }; var options = { 'host': hostname, 'port': hostport, 'path': '/v1/policy/' + name, 'method': 'DELETE', 'headers': headers }; r3logger.dlog('request options = ' + JSON.stringify(options)); r3logger.dlog('request headers = ' + JSON.stringify(headers)); var httpobj; if(is_https){ if(null !== cacerts.ca){ options.ca = cacerts.ca; } options.rejectUnauthorized = false; // always insecure for this manual test options.agent = new https.Agent(options); httpobj = https; }else{ options.agent = new http.Agent(options); httpobj = http; } var req = httpobj.request(options, function(res) { var response = ''; console.log('RESPONSE CODE = ' + res.statusCode); r3logger.dlog('response status = ' + res.statusCode); r3logger.dlog('response header = ' + JSON.stringify(res.headers)); res.setEncoding('utf8'); res.on('data', function (chunk) { r3logger.dlog('response chunk = ' + chunk); response += chunk; }); res.on('end', function(result) // eslint-disable-line no-unused-vars { r3logger.mlog(r3logger.dump(response)); // response is object(or not) console.log('RESPONSE BODY = ' + JSON.stringify(response)); process.exit(0); }); }); req.on('error', function(e) { r3logger.elog('problem with request: ' + e.message); }); req.end(); } // // run // cliutil.getConsoleInput('Scoped user token for tenant : ', true, false, function(isbreak, token) { if(isbreak){ process.exit(0); } var _token = token; cliutil.getConsoleInput('Policy name : ', true, false, function(isbreak, name) { if(isbreak){ process.exit(0); } var _name = name; // run deleteV1Policy(_token, _name); }); }); /* * 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 */