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 13 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: Add constructor for constructing `S3Path` from another `S3Path` ([#297]).
hannahilea marked this conversation as resolved.
Show resolved Hide resolved

[#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
11 changes: 8 additions & 3 deletions src/s3path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ end

"""
S3Path()
S3Path(str; version::$(AbstractS3Version)=nothing, config::$(AbstractS3PathConfig)=nothing)
S3Path(str::AbstractString; version::$(AbstractS3Version)=nothing, config::$(AbstractS3PathConfig)=nothing)
S3Path(path::S3Path; isdirectory=path.isdirectory, version=path.version, config=path.config)

Construct a new AWS S3 path type which should be of the form
`"s3://<bucket>/prefix/to/my/object"`.
Expand All @@ -73,8 +74,6 @@ NOTES:
"""
S3Path() = S3Path((), "/", "", true, nothing, nothing)

S3Path(path::S3Path) = path

# below definition needed by FilePathsBase
S3Path{A}() where {A<:AbstractS3PathConfig} = S3Path()

Expand Down Expand Up @@ -107,6 +106,12 @@ function S3Path(
)
end

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

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

@testset "construct s3path from s3path" begin
hannahilea marked this conversation as resolved.
Show resolved Hide resolved
# Use custom config to test that config is preserved in construction
config = AWSConfig(; region="bogus")
path = S3Path("s3://my_bucket/prefix"; config)

# When no kwargs provided, return identity
@test S3Path(path) === path

# version kwarg overrides path.version
version = String('A':'Z') * String('0':'5')
path_versioned = S3Path(path; version)
@test path_versioned.version == version
@test path_versioned == S3Path("s3://my_bucket/prefix"; version)
omus marked this conversation as resolved.
Show resolved Hide resolved
@test path_versioned.config == path.config == config

# ...if version already exists, overwrite silently
version2 = String('0':'5') * String('A':'Z')
@test S3Path(path_versioned; version=version2).version == version2 != version

# config kwarg overrides path.config
config2 = AWSConfig(; region="foo")
@test S3Path(path; config=config2).config == config2 != path.config
@test isnothing(S3Path(path; config=nothing).config)

# isdirectory kwarg overrides path.config
@test S3Path(path; isdirectory=!path.isdirectory) != path.isdirectory
hannahilea marked this conversation as resolved.
Show resolved Hide resolved
end

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