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

feat: add newer_concurrent_versions option to put lifecycle #260

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions lib/ex_aws/s3.ex
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ defmodule ExAws.S3 do
},
noncurrent_version_expiration: %{
trigger: {:days, 2} # Only days based
newer_noncurrent_versions: 10
},
abort_incomplete_multipart_upload: %{
trigger: {:days, 2} # Only days based
Expand Down
8 changes: 7 additions & 1 deletion lib/ex_aws/s3/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ defmodule ExAws.S3.Utils do
},
noncurrent_version_expiration: %{
tag: "NoncurrentVersionExpiration",
action_tags: fn _data -> [] end
action_tags: fn
%{newer_noncurrent_versions: versions} ->
[["<NewerNoncurrentVersions>", "#{versions}", "</NewerNoncurrentVersions>"]]

_ ->
[]
end
},
abort_incomplete_multipart_upload: %{
tag: "AbortIncompleteMultipartUpload",
Expand Down
13 changes: 10 additions & 3 deletions test/lib/s3/utils_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,23 @@ defmodule ExAws.S3.ImplTest do
storage: ""
},
noncurrent_version_expiration: %{
trigger: {:days, 2}
trigger: {:days, 2},
newer_noncurrent_versions: 10
},
abort_incomplete_multipart_upload: %{
trigger: {:days, 2}
}
}
}

assert rule |> Utils.build_lifecycle_rule() ==
"<Rule><AbortIncompleteMultipartUpload><DaysAfterInitiation>2</DaysAfterInitiation></AbortIncompleteMultipartUpload><NoncurrentVersionExpiration><NoncurrentDays>2</NoncurrentDays></NoncurrentVersionExpiration><NoncurrentVersionTransition><NoncurrentDays>2</NoncurrentDays><StorageClass></StorageClass></NoncurrentVersionTransition><Expiration><Days>2</Days><ExpiredObjectDeleteMarker>true</ExpiredObjectDeleteMarker></Expiration><Transition><Days>2</Days><StorageClass></StorageClass></Transition><Filter><Prefix>prefix/</Prefix></Filter><Status>Enabled</Status><ID>123</ID></Rule>"
assert Utils.build_lifecycle_rule(rule) ==
Enum.join([
"<Rule><AbortIncompleteMultipartUpload><DaysAfterInitiation>2</DaysAfterInitiation></AbortIncompleteMultipartUpload>",
"<NoncurrentVersionExpiration><NoncurrentDays>2</NoncurrentDays><NewerNoncurrentVersions>10</NewerNoncurrentVersions></NoncurrentVersionExpiration>",
"<NoncurrentVersionTransition><NoncurrentDays>2</NoncurrentDays><StorageClass></StorageClass></NoncurrentVersionTransition>",
"<Expiration><Days>2</Days><ExpiredObjectDeleteMarker>true</ExpiredObjectDeleteMarker></Expiration>",
"<Transition><Days>2</Days><StorageClass></StorageClass></Transition><Filter><Prefix>prefix/</Prefix></Filter><Status>Enabled</Status><ID>123</ID></Rule>"
])
end

test "lifecycle rule with 0 day trigger" do
Expand Down