Skip to content

Commit

Permalink
Clang-format on new files
Browse files Browse the repository at this point in the history
  • Loading branch information
nielm committed Nov 24, 2023
1 parent cf90cce commit f9f642c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
31 changes: 13 additions & 18 deletions cloudrun-malware-scanner/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Config = null;
const storage = new Storage({userAgent: `${pkgJson.name}/${pkgJson.version}`});

/**
* Read configuration from JSON configuration file, verify
* Read configuration from JSON configuration file, verify
* and return a Config object
*
* @async
Expand All @@ -58,9 +58,7 @@ async function readAndVerifyConfig(configFile) {
config = require(configFile);
delete config.comments;
} catch (e) {
logger.fatal(
{err: e},
`Unable to read JSON file from ${configFile}`);
logger.fatal({err: e}, `Unable to read JSON file from ${configFile}`);
throw new Error(`Invalid configuration ${configFile}`);
}

Expand All @@ -69,17 +67,16 @@ async function readAndVerifyConfig(configFile) {
throw new Error('No buckets configured');
}

logger.info('BUCKET_CONFIG: '+JSON.stringify(config, null, 2));
logger.info('BUCKET_CONFIG: ' + JSON.stringify(config, null, 2));

// Check buckets are specified and exist.
let success = true;
for (let x = 0; x < config.buckets.length; x++) {
const buckets = config.buckets[x];
for (const bucketType of ['unscanned', 'clean', 'quarantined']) {
if ( !(await checkBucketExists(
buckets[bucketType],
`config.buckets[${x}].${bucketType}`))) {
success=false;
if (!(await checkBucketExists(
buckets[bucketType], `config.buckets[${x}].${bucketType}`))) {
success = false;
}
}
if (buckets.unscanned === buckets.clean ||
Expand All @@ -90,10 +87,9 @@ async function readAndVerifyConfig(configFile) {
success = false;
}
}
if ( !(await checkBucketExists(
config.ClamCvdMirrorBucket,
'ClamCvdMirrorBucket'))) {
success=false;
if (!(await checkBucketExists(
config.ClamCvdMirrorBucket, 'ClamCvdMirrorBucket'))) {
success = false;
}

if (!success) {
Expand All @@ -120,13 +116,12 @@ async function checkBucketExists(bucketName, configName) {
// This is used in place of Bucket.exists() to avoid the need for
// Project/viewer permission.
try {
await storage.bucket(bucketName).getFiles(
{maxResults: 1, prefix: 'zzz', autoPaginate: false});
await storage.bucket(bucketName)
.getFiles({maxResults: 1, prefix: 'zzz', autoPaginate: false});
return true;
} catch (e) {
logger.fatal(
`Error in config: cannot view files in "${
configName}" : ${bucketName} : ${e.message}`);
logger.fatal(`Error in config: cannot view files in "${configName}" : ${
bucketName} : ${e.message}`);
logger.debug({err: e});
return false;
}
Expand Down
7 changes: 3 additions & 4 deletions cloudrun-malware-scanner/gcs-proxy-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const googleAuth = new GoogleAuth();

// access token for GCS requests - will be refreshed every 50 mins
let accessToken;
const ACCESS_TOKEN_REFRESH_INTERVAL = 50*60*1000;
const ACCESS_TOKEN_REFRESH_INTERVAL = 50 * 60 * 1000;

/**
* Set up a reverse proxy to add authentication to HTTP requests from
Expand Down Expand Up @@ -56,7 +56,7 @@ async function setupGcsReverseProxy(clamCvdMirrorBucket) {
statusCode = res.statusCode;
}
logger.error(`Failed to proxy to GCS for path ${req.url}, returning code ${
statusCode}: ${err}`);
statusCode}: ${err}`);
res.writeHead(statusCode, {
'Content-Type': 'text/plain',
});
Expand All @@ -65,8 +65,7 @@ async function setupGcsReverseProxy(clamCvdMirrorBucket) {

// Add auth header/
proxy.on('proxyReq', function(proxyReq, req, res) {
if (proxyReq.path.startsWith(
'/' + clamCvdMirrorBucket + '/')) {
if (proxyReq.path.startsWith('/' + clamCvdMirrorBucket + '/')) {
logger.info(`Proxying request for ${proxyReq.path} to GCS`);
proxyReq.setHeader('Authorization', 'Bearer ' + accessToken);
} else {
Expand Down

0 comments on commit f9f642c

Please sign in to comment.