diff --git a/package.json b/package.json index 3f151434..37b0385e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@alertlogic/paws-collector", - "version": "1.1.9", + "version": "1.2.0", "license": "MIT", "description": "Alert Logic AWS based API Poll Log Collector Library", "repository": { @@ -15,7 +15,7 @@ ], "scripts": { "lint": "jshint --exclude \"./node_modules/*\" **/*.js", - "test": "JUNIT_REPORT_PATH=./test/report.xml nyc --reporter=cobertura mocha --colors --reporter mocha-jenkins-reporter", + "test": "JUNIT_REPORT_PATH=./test/report.xml nyc --reporter=cobertura mocha --colors", "create-collector": "node create-collector.js", "rel": "npm publish --access=public" }, @@ -25,14 +25,13 @@ "clone": "*", "jshint": "^2.9.5", "mocha": "^6.2.2", - "mocha-jenkins-reporter": "^0.4.2", "nyc": "^14.1.1", "rewire": "^4.0.1", "sinon": "^7.5.0", "yargs": "^15.0.2" }, "dependencies": { - "@alertlogic/al-aws-collector-js": "2.0.11", + "@alertlogic/al-aws-collector-js": "3.0.2", "async": "3.1.0", "debug": "4.1.1", "moment": "2.24.0" diff --git a/paws_collector.js b/paws_collector.js index e4fcf62e..343571b9 100644 --- a/paws_collector.js +++ b/paws_collector.js @@ -21,6 +21,7 @@ const packageJson = require('./package.json'); const CREDS_FILE_PATH = '/tmp/paws_creds.json'; var PAWS_DECRYPTED_CREDS = null; +const DOMAIN_REGEXP = /^[htps]*:\/\/|\/$/gi; function getPawsParamStoreParam(){ return new Promise((resolve, reject) => { @@ -73,6 +74,7 @@ class PawsCollector extends AlAwsCollector { constructor(context, {aimsCreds, pawsCreds}, childVersion, healthChecks = [], statsChecks = []) { const version = childVersion ? childVersion : packageJson.version; + const endpointDomain = process.env.paws_endpoint.replace(DOMAIN_REGEXP, ''); super(context, 'paws', AlAwsCollector.IngestTypes.LOGMSGS, version, @@ -83,6 +85,9 @@ class PawsCollector extends AlAwsCollector { this._pawsCollectorType = process.env.paws_type_name; this.pollInterval = process.env.paws_poll_interval; this.applicationId = process.env.al_application_id; + this._pawsEndpoint = process.env.paws_endpoint + this._pawsDomainEndpoint = endpointDomain; + this._pawsHttpsEndpoint = 'https://' + endpointDomain; }; get application_id () { @@ -103,7 +108,19 @@ class PawsCollector extends AlAwsCollector { get pawsCollectorType() { return this._pawsCollectorType; - } + }; + + get pawsEndpoint() { + return this._pawsEndpoint; + }; + + get pawsDomainEndpoint() { + return this._pawsDomainEndpoint; + }; + + get pawsHttpsEndpoint() { + return this._pawsHttpsEndpoint; + }; getProperties() { const baseProps = super.getProperties(); @@ -154,32 +171,39 @@ class PawsCollector extends AlAwsCollector { }) } - register(event) { + registerPawsCollector(event, callback) { let collector = this; let pawsRegisterProps = this.getProperties(); + collector.pawsGetRegisterParameters(event, function(err, customRegister) { + if (err) { + console.err('PAWS000101 Error during registration', err); + return callback(err); + } else { + let registerProps = Object.assign(pawsRegisterProps, customRegister); + AlAwsCollector.prototype.register.call(collector, event, registerProps, callback); + + } + }); + } + + register(event, customUnused, callback) { + let collector = this; async.waterfall([ function(asyncCallback) { + collector.registerPawsCollector(event, asyncCallback); + }, + function(regResp, asyncCallback) { return collector.pawsInitCollectionState(event, asyncCallback); }, function(state, nextInvocationTimeout, asyncCallback) { return collector._storeCollectionState({}, state, nextInvocationTimeout, asyncCallback); - }, - function(sqsResponse, asyncCallback) { - return collector.pawsGetRegisterParameters(event, asyncCallback); - } - ], function(err, customRegister) { - if (err) { - console.error('PAWS000101 Error during registration', err); - return collector.done(err); - } else { - let registerProps = Object.assign(pawsRegisterProps, customRegister); - return AlAwsCollector.prototype.register.call(collector, event, registerProps); } - }); + ], + callback); }; - - deregister(event) { + + deregister(event, customUnused, callback) { let collector = this; let pawsRegisterProps = { pawsCollectorType : collector._pawsCollectorType @@ -189,7 +213,7 @@ class PawsCollector extends AlAwsCollector { console.warn('PAWS000102 Error during deregistration', err); } let registerProps = Object.assign(pawsRegisterProps, customRegister); - return AlAwsCollector.prototype.deregister.call(collector, event, registerProps); + return AlAwsCollector.prototype.deregister.call(collector, event, registerProps, callback); }); }; @@ -206,12 +230,19 @@ class PawsCollector extends AlAwsCollector { return super.handleEvent(event); } }; - + handlePollRequest(stateSqsMsg) { let collector = this; let pawsState = JSON.parse(stateSqsMsg.body); async.waterfall([ + function(asyncCallback) { + if (!collector.registered) { + return asyncCallback('PAWS000103 Collection attempt for unregistrered collector'); + } else { + return asyncCallback(); + } + }, function(asyncCallback) { return collector.pawsGetLogs(pawsState.priv_collector_state, asyncCallback); }, @@ -389,7 +420,7 @@ class PawsCollector extends AlAwsCollector { /** * @function collector callback to get specific (de)registration parameters - * @param event - collector register event coming in from CFT during stack Create/Delete operations. + * @param event - optional, collector register event coming in from CFT during stack Create/Delete operations. * @param callback * @returns callback - (error, objectWithRegistrationProperties) * diff --git a/ps_spec.yml b/ps_spec.yml new file mode 100644 index 00000000..b5ce2529 --- /dev/null +++ b/ps_spec.yml @@ -0,0 +1,48 @@ +version: 1.0 +service_name: paws-collector + +stages: + - + name: PR Test + when: + - pull_request + - pull_request: + trigger_phrase: test it + image: node:12 + compute_size: small + commands: + - make test + + - + name: Master Push - Publish + when: + - push: ['master'] + image: node:12 + compute_size: small + commands: + - | + set -ex + #git config --global --add url."git@github.com:".insteadOf "https://github.com/" + + echo //registry.npmjs.org/:_authToken=$NPM_TOKEN > .npmrc + npm whoami + + PKGNAME=$(node -e 'console.log(require("./package.json").name)') + PKGVERSION=$(node -e 'console.log(require("./package.json").version)') + V_VERSION=v$PKGVERSION + WORDCOUNT=$(npm view "${PKGNAME}@${PKGVERSION}" | wc -c) + + git tag -a $V_VERSION -m "$PKGNAME release $V_VERSION" HEAD + + npm install + + if [ "$WORDCOUNT" -eq 0 ]; then + echo "PUBLISHING $PKGNAME $PKGVERSION" + npm run lint + git push origin $V_VERSION + npm publish --access public + else + echo "NOT PUBLISHING $PKGNAME $PKGVERSION" + fi + - echo done +