From 5886c2157407a9d589804047b81e256dcdce6779 Mon Sep 17 00:00:00 2001 From: Durgesh1988 Date: Mon, 19 Sep 2016 11:21:37 +0530 Subject: [PATCH] CAT-2179 Fixed --- .../app/routes/v1.0/routes_serviceStatus.js | 47 +++++++++++++------ server/install.js | 2 + 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/server/app/routes/v1.0/routes_serviceStatus.js b/server/app/routes/v1.0/routes_serviceStatus.js index 660b6d2e5..2e712aec4 100644 --- a/server/app/routes/v1.0/routes_serviceStatus.js +++ b/server/app/routes/v1.0/routes_serviceStatus.js @@ -14,11 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// The file contains all the end points for Tracks - var logger = require('_pr/logger')(module); -var request = require("request"); +var https = require("https"); var errorResponses = require('./error_responses'); +var appConfig = require('_pr/config'); module.exports.setRoutes = function(app, sessionVerificationFunc) { @@ -26,26 +25,44 @@ module.exports.setRoutes = function(app, sessionVerificationFunc) { // Check for Service stop app.post('/serviceAction', function(req, res) { - - console.log(req.body); var post_data = { "cmd": req.body.cmd, "type": req.body.type, "hosts": req.body.hosts }; - request({ - url: 'https://52.8.208.191/api/v1/webhooks/remotecmd?st2-api-key=YTU0M2RlNmMwMjdhMzFlNzVmMTExZDA4YWExMWY5MmFjOTUyYzc2Nzk5YjMzYmM4ZjAwNWJiYjc2NjFmZjY1MA', - body: post_data, - method: 'post', - json: true, - }, function(err, httpResponse, body) { - if (err) { - res.status(500).send(err); - return; + post_data = JSON.stringify(post_data); + + + var post_options = { + host: appConfig.serverControllerUrl, + port: 443, + path: '/api/v1/webhooks/remotecmd?st2-api-key='+appConfig.serviceControllerKey, + method: 'POST', + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Content-Length': Buffer.byteLength(post_data) } - res.status(200).send(body); + }; + + + var post_req = https.request(post_options, function(httpsRes) { + httpsRes.setEncoding('utf8'); + var data = ''; + httpsRes.on('data', function(chunk) { + data = data + chunk + console.log('Response: ' + chunk); + }); + httpsRes.on('end', function(chunk) { + res.status(200).send(data); + }); + httpsRes.on('error', function(err) { + res.status(500).send(err); + }); }); + post_req.write(post_data); + post_req.end(); + }); }; \ No newline at end of file diff --git a/server/install.js b/server/install.js index 370278b28..cd3ae626c 100755 --- a/server/install.js +++ b/server/install.js @@ -67,6 +67,8 @@ function getDefaultsConfig() { return config.catalystHome + this.cookbooksDirName + "/"; } }, + serviceControllerKey:'ZDQ2YWM3ZTUyZDhhZjhhOWRkMWQ2ZTc3NDhhNjk1OWEyYzgxZGJkMWVjYjA3ZThiZjY0NTBjYjBjMTM5YzA0Yg', + serverControllerUrl:'stackstorm.rlcatalyst.com', constantData: { common_field: ['envId', 'providerId', 'orgId', 'bgId','organizationId','businessGroupId', 'projectId','templateType','blueprintConfig.cloudProviderType','cloudProviderType'], sort_field: ['name', 'description'],