Skip to content

A platform for community discussion. Free, open, simple.

FIX: Destination prefix in S3 inventory configuration is incorrect

Vinoth Kannanba9cc83d4cf9
diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rb
index 3f069673b35..763f1d1e462 100644
--- a/lib/s3_inventory.rb
+++ b/lib/s3_inventory.rb
@@ -125,18 +125,13 @@ class S3Inventory
def inventory_configuration
filter_prefix = inventory_id
- destination_prefix = File.join(INVENTORY_PREFIX, inventory_id)
-
- if bucket_folder_path.present?
- filter_prefix = File.join(bucket_folder_path, filter_prefix)
- destination_prefix = File.join(bucket_folder_path, destination_prefix)
- end
+ filter_prefix = File.join(bucket_folder_path, filter_prefix) if bucket_folder_path.present?
{
destination: {
s3_bucket_destination: {
bucket: bucket_arn,
- prefix: destination_prefix,
+ prefix: inventory_path,
format: "CSV"
}
},
diff --git a/spec/jobs/update_s3_inventory_spec.rb b/spec/jobs/update_s3_inventory_spec.rb
index ec26f950b15..07241cea0b7 100644
--- a/spec/jobs/update_s3_inventory_spec.rb
+++ b/spec/jobs/update_s3_inventory_spec.rb
@@ -16,9 +16,11 @@ describe Jobs::UpdateS3Inventory do
it "updates the bucket policy and inventory configuration in S3" do
id = "original"
+ path = File.join(S3Inventory::INVENTORY_PREFIX, S3Inventory::INVENTORY_VERSION)
+
@client.expects(:put_bucket_policy).with(
bucket: "bucket",
- policy: "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"InventoryAndAnalyticsPolicy\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"s3.amazonaws.com\"},\"Action\":[\"s3:PutObject\"],\"Resource\":[\"arn:aws:s3:::bucket/#{S3Inventory::INVENTORY_PREFIX}/#{S3Inventory::INVENTORY_VERSION}/*\"],\"Condition\":{\"ArnLike\":{\"aws:SourceArn\":\"arn:aws:s3:::bucket\"},\"StringEquals\":{\"s3:x-amz-acl\":\"bucket-owner-full-control\"}}}]}"
+ policy: "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"InventoryAndAnalyticsPolicy\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"s3.amazonaws.com\"},\"Action\":[\"s3:PutObject\"],\"Resource\":[\"arn:aws:s3:::bucket/#{path}/*\"],\"Condition\":{\"ArnLike\":{\"aws:SourceArn\":\"arn:aws:s3:::bucket\"},\"StringEquals\":{\"s3:x-amz-acl\":\"bucket-owner-full-control\"}}}]}"
)
@client.expects(:put_bucket_inventory_configuration)
@client.expects(:put_bucket_inventory_configuration).with(
@@ -28,7 +30,7 @@ describe Jobs::UpdateS3Inventory do
destination: {
s3_bucket_destination: {
bucket: "arn:aws:s3:::bucket",
- prefix: "inventory/#{id}",
+ prefix: path,
format: "CSV"
}
},