Skip to content

Commit

Permalink
Define set_features for low-level API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
omus committed Sep 24, 2021
1 parent b4b7b64 commit cccc439
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/AWS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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()
Expand Down Expand Up @@ -135,19 +135,21 @@ macro service(module_name::Symbol, features...)
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 @@ -156,7 +158,7 @@ struct JSONService
target::String
end

struct RestJSONService
struct RestJSONService <: Service
signing_name::String
endpoint_prefix::String
api_version::String
Expand All @@ -170,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 @@ -375,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

0 comments on commit cccc439

Please sign in to comment.