Skip to content

Commit

Permalink
syncing with saas
Browse files Browse the repository at this point in the history
  • Loading branch information
alphadev4 committed Nov 8, 2024
1 parent 90cff06 commit e8ac33c
Show file tree
Hide file tree
Showing 142 changed files with 3,416 additions and 1,003 deletions.
6 changes: 3 additions & 3 deletions collectors/aws/ecs/listContainerInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ module.exports = function(AWSConfig, collection, retries, callback) {
helpers.makeCustomCollectorCall(ecs, 'listContainerInstances', params, retries, null, null, null, function(err, data) {
if (err) {
collection.ecs.listContainerInstances[AWSConfig.region][cluster].err = err;
} else if (data && data.containerInstanceArns) {
collection.ecs.listContainerInstances[AWSConfig.region][cluster].data = data.containerInstanceArns;
}

collection.ecs.listContainerInstances[AWSConfig.region][cluster].data = data.containerInstanceArns;

cb();
});
}, function(){
callback();
});
};
};
5 changes: 3 additions & 2 deletions collectors/aws/ecs/listServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ module.exports = function(AWSConfig, collection, retries, callback) {
if (err) {
collection.ecs.listServices[AWSConfig.region][cluster].err = err;
}
if (data && data.serviceArns) collection.ecs.listServices[AWSConfig.region][cluster].data = data.serviceArns;

collection.ecs.listServices[AWSConfig.region][cluster].data = data.serviceArns;

cb();
});
}, function(){
callback();
});
};
};
6 changes: 2 additions & 4 deletions collectors/azure/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ let collect = function(AzureConfig, settings, callback) {
helpers.call({
url: localUrl,
post: obj.post,
token: obj.graph ? loginData.graphToken : (obj.vault ? loginData.vaultToken : loginData.token),
govcloud : AzureConfig.Govcloud
token: obj.graph ? loginData.graphToken : (obj.vault ? loginData.vaultToken : loginData.token)
}, function(err, data) {
if (err) return cb(err);

Expand Down Expand Up @@ -144,8 +143,7 @@ let collect = function(AzureConfig, settings, callback) {
function(cb) {
function processTopCall(collectionObj, service, subCallObj, subCallCb) {
processCall(subCallObj, function(processCallErr, processCallData) {
if (AzureConfig.Govcloud) helpers.addGovLocations(subCallObj, service, collectionObj, processCallErr, processCallData , skip_locations);
else helpers.addLocations(subCallObj, service, collectionObj, processCallErr, processCallData , skip_locations);
helpers.addLocations(subCallObj, service, collectionObj, processCallErr, processCallData , skip_locations);
subCallCb();
});
}
Expand Down
5 changes: 1 addition & 4 deletions config_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ module.exports = {
// application_id: process.env.AZURE_APPLICATION_ID || '',
// key_value: process.env.AZURE_KEY_VALUE || '',
// directory_id: process.env.AZURE_DIRECTORY_ID || '',
// subscription_id: process.env.AZURE_SUBSCRIPTION_ID || '',
// storage_connection: process.env.AZURE_STORAGE_CONNECTION || '',
// blob_container: process.env.AZURE_BLOB_CONTAINER || '',
// govcloud: process.env.AZURE_GOV_CLOUD || ''
// subscription_id: process.env.AZURE_SUBSCRIPTION_ID || ''
},
azure_remediate: {
// OPTION 1: If using a credential JSON file, enter the path below
Expand Down
41 changes: 2 additions & 39 deletions engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,6 @@ function runAuth(settings, remediateConfig, callback) {
});
} else callback();
}

async function uploadResultsToBlob(resultsObject, storageConnection, blobContainerName ) {
var azureStorage = require('@azure/storage-blob');

try {
const blobServiceClient = azureStorage.BlobServiceClient.fromConnectionString(storageConnection);
const containerClient = blobServiceClient.getContainerClient(blobContainerName);

// Check if the container exists, if not, create it
const exists = await containerClient.exists();
if (!exists) {
await containerClient.create();
console.log(`Container ${blobContainerName} created successfully.`);
}

const blobName = `results-${Date.now()}.json`;
const blockBlobClient = containerClient.getBlockBlobClient(blobName);

const data = JSON.stringify(resultsObject, null, 2);
const uploadBlobResponse = await blockBlobClient.upload(data, data.length);
console.log(`Blob ${blobName} uploaded successfully. Request ID: ${uploadBlobResponse.requestId}`);
} catch (error) {
if (error.message && error.message == 'Invalid DefaultEndpointsProtocol') {
console.log(`Invalid Storage Account connection string ${error.message}`);
} else {
console.log(`Failed to upload results to blob: ${error.message}`);
}
}
}

/**
* The main function to execute CloudSploit scans.
* @param cloudConfig The configuration for the cloud provider.
Expand Down Expand Up @@ -178,28 +148,23 @@ var engine = function(cloudConfig, settings) {
console.log('INFO: Analysis complete. Scan report to follow...');

var maximumStatus = 0;
var resultsObject = {}; // Initialize resultsObject for azure gov cloud


function executePlugins(cloudRemediateConfig) {
async.mapValuesLimit(plugins, 10, function(plugin, key, pluginDone) {
if (skippedPlugins.indexOf(key) > -1) return pluginDone(null, 0);

var postRun = function(err, results) {
if (err) return console.log(`ERROR: ${err}`);
if (!results || !results.length) {
console.log(`Plugin ${plugin.title} returned no results. There may be a problem with this plugin.`);
} else {
if (!resultsObject[plugin.title]) {
resultsObject[plugin.title] = [];
}
for (var r in results) {
// If we have suppressed this result, then don't process it
// so that it doesn't affect the return code.
if (suppressionFilter([key, results[r].region || 'any', results[r].resource || 'any'].join(':'))) {
continue;
}

resultsObject[plugin.title].push(results[r]);

var complianceMsg = [];
if (settings.compliance && settings.compliance.length) {
settings.compliance.forEach(function(c) {
Expand Down Expand Up @@ -259,8 +224,6 @@ var engine = function(cloudConfig, settings) {
}
}, function(err) {
if (err) return console.log(err);

if (cloudConfig.StorageConnection && cloudConfig.BlobContainer) uploadResultsToBlob(resultsObject, cloudConfig.StorageConnection, cloudConfig.BlobContainer);
// console.log(JSON.stringify(collection, null, 2));
outputHandler.close();
if (settings.exit_code) {
Expand Down
Loading

0 comments on commit e8ac33c

Please sign in to comment.