Skip to content

Commit

Permalink
Try #457:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Sep 24, 2021
2 parents ca6b550 + cccc439 commit e1ae9a7
Show file tree
Hide file tree
Showing 285 changed files with 41,968 additions and 7,307 deletions.
44 changes: 35 additions & 9 deletions src/AWS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ export AbstractAWSConfig, AWSConfig, AWSExceptions, AWSServices, Request
export ec2_instance_metadata, ec2_instance_region
export generate_service_url, global_aws_config, set_user_agent
export sign!, sign_aws2!, sign_aws4!
export JSONService, RestJSONService, RestXMLService, QueryService
export JSONService, RestJSONService, RestXMLService, QueryService, set_features

const DEFAULT_REGION = "us-east-1"
const DEFAULT_SERVICE_FEATURES = NamedTuple()

include(joinpath("utilities", "utilities.jl"))

Expand Down Expand Up @@ -122,27 +123,33 @@ using AWS: @service
# Return
- `Expression`: Base.include() call to introduce the high-level service API wrapper functions in your namespace
"""
macro service(module_name::Symbol)
macro service(module_name::Symbol, features...)
service_name = joinpath(@__DIR__, "services", lowercase(string(module_name)) * ".jl")
service_features = _process_service_features(features, DEFAULT_SERVICE_FEATURES)

return Expr(:toplevel, :(module ($(esc(module_name)))
Base.include($(esc(module_name)), $(esc(service_name)))
end))
module_block = quote
const SERVICE_FEATURES = $service_features
include($service_name)
end

return Expr(:toplevel, Expr(:module, true, esc(module_name), esc(module_block)))
end

struct RestXMLService
abstract type Service end

struct RestXMLService <: Service
signing_name::String
endpoint_prefix::String
api_version::String
end

struct QueryService
struct QueryService <: Service
signing_name::String
endpoint_prefix::String
api_version::String
end

struct JSONService
struct JSONService <: Service
signing_name::String
endpoint_prefix::String
api_version::String
Expand All @@ -151,7 +158,7 @@ struct JSONService
target::String
end

struct RestJSONService
struct RestJSONService <: Service
signing_name::String
endpoint_prefix::String
api_version::String
Expand All @@ -165,6 +172,16 @@ function RestJSONService(signing_name::String, endpoint_prefix::String, api_vers
)
end

struct ServiceWrapper{S<:Service}
service::S
features::NamedTuple
end

function set_features(service::Service; features...)
features = merge(DEFAULT_SERVICE_FEATURES, features)
return ServiceWrapper(service, features)
end

# Needs to be included after the definition of struct otherwise it cannot find them
include("AWSServices.jl")

Expand Down Expand Up @@ -207,6 +224,7 @@ function (service::RestXMLService)(
request_uri::String,
args::AbstractDict{String,<:Any}=Dict{String,Any}();
aws_config::AbstractAWSConfig=global_aws_config(),
features::NamedTuple=DEFAULT_SERVICE_FEATURES,
)
return_headers = _pop!(args, "return_headers", false)

Expand Down Expand Up @@ -259,6 +277,7 @@ function (service::QueryService)(
operation::String,
args::AbstractDict{String,<:Any}=Dict{String,Any}();
aws_config::AbstractAWSConfig=global_aws_config(),
features::NamedTuple=DEFAULT_SERVICE_FEATURES,
)
POST_RESOURCE = "/"
return_headers = _pop!(args, "return_headers", false)
Expand Down Expand Up @@ -301,6 +320,7 @@ function (service::JSONService)(
operation::String,
args::AbstractDict{String,<:Any}=Dict{String,Any}();
aws_config::AbstractAWSConfig=global_aws_config(),
features::NamedTuple=DEFAULT_SERVICE_FEATURES,
)
POST_RESOURCE = "/"
return_headers = _pop!(args, "return_headers", false)
Expand Down Expand Up @@ -343,6 +363,7 @@ function (service::RestJSONService)(
request_uri::String,
args::AbstractDict{String,<:Any}=Dict{String,String}();
aws_config::AbstractAWSConfig=global_aws_config(),
features::NamedTuple=DEFAULT_SERVICE_FEATURES,
)
return_headers = _pop!(args, "return_headers", false)

Expand All @@ -366,6 +387,11 @@ function (service::RestJSONService)(
return submit_request(aws_config, request; return_headers=return_headers)
end

function (service::ServiceWrapper)(args...; features::NamedTuple=NamedTuple(), kwargs...)
features = merge(service.features, features)
return service.service(args...; features=features, kwargs...)
end

function __init__()
DEFAULT_BACKEND[] = HTTPBackend()
return nothing
Expand Down
36 changes: 18 additions & 18 deletions src/api_generation/high_level.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,28 +144,28 @@ function _generate_high_level_definition(

if required_keys && (idempotent || headers)
return """
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", $params_headers_str; aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", Dict{String, Any}(mergewith(_merge, $params_headers_str, params)); aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", $params_headers_str; aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", Dict{String, Any}(mergewith(_merge, $params_headers_str, params)); aws_config=aws_config, features=SERVICE_FEATURES)
"""
elseif !required_keys && (idempotent || headers)
return """
$formatted_function_name(; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", $params_headers_str; aws_config=aws_config)
$formatted_function_name(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", Dict{String, Any}(mergewith(_merge, $params_headers_str, params)); aws_config=aws_config)
$formatted_function_name(; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", $params_headers_str; aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", Dict{String, Any}(mergewith(_merge, $params_headers_str, params)); aws_config=aws_config, features=SERVICE_FEATURES)
"""
elseif required_keys && !isempty(req_kv)
return """
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", $req_str); aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", Dict{String, Any}(mergewith(_merge, $req_str), params)); aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", $req_str); aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", Dict{String, Any}(mergewith(_merge, $req_str), params)); aws_config=aws_config, features=SERVICE_FEATURES)
"""
elseif required_keys
return """
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\"; aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", params; aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\"; aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", params; aws_config=aws_config, features=SERVICE_FEATURES)
"""
else
return """
$formatted_function_name(; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\"; aws_config=aws_config)
$formatted_function_name(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", params; aws_config=aws_config)
$formatted_function_name(; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\"; aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$method\", \"$request_uri\", params; aws_config=aws_config, features=SERVICE_FEATURES)
"""
end
end
Expand Down Expand Up @@ -193,23 +193,23 @@ function _generate_high_level_definition(

if required && idempotent
return """
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}($(join(req_kv, ", ")), $(join(idempotent_kv, ", "))); aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}(mergewith(_merge, Dict{String, Any}($(join(req_kv, ", ")), $(join(idempotent_kv, ", "))), params)); aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}($(join(req_kv, ", ")), $(join(idempotent_kv, ", "))); aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}(mergewith(_merge, Dict{String, Any}($(join(req_kv, ", ")), $(join(idempotent_kv, ", "))), params)); aws_config=aws_config, features=SERVICE_FEATURES)
"""
elseif required
return """
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}($(join(req_kv, ", "))); aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}(mergewith(_merge, Dict{String, Any}($(join(req_kv, ", "))), params)); aws_config=aws_config)
$formatted_function_name($(join(req_keys, ", ")); aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}($(join(req_kv, ", "))); aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name($(join(req_keys, ", ")), params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}(mergewith(_merge, Dict{String, Any}($(join(req_kv, ", "))), params)); aws_config=aws_config, features=SERVICE_FEATURES)
"""
elseif idempotent
return """
$formatted_function_name(; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}($(join(idempotent_kv, ", "))); aws_config=aws_config)
$formatted_function_name(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}(mergewith(_merge, Dict{String, Any}($(join(idempotent_kv, ", "))), params)); aws_config=aws_config)
$formatted_function_name(; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}($(join(idempotent_kv, ", "))); aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", Dict{String, Any}(mergewith(_merge, Dict{String, Any}($(join(idempotent_kv, ", "))), params)); aws_config=aws_config, features=SERVICE_FEATURES)
"""
else
return """
$formatted_function_name(; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\"; aws_config=aws_config)
$formatted_function_name(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", params; aws_config=aws_config)
$formatted_function_name(; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\"; aws_config=aws_config, features=SERVICE_FEATURES)
$formatted_function_name(params::AbstractDict{String}; aws_config::AbstractAWSConfig=global_aws_config()) = $service_name(\"$function_name\", params; aws_config=aws_config, features=SERVICE_FEATURES)
"""
end
end
Expand Down
Loading

0 comments on commit e1ae9a7

Please sign in to comment.