Skip to content

Commit

Permalink
More renaming (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkuzmin authored Nov 27, 2019
1 parent c716205 commit 4e54dc3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 27 deletions.
4 changes: 3 additions & 1 deletion collectors/okta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"test": "JUNIT_REPORT_PATH=./test/report.xml nyc --reporter=cobertura mocha --colors --reporter mocha-jenkins-reporter"
},
"devDependencies": {
"aws-sdk": "*",
"aws-sdk-mock": "*",
"jshint": "^2.9.5",
"mocha": "^6.2.2",
"mocha-jenkins-reporter": "^0.4.2",
Expand All @@ -19,7 +21,7 @@
"dependencies": {
"@okta/okta-sdk-nodejs": "3.1.0",
"@alertlogic/al-collector-js": "1.3.4",
"@alertlogic/paws-collector": "1.0.1",
"@alertlogic/paws-collector": "1.0.2",
"async": "3.1.0",
"debug": "4.1.1",
"moment": "2.24.0"
Expand Down
6 changes: 1 addition & 5 deletions collectors/okta/test/okta_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,10 @@ describe('Unit Tests', function() {
done();
}
};
// const testEvent = {
// RequestType: 'ScheduledEvent',
// Type: 'PollRequest'
// };

OktaCollector.load().then(function(creds) {
var collector = new OktaCollector(ctx, creds, 'okta');
let fmt = collector.extensionFormatLog(oktaMock.OKTA_LOG_EVENT);
let fmt = collector.pawsFormatLog(oktaMock.OKTA_LOG_EVENT);
console.log('!!!', fmt);
done();
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alertlogic/paws-collector",
"version": "1.0.1",
"version": "1.0.2",
"description": "Alert Logic AWS based API Poll Log Collector Library",
"repository": {
"type": "git",
Expand Down
32 changes: 16 additions & 16 deletions paws_collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ const AlAwsCollector = require('@alertlogic/al-aws-collector-js').AlAwsCollector
const m_packageJson = require('./package.json');

class PawsCollector extends AlAwsCollector {
constructor(context, creds, extensionName) {
constructor(context, creds, collectorType) {
super(context, 'paws',
AlAwsCollector.IngestTypes.LOGMSGS,
m_packageJson.version,
creds,
null, [], []);
console.info('PAWS000100 Loading extension', extensionName);
this._extensionName = extensionName;
console.info('PAWS000100 Loading collector', collectorType);
this._collectorType = collectorType;
this.pollInterval = process.env.paws_poll_interval;
};

register(event) {
let collector = this;
let stack = {
stackName : event.ResourceProperties.StackName,
extensionName : collector._extensionName,
pawsCollectorType : collector._collectorType,
pawsEndpoint : process.env.paws_endpoint
};

async.waterfall([
function(asyncCallback) {
return collector.extensionInitCollectionState(event, asyncCallback);
return collector.pawsInitCollectionState(event, asyncCallback);
},
function(state, nextInvocationTimeout, asyncCallback) {
return collector._storeCollectionState({}, state, nextInvocationTimeout, asyncCallback);
},
function(sqsResponse, asyncCallback) {
return collector.extensionGetRegisterParameters(event, asyncCallback);
return collector.pawsGetRegisterParameters(event, asyncCallback);
}
], function(err, customRegister) {
if (err) {
Expand All @@ -62,9 +62,9 @@ class PawsCollector extends AlAwsCollector {
let collector = this;
let stack = {
stackName : event.ResourceProperties.StackName,
extensionName : collector._extensionName
pawsCollectorType : collector._collectorType
};
let custom = collector.extensionGetRegisterParameters(event, function(err, customRegister) {
let custom = collector.pawsGetRegisterParameters(event, function(err, customRegister) {
if (err) {
console.warn('PAWS000102 Error during deregistration', err);
}
Expand Down Expand Up @@ -93,11 +93,11 @@ class PawsCollector extends AlAwsCollector {

async.waterfall([
function(asyncCallback) {
return collector.extensionGetLogs(pawsState.extension_state, asyncCallback);
return collector.pawsGetLogs(pawsState.priv_collector_state, asyncCallback);
},
function(logs, newExtState, nextInvocationTimeout, asyncCallback) {
console.info('PAWS000200 Log events received ', logs.length);
return collector.processLog(logs, collector.extensionFormatLog, null, function(err) {
return collector.processLog(logs, collector.pawsFormatLog, null, function(err) {
return asyncCallback(err, newExtState, nextInvocationTimeout);
});
},
Expand All @@ -113,7 +113,7 @@ class PawsCollector extends AlAwsCollector {
let collector = this;
var sqs = new AWS.SQS({apiVersion: '2012-11-05'});
const nextInvocationTimeout = invocationTimeout ? invocationTimeout : collector.pollInterval;
pawsState.extension_state = newExtState;
pawsState.priv_collector_state = newExtState;

const params = {
MessageBody: JSON.stringify(pawsState),
Expand All @@ -125,7 +125,7 @@ class PawsCollector extends AlAwsCollector {
};

/**
* @function extension callback to initialize collection state
* @function collector callback to initialize collection state
* @param event - collector register event coming in from CFT.
* @param callback
* @returns callback - (error, stateObject, nextInvocationTimeoutSec)
Expand All @@ -136,8 +136,8 @@ class PawsCollector extends AlAwsCollector {
}

/**
* @function extension callback to receive logs data
* @param state - collection state specific to an extension.
* @function collector callback to receive logs data
* @param state - collection state specific to a PAWS collector.
* @param callback
* @returns callback - (error, logsArray, stateObject, nextInvocationTimeoutSec)
*
Expand All @@ -147,7 +147,7 @@ class PawsCollector extends AlAwsCollector {
};

/**
* @function extension callback to get extension specific (de)registration parameters
* @function collector callback to get specific (de)registration parameters
* @param event - collector register event coming in from CFT during stack Create/Delete operations.
* @param callback
* @returns callback - (error, objectWithRegistrationProperties)
Expand All @@ -158,7 +158,7 @@ class PawsCollector extends AlAwsCollector {
};

/**
* @function extension callback to format received data
* @function collector callback to format received data
* Refer to al-collector-js.buildPayload parseCallback param
*/
pawsFormatLog() {
Expand Down
8 changes: 4 additions & 4 deletions test/paws_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ class TestCollector extends PawsCollector {
super(ctx, creds, 'test-collector');
}

extensionInitCollectionState(event, callback) {
pawsInitCollectionState(event, callback) {
return callback(null, {state: 'initial-state'}, 900);
}

extensionGetLogs(state, callback) {
pawsGetLogs(state, callback) {
return callback(null, ['log1', 'log2'], {state: 'new-state'}, 900);
}

extensionGetRegisterParameters(event, callback) {
pawsGetRegisterParameters(event, callback) {
return callback(null, {register: 'test-param'});
}

extensionFormatLog(msg) {
pawsFormatLog(msg) {
let formattedMsg = {
messageTs: 12345678,
priority: 11,
Expand Down

0 comments on commit 4e54dc3

Please sign in to comment.