Skip to content

Commit

Permalink
Merge branch 'master' into hr/constructor-s3path
Browse files Browse the repository at this point in the history
  • Loading branch information
omus authored Jun 30, 2023
2 parents b2d57c7 + e603239 commit 6a4a5de
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

- 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: `s3_copy` supports the `parse_response` keyword allowing for access to the unparsed AWS API response ([#300]).
- v0.11.2: Add `S3Path` copy constructor for allowing updating `version`, `config`, and/or `isdirectory` ([#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
[#300]: https://github.com/JuliaCloud/AWSS3.jl/pull/300
39 changes: 27 additions & 12 deletions src/AWSS3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,27 @@ end
s3_delete(a...; b...) = s3_delete(global_aws_config(), a...; b...)

"""
s3_copy([::AbstractAWSConfig], bucket, path; to_bucket=bucket, to_path=path, kwargs...)
s3_copy([::AbstractAWSConfig], bucket, path; acl::AbstractString="",
to_bucket=bucket, to_path=path, metadata::AbstractDict=SSDict(),
parse_response::Bool=true, kwargs...)
[PUT Object - Copy](http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html)
Copy the object at `path` in `bucket` to `to_path` in `to_bucket`.
# Optional Arguments
- `metadata::Dict=`; optional `x-amz-meta-` headers.
- `acl=`; `x-amz-acl` header for setting access permissions with canned config.
See [here](https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl).
- `metadata::Dict=`; `x-amz-meta-` headers.
- `parse_response::Bool=`; when `false`, return raw `AWS.Response`
- `kwargs`; additional kwargs passed through into `S3.copy_object`
# API Calls
- [`CopyObject`](http://https://docs.aws.amazon.com/AmazonS3/latest/API/API_CopyObject.html)
# Permissions
- [`s3:PutObject`](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html#amazons3-PutObject)
- [`s3:GetObject`](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazons3.html#amazons3-GetObject)
"""
function s3_copy(
aws::AbstractAWSConfig,
Expand All @@ -426,6 +441,7 @@ function s3_copy(
to_bucket=bucket,
to_path=path,
metadata::AbstractDict=SSDict(),
parse_response::Bool=true,
kwargs...,
)
headers = SSDict(
Expand All @@ -437,16 +453,15 @@ function s3_copy(
headers["x-amz-acl"] = acl
end

return parse(
S3.copy_object(
to_bucket,
to_path,
"$bucket/$path",
Dict("headers" => headers);
aws_config=aws,
kwargs...,
),
response = S3.copy_object(
to_bucket,
to_path,
"$bucket/$path",
Dict("headers" => headers);
aws_config=aws,
kwargs...,
)
return parse_response ? parse(response) : response
end

s3_copy(a...; b...) = s3_copy(global_aws_config(), a...; b...)
Expand Down
19 changes: 18 additions & 1 deletion test/awss3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,25 @@ function awss3_tests(base_config)

@testset "Object Copy" begin
config = assume_testset_role("ReadWriteObject"; base_config)
s3_copy(bucket_name, "key1"; to_bucket=bucket_name, to_path="key1.copy")
result = s3_copy(
config, bucket_name, "key1"; to_bucket=bucket_name, to_path="key1.copy"
)
@test result isa AbstractDict
@test s3_get(config, bucket_name, "key1.copy") == b"data1.v1"

result = s3_copy(
config,
bucket_name,
"key1";
to_bucket=bucket_name,
to_path="key1.copy",
parse_response=false,
)
@test result isa AWS.Response

if is_aws(base_config)
@test !isnothing(HTTP.header(result.headers, "x-amz-version-id", nothing))
end
end

@testset "Object exists" begin
Expand Down

0 comments on commit 6a4a5de

Please sign in to comment.