Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} = params;
// Create the record in the database
const id = uuidv4();
await this.create({
id,
status: 'RUNNING',
description,
operationType
});
// Store the payload to S3
const payloadBucket = this.systemBucket;
const payloadKey = `${this.stackName}/async-operation-payloads/${id}.json`;
await s3().putObject({
Bucket: payloadBucket,
Key: payloadKey,
Body: JSON.stringify(payload)
}).promise();
// Start the task in ECS
const runTaskResponse = await ecs().runTask({
cluster,
taskDefinition: asyncOperationTaskDefinition,
launchType: 'EC2',
overrides: {
containerOverrides: [
{
name: 'AsyncOperation',
environment: [
{ name: 'asyncOperationId', value: id },
};
}
const stagingDir = granule.files[0].fileStagingDir;
const filename = `${stagingDir}/${granule.granuleId}.cmr.json`;
const params = {
Bucket: bucket,
Key: filename,
Body: JSON.stringify(jsonObject),
ContentType: 'application/json',
Tagging: `granuleId=${granule.granuleId}`
};
await s3().putObject(params).promise();
const granuleFiles = granule.files.map((f) => f.filename);
granuleFiles.push(`s3://${bucket}/${filename}`);
log.info(`s3://${bucket}/${filename}`);
log.info(granuleFiles);
return granuleFiles;
}
function getConfigurations() {
const earthdataLoginClient = EarthdataLogin.createFromEnv({
redirectUri: process.env.DISTRIBUTION_REDIRECT_ENDPOINT
});
return {
accessTokenModel: new AccessToken(),
authClient: earthdataLoginClient,
distributionUrl: process.env.DISTRIBUTION_ENDPOINT,
s3Client: s3()
};
}
function fetchPdr(bucket, key) {
return aws.s3().getObject({ Bucket: bucket, Key: key }).promise()
.then((response) => response.Body.toString());
}
async function prepareServices(stackName, bucket) {
setLocalEsVariables(stackName);
await bootstrap.bootstrapElasticSearch(process.env.ES_HOST, process.env.ES_INDEX);
await s3().createBucket({ Bucket: bucket }).promise();
}
function getConfigurations() {
const earthdataLoginClient = EarthdataLogin.createFromEnv({
redirectUri: process.env.DISTRIBUTION_REDIRECT_ENDPOINT
});
return {
accessTokenModel: new AccessToken(),
authClient: earthdataLoginClient,
distributionUrl: process.env.DISTRIBUTION_ENDPOINT,
s3Client: s3()
};
}
async function get(req, res) {
const [Bucket, Key] = getFileBucketAndKey(req.params[0]);
return s3().getObject({ Bucket, Key })
.on('httpHeaders', (code, headers) => {
res.set('Content-Type', headers['content-type']);
})
.createReadStream()
.pipe(res);
}
async function countLock(bucket, pName) {
const list = aws.s3().listObjectsV2({
Bucket: bucket,
Prefix: `${lockPrefix}/${pName}`
}).promise();
const count = checkOldLocks(bucket, list.Contents);
return count;
}
function uploadTestDataToS3(file, bucket) {
const data = fs.readFileSync(require.resolve(file), 'utf8');
const key = path.basename(file);
return s3().putObject({
Bucket: bucket,
Key: `cumulus-test-data/pdrs/${key}`,
Body: data
}).promise();
}