coinstac-client-core
Advanced tools
Comparing version 6.4.5 to 6.5.0
{ | ||
"name": "coinstac-client-core", | ||
"version": "6.4.5", | ||
"version": "6.5.0", | ||
"description": "COINSTAC business logic for clients.", | ||
@@ -32,7 +32,9 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"archiver": "^5.3.1", | ||
"axios": "^0.21.1", | ||
"coinstac-manager": "^6.4.5", | ||
"coinstac-pipeline": "^6.4.5", | ||
"coinstac-manager": "^6.5.0", | ||
"coinstac-pipeline": "^6.5.0", | ||
"convict": "^6.2.1", | ||
"csv-parse": "^4.4.3", | ||
"form-data": "^4.0.0", | ||
"lodash": "^4.17.10", | ||
@@ -39,0 +41,0 @@ "mkdirp": "^0.5.1", |
@@ -15,2 +15,5 @@ 'use strict'; | ||
const { ncp } = require('ncp'); | ||
const FormData = require('form-data'); | ||
const { createReadStream, createWriteStream } = require('fs'); | ||
const archiver = require('archiver'); | ||
@@ -22,6 +25,43 @@ // set w/ config etc post release | ||
const Manager = require('coinstac-manager'); | ||
const PipelineManager = require('coinstac-pipeline'); | ||
async function getAllFiles(directoryName, results = []) { | ||
const files = await fs.readdir(directoryName, { withFileTypes: true }); | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const f of files) { | ||
const fullPath = path.join(directoryName, f.name); | ||
if (f.isDirectory()) { | ||
// eslint-disable-next-line no-await-in-loop | ||
await getAllFiles(fullPath, results); | ||
} else { | ||
results.push(fullPath); | ||
} | ||
} | ||
return results; | ||
} | ||
function createTarFromDir(dir, zippedFilePath) { | ||
return new Promise((resolve, reject) => { | ||
const output = createWriteStream(zippedFilePath); | ||
const archive = archiver('tar', { | ||
gzip: true, | ||
gzipOptions: { | ||
level: 9, | ||
}, | ||
}); | ||
archive.on('error', (err) => { | ||
reject(err); | ||
}); | ||
output.on('close', () => { | ||
resolve('closed'); | ||
}); | ||
output.on('end', () => { | ||
resolve('data has been drained'); | ||
}); | ||
archive.pipe(output); | ||
archive.directory(dir, false); | ||
archive.finalize(); | ||
}); | ||
} | ||
/** | ||
@@ -53,6 +93,4 @@ * Create a user client for COINSTAC | ||
this.clientServerURL = opts.clientServerURL; | ||
this.imageDirectory = opts.imageDirectory; | ||
this.Manager = Manager; | ||
this.Manager.setLogger(this.logger); | ||
/* istanbul ignore if */ | ||
@@ -88,5 +126,7 @@ if (opts.logLevel) { | ||
mqttSubChannel: this.options.mqttServer.subChannel, | ||
}).then((manager) => { | ||
this.pipelineManager = manager; | ||
return manager; | ||
imageDirectory: this.imageDirectory, | ||
}).then((pipelineManager) => { | ||
this.pipelineManager = pipelineManager; | ||
this.Manager = pipelineManager.coinstacManager; | ||
return pipelineManager; | ||
}); | ||
@@ -303,3 +343,3 @@ } | ||
|| (filePaths.directories | ||
&& filePaths.directories.length > 0) | ||
&& filePaths.directories.length > 0) | ||
) { | ||
@@ -443,4 +483,40 @@ stageFiles = fs.symlink; | ||
} | ||
async uploadFiles(runId) { | ||
const runOutputDirectory = path.join(this.appDirectory, 'output', this.clientId, runId); | ||
const formData = new FormData(); | ||
formData.append('runId', runId); | ||
// zip the contents of the run directory | ||
const fileName = `${runId}.tar.gz`; | ||
const zippedFilePath = path.join(this.appDirectory, 'output', this.clientId, fileName); | ||
await createTarFromDir(runOutputDirectory, zippedFilePath); | ||
// append the readStream | ||
const readStream = createReadStream(zippedFilePath); | ||
formData.append('file', readStream, fileName); | ||
const postConfig = { | ||
headers: { | ||
Authorization: `Bearer ${this.token}`, | ||
...formData.getHeaders(), | ||
}, | ||
maxContentLength: 100000000, | ||
maxBodyLength: 1000000000, | ||
}; | ||
axios.post( | ||
`${process.env.API_URL}/uploadFiles`, | ||
formData, | ||
postConfig | ||
).then((result) => { | ||
this.logger.info(result); | ||
}).catch((e) => { | ||
this.logger.error(e); | ||
}); | ||
// delete the zipped file here? | ||
} | ||
} | ||
module.exports = CoinstacClient; |
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
18838
483
12
6
+ Addedarchiver@^5.3.1
+ Addedform-data@^4.0.0
+ Addedarchiver@5.3.2(transitive)
+ Addedarchiver-utils@3.0.4(transitive)
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedcompress-commons@4.1.2(transitive)
+ Addedcrc-32@1.2.2(transitive)
+ Addedcrc32-stream@4.0.3(transitive)
+ Addedform-data@4.0.2(transitive)
+ Addedminimatch@5.1.6(transitive)
+ Addedreaddir-glob@1.1.3(transitive)
+ Addedzip-stream@4.1.1(transitive)
Updatedcoinstac-manager@^6.5.0
Updatedcoinstac-pipeline@^6.5.0