Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const loadConfig = async () => {
await loadEnvFile('./.env');
verifyRequiredEnvironmentVariables();
const configFromFile = loadConfigYmlFile(process.env.DEPLOYMENT);
const buckets = await getJsonS3Object(
configFromFile.bucket,
`${configFromFile.stackName}/workflows/buckets.json`
);
return { ...configFromFile, buckets };
};
const getFailedExecutionMessage = async (inputMessage) => {
try {
const executionArn = getMessageExecutionArn(inputMessage);
const { events } = await StepFunctions.getExecutionHistory({ executionArn });
const stepFailedEvents = events.filter(
(event) =>
['ActivityFailed', 'LambdaFunctionFailed'].includes(event.type)
);
if (stepFailedEvents.length === 0) {
log.info(`No failed step events found in execution ${executionArn}`);
return inputMessage;
}
const lastStepFailedEvent = stepFailedEvents[stepFailedEvents.length - 1];
const failedStepExitedEvent = getStepExitedEvent(events, lastStepFailedEvent);
if (!failedStepExitedEvent) {
log.info(
`Could not retrieve output from last failed step in execution ${executionArn}, falling back to execution input`,
'use strict';
const awsServices = require('@cumulus/aws-client/services');
const log = require('@cumulus/common/log');
const messageConsumer = require('./message-consumer');
const Kinesis = awsServices.kinesis();
const tallyReducer = (acc, cur) => acc + cur;
/**
* This function will accept as valid input an event whose `endTimestamp` and `startTimestamp`
* fields must contain valid input to the `new Date()` constructor if they exist.
* They will then be populated into `process.env` as ISO strings.
*
* @param {Object} event - input object
*/
const configureTimestampEnvs = (event) => {
if (!process.env.endTimestamp && event.endTimestamp) {
const dateObj = new Date(event.endTimestamp);
if (Number.isNaN(dateObj.valueOf())) {
throw new TypeError(`endTimestamp ${event.endTimestamp} is not a valid input for new Date().`);
}
process.env.endTimestamp = dateObj.toISOString();
(record) => {
const execution = attr.unwrap(record.dynamodb.NewImage);
return publishSnsMessage(topicArn, execution);
}
);
const getCumulusMessageFromExecutionEvent = async (executionEvent) => {
let cumulusMessage;
if (executionEvent.detail.status === 'RUNNING') {
cumulusMessage = JSON.parse(executionEvent.detail.input);
} else if (executionEvent.detail.status === 'SUCCEEDED') {
cumulusMessage = JSON.parse(executionEvent.detail.output);
} else {
const inputMessage = JSON.parse(get(executionEvent, 'detail.input', '{}'));
cumulusMessage = await getFailedExecutionMessage(inputMessage);
}
const fullCumulusMessage = await pullStepFunctionEvent(cumulusMessage);
const workflowStatus = executionStatusToWorkflowStatus(executionEvent.detail.status);
set(fullCumulusMessage, 'meta.status', workflowStatus);
set(fullCumulusMessage, 'cumulus_meta.workflow_start_time', executionEvent.detail.startDate);
set(fullCumulusMessage, 'cumulus_meta.workflow_stop_time', executionEvent.detail.stopDate);
return fullCumulusMessage;
};