Skip to content

Commit

Permalink
From vhenckel: fix unnecessary code (#3064)
Browse files Browse the repository at this point in the history
* fix: removing unnecessary code

* fix: removing foreach method and returning with map

* fix: removing foreach method and returning with map

Co-authored-by: Vitor Henckel <[email protected]>
  • Loading branch information
filipgraniczny and vhenckel authored Aug 2, 2022
1 parent 9b27ef9 commit 581454c
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions example/lambdas/ftpPopulateTestLambda/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
'use strict';

const {
randomStringFromRegex,
} = require('@cumulus/common/test-utils');
const { randomStringFromRegex } = require('@cumulus/common/test-utils');
const Logger = require('@cumulus/logger');

const { fetchFakeProviderIp } = require('@cumulus/common/fake-provider');
// eslint-disable-next-line no-unused-vars
const { granules } = require('@cumulus/test-data');
const replace = require('lodash/replace');
const JSFtp = require('jsftp');
const path = require('path');
const fs = require('fs');

const log = new Logger({ sender: '@cumulus/example/lambdas/ftpPopulateTestLambda' });
const log = new Logger({
sender: '@cumulus/example/lambdas/ftpPopulateTestLambda',
});

const updateAndUploadTestFileToFtpHost = (params) => {
const {
Expand All @@ -24,14 +22,11 @@ const updateAndUploadTestFileToFtpHost = (params) => {
targetReplacementRegex,
targetReplacementString,
} = params;
let data;
let data = fs.readFileSync(file);
if (replacements.length > 0) {
data = fs.readFileSync(file);
replacements.forEach((replacement) => {
data = replace(data, new RegExp(replacement.old, 'g'), replacement.new);
});
} else {
data = fs.readFileSync(file);
}
let key = path.basename(file);
if (targetReplacementRegex) {
Expand Down Expand Up @@ -64,9 +59,7 @@ const updateAndUploadTestFileToFtpHost = (params) => {
}
};

const uploadFtpGranuleDataForDiscovery = async ({
prefix,
}) => {
const uploadFtpGranuleDataForDiscovery = async ({ prefix }) => {
log.info('Starting lambda');
const ftpData = [
'./granules/MOD09GQ.A2016358.h13v04.006.2016360104606.hdf.met',
Expand All @@ -85,24 +78,22 @@ const uploadFtpGranuleDataForDiscovery = async ({
log.info(`Hostconfig is ${JSON.stringify(hostConfig)}`);

const filePaths = await Promise.all(
ftpData.map(
async (file) => {
let objectKey;
try {
objectKey = await updateAndUploadTestFileToFtpHost({
file,
hostConfig,
prefix,
targetReplacementRegex: 'MOD09GQ.A2016358.h13v04.006.2016360104606',
targetReplacementString: newGranuleId,
});
} catch (error) {
log.info('Error!', error);
throw error;
}
return objectKey;
ftpData.map(async (file) => {
let objectKey;
try {
objectKey = await updateAndUploadTestFileToFtpHost({
file,
hostConfig,
prefix,
targetReplacementRegex: 'MOD09GQ.A2016358.h13v04.006.2016360104606',
targetReplacementString: newGranuleId,
});
} catch (error) {
log.info('Error!', error);
throw error;
}
)
return objectKey;
})
);
log.info(JSON.stringify(filePaths));
return { filePaths, newGranuleId };
Expand Down Expand Up @@ -130,9 +121,7 @@ const deleteFtpGranule = async (filePath) => {
});
};

const deleteFtpGranules = async ({
filePaths,
}) => {
const deleteFtpGranules = async ({ filePaths }) => {
const deletions = await Promise.allSettled(
filePaths.map((ftpFilePath) => deleteFtpGranule(ftpFilePath))
);
Expand Down

0 comments on commit 581454c

Please sign in to comment.