async function checkBucketExists()

in cloudrun-malware-scanner/config.ts [271:296]


async function checkBucketExists(
  bucketName: string,
  configName: string,
  storage: Storage,
): Promise<boolean> {
  if (!bucketName) {
    logger.fatal(`Config Error: no "${configName}" bucket defined`);
    return false;
  }
  // Check for bucket existence by listing files in bucket, will throw
  // an exception if the bucket is not readable.
  // 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});
    return true;
  } catch (e) {
    logger.fatal(
      `Error in config: cannot view files in "${configName}" : ${bucketName} : ${e as Error}`,
    );
    logger.debug({err: e});
    return false;
  }
}