@capriza/connector-controller
Advanced tools
Comparing version 1.0.31 to 1.0.32
var Syncher = require ("./syncher.js"); | ||
var hashFunction = require('object-hash'); | ||
var jslt = require('@capriza/jslt'); | ||
var LoggerClass = require ("./log").Logger; | ||
@@ -14,2 +15,9 @@ exports.Connector = class Connector { | ||
getBLLogger(logger) { | ||
if (!this.config.separateBlLog) return logger; | ||
logger.log ("BL log will be written in bl.log file"); | ||
var bindings = LoggerClass.getLoggerBindings(logger); | ||
return (new LoggerClass(process.env.logStream, 'bl.log')).create({}).child(bindings); | ||
} | ||
/** | ||
@@ -71,2 +79,3 @@ * Checks the BL is valid, and answers to all the requirements, else, throws an exception | ||
var logger = options.logger.child({component: "connector-controller", approvalId: data.approval.private.id}); | ||
var blLogger = this.getBLLogger(logger); | ||
@@ -88,3 +97,3 @@ logger.info (`Performing action '${type}'`); | ||
fetchedApproval = await this.BL.getApproval (data.approval, {logger}); | ||
fetchedApproval = await this.BL.getApproval (data.approval, {blLogger}); | ||
if (!fetchedApproval) { | ||
@@ -107,3 +116,3 @@ var error = new Error (`Approval was not returned from the connector`); | ||
logger.info (`Passing approval '${data.approval.private.id}' to connector to perform action '${type}'`); | ||
await this.BL[type](data, {logger}); | ||
await this.BL[type](data, {blLogger}); | ||
logger.info (`Connector performed action successfully!`); | ||
@@ -113,3 +122,3 @@ | ||
logger.info(`Mini-sync: Fetching the updated approval`); | ||
updatedApproval = await this.BL.getApproval(data.approval, {logger}); | ||
updatedApproval = await this.BL.getApproval(data.approval, {blLogger}); | ||
} else logger.info ("Mini-sync disabled, marking the approval as deleted."); | ||
@@ -141,3 +150,3 @@ | ||
this.config = context.config.controllerConfig; | ||
return this.BL.init({config: context.config.blConfig, logger: context.logger}); | ||
return this.BL.init({config: context.config.blConfig, logger: this.getBLLogger(this.logger)}); | ||
} | ||
@@ -151,2 +160,3 @@ | ||
var logger = action.logger.child({component: "connector-controller"}); | ||
var blLogger = this.getBLLogger(logger); | ||
logger.info(`syncing hash list (length = ${this.signatureList.length})`); | ||
@@ -172,3 +182,3 @@ | ||
var fetchRes = this.BL.fetch({ signatureList, logger }, (err, approvalsChunk, hasMore) => { | ||
var fetchRes = this.BL.fetch({ signatureList, blLogger }, (err, approvalsChunk, hasMore) => { | ||
if (err) return reject(err); | ||
@@ -190,4 +200,5 @@ processChunk(approvalsChunk, hasMore); | ||
var logger = options.logger.child({component: "connector-controller"}); | ||
var blLogger = this.getBLLogger(logger); | ||
logger.info (`downloading attachment '${data.attachmentId}' of approval: '${data.approval.private.id}'`); | ||
var {data, mediaType} = await this.BL.downloadAttachment(data, {logger}); | ||
var {data, mediaType} = await this.BL.downloadAttachment(data, {blLogger}); | ||
return {data, contentType: mediaType}; | ||
@@ -197,5 +208,6 @@ } | ||
var logger = options.logger.child({component: "connector-controller"}); | ||
var blLogger = this.getBLLogger(logger); | ||
logger.info (`Authenticating: ${data.credentials && data.credentials.username}`); | ||
try { | ||
var res = await this.BL.authenticate(data.credentials, {logger}); | ||
var res = await this.BL.authenticate(data.credentials, {blLogger}); | ||
if (!res){ | ||
@@ -211,8 +223,2 @@ throw `Credentials authentication failed for ${data.credentials.username}`; | ||
} | ||
/** | ||
* Allows to add aditional payload on each approval that is returned in the sync process. | ||
*/ | ||
setApprovalPayload(obj){ | ||
this.additionalPayload = obj; | ||
} | ||
} |
@@ -5,12 +5,12 @@ var fs = require ('fs'); | ||
var logrotate = require('logrotator'); | ||
const logFile = `./log/main.log`; | ||
exports.Logger = class Logger{ | ||
constructor(output) { | ||
constructor(output, fileName = 'main.log') { | ||
try { | ||
this.output = output; | ||
this.logFile = `log/${fileName}`; | ||
if (output == 'file') { | ||
var dirname = path.dirname(logFile); | ||
var dirname = path.dirname(this.logFile); | ||
if (!fs.existsSync(dirname)) fs.mkdirSync(dirname); | ||
this.stream = fs.createWriteStream (logFile, { flags: 'a' }); | ||
this.stream = fs.createWriteStream (this.logFile, { flags: 'a' }); | ||
} | ||
@@ -20,2 +20,11 @@ } | ||
} | ||
static getLoggerBindings(logger){ | ||
try { | ||
return JSON.parse(`{${logger.chindings.substring(1)}}`); | ||
} | ||
catch (ex){ | ||
logger.error ("Error fetching logger bindings"); | ||
return {}; | ||
} | ||
} | ||
create(data){ | ||
@@ -33,3 +42,3 @@ if (this.output == "console") Object.assign (data, {prettyPrint : true}); | ||
// keep only 3 rotated files and compress (gzip) them. | ||
rotator.register(logFile, {schedule: '5m', size: '10m', compress: true, count: 3}); | ||
rotator.register(this.logFile, {schedule: '5m', size: '10m', compress: true, count: 3}); | ||
@@ -36,0 +45,0 @@ rotator.on('error', function(err) { |
{ | ||
"name": "@capriza/connector-controller", | ||
"version": "1.0.31", | ||
"version": "1.0.32", | ||
"description": "Capriza connectors controller", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -109,3 +109,4 @@ # Capriza Connectors | ||
* **`maxConcurrentTasks`** - A number that limits the number of concurrent tasks the connector would do at runtime. If the controller has reached its limit, it would stop pulling tasks, until a task is completed. Default: 5. | ||
* **`taskTimeout`** - Fails task if it wasn't completed in this time (in ms). Default: 30 * 60 * 1000 (30 min). | ||
* **`taskTimeout`** - Fails task if it wasn't completed in this time (in ms). Default: 30 * 60 * 1000 (30 min). | ||
* **`separateBlLog`** - When true, will write the BL log to a separate file (bl.log). | ||
@@ -112,0 +113,0 @@ * **`caprizaConfig`** - Contains the Capriza (backend) API keys, secret, and urls. This file is auto-generated on deployment using *Fortitude* (see below) for production deployment. For develpment purposes, this file should be manually created on the machine, and it's path should be mentioned in the config.json of the connector. |
@@ -13,4 +13,5 @@ var path = require('path'); | ||
var loggerFactory; | ||
if ("dev" in argv) loggerFactory = new Logger("console"); //in dev mode write log to console | ||
else loggerFactory = new Logger ("file"); //in production write log to file | ||
if ("dev" in argv) process.env.logStream = "console"; //in dev mode write log to console | ||
else process.env.logStream = "file"; //in production write log to file | ||
loggerFactory = new Logger(process.env.logStream); | ||
@@ -17,0 +18,0 @@ var logger = loggerFactory.create({}).child({component: "index.js", module: "connectors", connectorName: connectorName, connectorVersion: connectorVersion}); |
@@ -53,3 +53,9 @@ var validate = require('capriza-schema').validate; | ||
.then(data => { | ||
if (template) return data.map(rawApproval => jslt.transform(rawApproval)); | ||
if(data.partialSync){ | ||
data = data.approvals; | ||
} | ||
if (template) return data.map(rawApproval => { | ||
if (rawApproval.error) return rawApproval; | ||
return jslt.transform(rawApproval) | ||
}); | ||
return data; | ||
@@ -61,8 +67,10 @@ }) | ||
var approval = data[i]; | ||
if (!approval.schemaId) { | ||
validationResult = {errors: [{error: `approval ${approval.private.id} has no schemaId:\n${JSON.stringify()}`}]}; | ||
break; | ||
if (!approval.error) { | ||
if (!approval.schemaId) { | ||
validationResult = {errors: [{error: `approval ${approval.private.id} has no schemaId:\n${JSON.stringify()}`}]}; | ||
break; | ||
} | ||
validationResult = validate(JSON.parse(JSON.stringify(approval)), approval.schemaId); | ||
if (validationResult.errors.length > 0) break; | ||
} | ||
validationResult = validate(JSON.parse(JSON.stringify(approval)), approval.schemaId); | ||
if (validationResult.errors.length > 0) break; | ||
} | ||
@@ -69,0 +77,0 @@ res.write(JSON.stringify({data, validationResult})); |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
127648
1469
133
24