Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 25 additions & 3 deletions src/AWS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const aws_config = Ref{AbstractAWSConfig}()
"""
FeatureSet

Allows end users to opt-in to new breaking behaviors prior before a major/breaking package
Allows end users to opt-in to new breaking behaviors prior to a major/breaking package
release. Each field of this struct contains a default which specifies uses the original
non-breaking behavior.

Expand All @@ -61,10 +61,21 @@ non-breaking behavior.
call response typically be parsed but will vary depending on the following parameters:
"return_headers", "return_stream", "return_raw", "response_dict_type".
"""
Base.@kwdef struct FeatureSet
Base.@kwdef mutable struct FeatureSet
use_response_type::Bool = false
end

# Reset the given `FeatureSet` to have the features specified via keyword arguments.
# Notably, if no keyword arguments are provided, the `FeatureSet` is reset to defaults.
# This is used internally by `@service` when a module already exists.
function set_features!(fs::FeatureSet; kwargs...)
new = FeatureSet(; kwargs...)
for field in fieldnames(FeatureSet)
setfield!(fs, field, getfield(new, field))
end
return fs
end

"""
global_aws_config()

Expand Down Expand Up @@ -168,6 +179,9 @@ AWS.Response: application/xml interpreted as:
OrderedCollections.LittleDict{Union{String, Symbol}, Any, Vector{Union{String, Symbol}}, Vector{Any}} with 2 entries:
"GetCallerIdentityResult" => LittleDict{Union{String, Symbol}, Any, Vector{Un…
"ResponseMetadata" => LittleDict{Union{String, Symbol}, Any, Vector{Un…

julia> @service STS as SecurityTokenService # reset a feature to its default by calling `@service` again
SecurityTokenService
```

Service IDs are case insensitive:
Expand Down Expand Up @@ -225,8 +239,16 @@ macro service(exprs...)
const SERVICE_FEATURE_SET = FeatureSet(; $(features...))
include($service_file)
end
module_def = Expr(:toplevel, Expr(:module, true, esc(module_name), esc(module_block)))

service_module = :($__module__.$module_name)
reset_block = quote
$set_features!($service_module.SERVICE_FEATURE_SET; $(features...))
$service_module
end
check = :($(Core.isdefined)($__module__, $(QuoteNode(module_name))))

return Expr(:toplevel, Expr(:module, true, esc(module_name), esc(module_block)))
return Expr(:if, esc(check), esc(reset_block), module_def)
end

abstract type Service end
Expand Down
12 changes: 12 additions & 0 deletions test/unit/AWS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,16 @@
@test !(:STS in names(@__MODULE__; all=true))
@test !(Symbol("STS.X") in names(@__MODULE__; all=true))
end

@testset "module redefinition" begin
#! format: off
@eval baremodule __service_module_redefinition
using AWS, Test
@service S3 use_response_type = true
features = S3.SERVICE_FEATURE_SET
@service S3
@test features === S3.SERVICE_FEATURE_SET # ensures module wasn't replaced
Copy link
Member

Choose a reason for hiding this comment

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

I'm surprised that the containing testset captures this test.

Copy link
Member Author

Choose a reason for hiding this comment

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

¯\_(ツ)_/¯

end
#! format: on
end
end
Loading