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

Add S3Path constructor that takes in S3Path and version #297

Merged
merged 18 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- v0.11.0: The `s3_exists` and `isdir(::S3Path)` calls no longer encounter HTTP 403 (Access Denied) errors when attempting to list resources which requiring an `s3:prefix` to be specified ([#289]).
- v0.11.1: The new keyword argument `returns` for `Base.write(fp::S3Path, ...)` determines the output returned from `write`, which can now be the raw `AWS.Response` (`returns=:response`) or the `S3Path` (`returns=:path`); this latter option returns an `S3Path` populated with the version ID of the written object (when versioning is enabled on the bucket) ([#293]).
- v0.11.2: New constructor for unversioned `S3Path` and version: `S3Path(path::S3Path; version=...)` ([#297]).

[#289]: https://github.com/JuliaCloud/AWSS3.jl/pull/289
[#293]: https://github.com/JuliaCloud/AWSS3.jl/pull/293
[#297]: https://github.com/JuliaCloud/AWSS3.jl/pull/297
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "AWSS3"
uuid = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
version = "0.11.1"
version = "0.11.2"

[deps]
AWS = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc"
Expand Down
12 changes: 12 additions & 0 deletions src/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ end

"""
S3Path()
S3Path(path::S3Path; version::$(AbstractS3Version))
S3Path(str; version::$(AbstractS3Version)=nothing, config::$(AbstractS3PathConfig)=nothing)
hannahilea marked this conversation as resolved.
Show resolved Hide resolved

Construct a new AWS S3 path type which should be of the form
Expand Down Expand Up @@ -107,6 +108,17 @@ function S3Path(
)
end

function S3Path(path::S3Path; version::AbstractS3Version)
if !isnothing(path.version)
throw(
ArgumentError(
"Can't construct versioned path, input already specifies version: $path"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not allow the keyword version to overwrite the version of the S3Path silently? Should probably document the rational for this as part of the docstring

),
)
end
return S3Path(path.bucket, path.key; path.isdirectory, path.config, version)
end

# To avoid a breaking change.
function S3Path(
str::AbstractString;
Expand Down
17 changes: 17 additions & 0 deletions test/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,23 @@ function s3path_tests(base_config)
@test_throws ArgumentError S3Path("s3://my_bucket/"; version="")
end

@testset "construct versioned s3path from unversioned s3path" begin
# Use custom config to test that config is preserved in construction
config = AWSConfig(; region="bogus")
ver = String('A':'Z') * String('0':'5')

unversioned = S3Path("s3://my_bucket/prefix"; config)
@test unversioned.version === nothing

versioned = S3Path(unversioned; version=ver)
@test versioned.version == ver
@test versioned == S3Path("s3://my_bucket/prefix"; version=ver)
@test versioned.config == unversioned.config == config

# If input path already has a version, fail---even if the versions are the same
@test_throws ArgumentError S3Path(versioned; version=ver)
end

# `s3_list_versions` gives `SignatureDoesNotMatch` exceptions on Minio
if is_aws(base_config)
@testset "S3Path versioning" begin
Expand Down