Skip to content

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

FIX: inconsistency in S3 inventory config (#11112)

Penar Musaraj9f6c4ad71a26
diff --git a/lib/s3_inventory.rb b/lib/s3_inventory.rb
index 943ebca9fa4..7114660ebed 100644
--- a/lib/s3_inventory.rb
+++ b/lib/s3_inventory.rb
@@ -270,7 +270,7 @@ class S3Inventory
def inventory_configuration
filter_prefix = type
- filter_prefix = File.join(bucket_folder_path, filter_prefix) if bucket_folder_path.present?
+ filter_prefix = bucket_folder_path if bucket_folder_path.present?
{
destination: {
diff --git a/spec/components/s3_inventory_spec.rb b/spec/components/s3_inventory_spec.rb
index 405a9e05b0d..a31efcdfccd 100644
--- a/spec/components/s3_inventory_spec.rb
+++ b/spec/components/s3_inventory_spec.rb
@@ -187,4 +187,25 @@ describe "S3Inventory" do
expect(db2.lines.count).to eq(1)
files.values.each { |f| f.close; f.unlink }
end
+
+ context "s3 inventory configuration" do
+ let(:bucket_name) { "s3-upload-bucket" }
+ let(:subfolder_path) { "subfolder" }
+ before do
+ SiteSetting.s3_upload_bucket = "#{bucket_name}/#{subfolder_path}"
+ end
+
+ it "is formatted correctly for subfolders" do
+ s3_helper = S3Helper.new(SiteSetting.Upload.s3_upload_bucket.downcase, "", client: client)
+ config = S3Inventory.new(s3_helper, :upload).send(:inventory_configuration)
+
+ expect(config[:destination][:s3_bucket_destination][:bucket]).to eq("arn:aws:s3:::#{bucket_name}")
+ expect(config[:destination][:s3_bucket_destination][:prefix]).to eq("#{subfolder_path}/inventory/1")
+ expect(config[:id]).to eq("#{subfolder_path}-original")
+ expect(config[:schedule][:frequency]).to eq("Daily")
+ expect(config[:included_object_versions]).to eq("Current")
+ expect(config[:optional_fields]).to eq(["ETag"])
+ expect(config[:filter][:prefix]).to eq(subfolder_path)
+ end
+ end
end