Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deal with buckets being collected from multiple regions #80

Merged
merged 1 commit into from
Apr 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions app/collectors/bucket.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ case class AWSBucketCollector(origin: AmazonOrigin, resource: ResourceType) exte

def crawl: Iterable[Bucket] = {
val request = new ListBucketsRequest()
client.listBuckets(request).asScala.flatMap {
Bucket.fromApiData(_, client)
}
client.listBuckets(request).asScala
.flatMap {
Bucket.fromApiData(_, client)
}
}
}

Expand All @@ -43,14 +44,20 @@ object Bucket {
def fromApiData(bucket: AWSBucket, client: AmazonS3): Option[Bucket] = {
val bucketName = bucket.getName
try {
Some(Bucket(
arn = arn(bucketName),
name = bucketName,
region = client.getBucketLocation(bucket.getName),
createdTime = Try(new DateTime(bucket.getCreationDate)).toOption
))
val bucketRegion = client.getBucketLocation(bucket.getName)
if (bucketRegion == client.getRegionName) {
Some(Bucket(
arn = arn(bucketName),
name = bucketName,
region = bucketRegion,
createdTime = Try(new DateTime(bucket.getCreationDate)).toOption
))
} else {
None
}
} catch {
case e:AmazonS3Exception if e.getErrorCode == "NoSuchBucket" => None
case e:AmazonS3Exception if e.getErrorCode == "AuthorizationHeaderMalformed" => None
case NonFatal(t) =>
throw new IllegalStateException(s"Failed when building info for bucket $bucketName", t)
}
Expand Down