From cf5edafaf6923b748a229cbd3f2422da255f5806 Mon Sep 17 00:00:00 2001 From: Laurence Maultsby Date: Thu, 20 Oct 2016 21:39:20 -0400 Subject: [PATCH 1/1] RIFT-14874: Allow deny of duplicate events in loggin Signed-off-by: Laurence Maultsby --- skyquake/plugins/logging/api/logging.js | 11 ++++----- skyquake/plugins/logging/api/transforms.js | 4 ++-- skyquake/plugins/logging/src/loggingSource.js | 24 +++++++++++++++++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/skyquake/plugins/logging/api/logging.js b/skyquake/plugins/logging/api/logging.js index c2f56f834..3ef9027d9 100644 --- a/skyquake/plugins/logging/api/logging.js +++ b/skyquake/plugins/logging/api/logging.js @@ -369,15 +369,14 @@ Config.deleteDefaultSyslogSeverity = function(req) { Config.setAllowDuplicateEvents = function(req) { // TODO: verify there is one key at root of data: 'default-severity' // OR just filter on the request body - - if (req.body.hasOwnProperty('allowDuplicateEvents') && - typeof req.body.allowDuplicateEvents == 'boolean') { - if (req.body.allowDuplicateEvents) { - return handlePutRequest(req, APIVersion + '/api/config/logging/allow', { +console.log(req.body) + if (req.body.hasOwnProperty('allowDuplicateEvents')) { + if (req.body.allowDuplicateEvents.toUpperCase() == "TRUE") { + return handlePutRequest(req, '/api/config/logging/allow', { "duplicate": "events" }); } else { // false, remove entry from logging config - return handleDeleteRequest(req, APIVersion + '/api/config/logging/allow/duplicate'); + return handleDeleteRequest(req, '/api/config/logging/allow/duplicate'); } } else { return handleReject(statusCode=400, diff --git a/skyquake/plugins/logging/api/transforms.js b/skyquake/plugins/logging/api/transforms.js index eb17b7abc..5f6501020 100644 --- a/skyquake/plugins/logging/api/transforms.js +++ b/skyquake/plugins/logging/api/transforms.js @@ -1,5 +1,5 @@ /* - * + * * Copyright 2016 RIFT.IO Inc * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -168,7 +168,7 @@ LoggingConfigEncoder.prototype.denyEvents = function(data) { * or absence of the { "allow": { "duplicate": "events" }} key/value hierarchy */ LoggingConfigEncoder.prototype.allow = function(data) { - if (data.allowDuplicateEvents) { + if (data.allowDuplicateEvents.toUpperCase() == "TRUE") { return { duplicate: "events" }; } else { return null; diff --git a/skyquake/plugins/logging/src/loggingSource.js b/skyquake/plugins/logging/src/loggingSource.js index dc28aa4cc..c83b322d3 100644 --- a/skyquake/plugins/logging/src/loggingSource.js +++ b/skyquake/plugins/logging/src/loggingSource.js @@ -66,6 +66,30 @@ export default { return new Promise(function(resolve, reject) { let promises = []; let remove = null; + // $.ajax({ + // url: 'https://10.66.202.130:8008/api/config/logging/allow/duplicate', + // type: 'DELETE', + // beforeSend: Utils.addAuthorizationStub + // }) + if(loggingConfig.hasOwnProperty('allowDuplicateEvents')) { + promises.push($.ajax({ + // url: apiUrl('api/config/default-severity'), + url: apiUrl('api/config/allow-duplicate-events'), + type: 'PUT', + beforeSend: Utils.addAuthorizationStub, + data: { + allowDuplicateEvents: loggingConfig.allowDuplicateEvents + }, + success: function(data) { + resolve(data); + }, + error: function(error) { + console.log("There was an error updating the logging config data", + error); + reject(error); + } + })) + } // if(nulledCategories.length > 0) { // remove = $.ajax({ // // url: apiUrl('api/config/default-severity'), -- 2.17.1