-
Notifications
You must be signed in to change notification settings - Fork 68
Auto-generate low/high level AWS wrappers #121
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d2462f6
Added dependencies to the Project.toml
mattBrzezinski fbdd690
Ignoring .DS_STORE
mattBrzezinski 00d95ab
Generate AWS Services in Julia code
mattBrzezinski 2af1ec8
Initial generation of AWS Services
mattBrzezinski 5b77167
Added unit testing
mattBrzezinski 46d6434
Added compat, extras, and targets section to Project.toml
mattBrzezinski d1e2b96
Don't export internal functions in AWSMetadataUtilities.jl
mattBrzezinski 24cd716
Added trailing white space, fixed typo, removed mutable from request …
mattBrzezinski 1fa65dc
Addressed CR comments from @omus
mattBrzezinski d6166d1
Re-generated API wrappers
mattBrzezinski f1292ae
Re-arranged include, using, export
mattBrzezinski 6004613
Addressed more CR feedback from @omus
mattBrzezinski 35eb499
Set OrderedCollections to 1
mattBrzezinski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| Manifest.toml | ||
| .idea/* | ||
| .idea/* | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| name = "AWS" | ||
| uuid = "fbe9abb3-538b-5e4e-ba9e-bc94f4f92ebc" | ||
| license = "MIT" | ||
| version = "1.0.0" | ||
| version = "1.0.0" | ||
|
|
||
| [deps] | ||
| AWSCore = "4f1ea46c-232b-54a6-9b17-cc2d0f3e6598" | ||
| DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | ||
| HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3" | ||
| JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" | ||
| SymDict = "2da68c74-98d7-5633-99d6-8493888d7b1e" | ||
| Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| module AWS | ||
|
|
||
| include("AWSMetadataUtilities.jl") | ||
|
|
||
| export @service, AWSServices, RestJSONService, JSONService, RestXMLService, QueryService | ||
|
|
||
| using AWSCore | ||
| using SymDict | ||
|
|
||
| macro service(module_name::Symbol) | ||
| service_name = "services/" * lowercase(string(module_name)) * ".jl" | ||
| service_name = joinpath(@__DIR__, service_name) | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
|
|
||
| return Expr(:toplevel, | ||
| :(module ($(esc(module_name))) | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
| Base.include($(esc(module_name)), $(esc(service_name))) | ||
| end)) | ||
| end | ||
|
|
||
| mutable struct RestXMLService | ||
| name::String | ||
| api_version::String | ||
| end | ||
|
|
||
| mutable struct QueryService | ||
| name::String | ||
| api_version::String | ||
| end | ||
|
|
||
| mutable struct JSONService | ||
| name::String | ||
| api_version::String | ||
|
|
||
| json_version::String | ||
| target::String | ||
| end | ||
|
|
||
| mutable struct RestJSONService | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
| name::String | ||
| api_version::String | ||
| end | ||
|
|
||
| function (service::RestXMLService)(aws::AWSConfig, request_method::String, request_uri::String, args=[]) | ||
| return AWSCore.service_rest_xml( | ||
| aws; | ||
| service=service.name, | ||
| version=service.api_version, | ||
| verb=request_method, | ||
| resource=request_uri, | ||
| args=args | ||
| ) | ||
| end | ||
| (service::RestXMLService)(request_method::String, request_uri::String, args=[]) = service(default_aws_config(), request_method, request_uri, args) | ||
| (service::RestXMLService)(a...; b...) = service(a..., b) | ||
|
|
||
| function (service::QueryService)(aws::AWSConfig, operation, args=[]) | ||
| return AWSCore.service_query( | ||
| aws; | ||
| service=service.name, | ||
| version=service.api_version, | ||
| operation=operation, | ||
| args=args | ||
| ) | ||
| end | ||
| (service::QueryService)(operation, args=[]) = service(default_aws_config(), operation, args) | ||
| (service::QueryService)(a...; b...) = service(a..., b) | ||
|
|
||
| function (service::JSONService)(aws::AWSConfig, operation, args=[]) | ||
| return AWSCore.service_json( | ||
| aws; | ||
| service=service.name, | ||
| version=service.api_version, | ||
| json_version=service.json_version, | ||
| target=service.target, | ||
| operation=operation, | ||
| args=args | ||
| ) | ||
| end | ||
| (service::JSONService)(operation, args=[]) = service(default_aws_config(), operation, args) | ||
| (service::JSONService)(a...; b...) = service(a..., b) | ||
|
|
||
| function (service::RestJSONService)(aws::AWSConfig, request_method::String, request_uri::String, args=[]) | ||
| return AWSCore.service_rest_json( | ||
| aws; | ||
| service=service.name, | ||
| version=service.api_version, | ||
| verb=request_method, | ||
| resource=request_uri, | ||
| args=args | ||
| ) | ||
| end | ||
| (service::RestJSONService)(request_method::String, request_uri::String, args=[]) = service(default_aws_config(), request_method, request_uri, args) | ||
| (service::RestJSONService)(a...; b...) = service(a..., b) | ||
|
|
||
| end # module AWS | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| module AWSExceptions | ||
|
|
||
| export ProtocolNotDefined, InvalidFileName | ||
|
|
||
| struct ProtocolNotDefined <: Exception | ||
| message::String | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
| end | ||
| show(io::IO, e::ProtocolNotDefined) = println(io, e.message) | ||
|
|
||
| struct InvalidFileName <: Exception | ||
| message::String | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
| end | ||
| show(io::IO, e::InvalidFileName) = println(io, e.message) | ||
|
|
||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| module AWSMetadata | ||
|
|
||
| using DataStructures: OrderedDict | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
| using HTTP | ||
| using JSON | ||
|
|
||
| include("AWSMetadataUtilities.jl") | ||
|
|
||
| function parse_aws_metadata() | ||
| function _process_service(file::OrderedDict{String, Any}, version::String) | ||
| data_changed = true | ||
| push!(metadata, file["name"] => Dict("version" => version, "sha" => file["sha"])) | ||
| push!(services_modified, file) | ||
| end | ||
|
|
||
| metadata_path = joinpath(@__DIR__, "metadata.json") | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
| metadata = JSON.parsefile(metadata_path, dicttype=OrderedDict) | ||
|
|
||
| files = AWSMetadataUtilities._get_aws_sdk_js_files() | ||
|
|
||
| data_changed = false | ||
| services_modified = OrderedDict[] | ||
|
|
||
| for file in files | ||
| service_name, version = AWSMetadataUtilities._get_service_and_version(file["name"]) | ||
| filename = file["name"] | ||
|
|
||
| # AWS has released a new service API | ||
| if !haskey(metadata, filename) | ||
| println(service_name, " does not exist in metadata.") | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
| _process_service(file, version) | ||
| else | ||
| # Check if the service API has changed since the last run | ||
| if metadata[filename]["sha"] != file["sha"] | ||
| println(service_name, " sha hashes do not match, updating.") | ||
| _process_service(file, version) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| if data_changed | ||
| _generate_low_level_wrappers(files) | ||
| _generate_high_level_wrapper(services_modified) | ||
| open(metadata_path, "w") do f | ||
| print(f, json(OrderedDict(metadata), 2)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function _generate_low_level_wrappers(services::Array{OrderedDict}) | ||
| service_definitions = AWSMetadataUtilities._generate_low_level_definitions(services) | ||
|
|
||
| template = """ | ||
| # This is file is auto-generated by AWSMetadata.jl | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
|
|
||
| module AWSServices | ||
|
|
||
| include("AWS.jl") | ||
|
|
||
| $(join(service_definitions, "\n")) | ||
|
|
||
| end | ||
| """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May be easier to read if you write this like this: template = """
# This file is auto-generated by AWSMetadata.jl
module AWSServices
include("AWS.jl")
$(join(service_definitions, "\n"))
end
""" |
||
|
|
||
| services_path = joinpath(@__DIR__, "AWSServices.jl") | ||
| open(services_path, "w") do f | ||
| print(f, template) | ||
| end | ||
|
|
||
| return template | ||
| end | ||
|
|
||
| function _generate_high_level_wrapper(services::Array{OrderedDict}) | ||
| for service in services | ||
| service_name = service["name"] | ||
| println("Generating high level wrapper for $service_name") | ||
| service = JSON.parse(String(HTTP.get(service["download_url"]).body)) | ||
| service_name = lowercase(service["metadata"]["serviceId"]) | ||
| service_name = replace(service_name, ' ' => '_') | ||
| operations = service["operations"] | ||
| shapes = service["shapes"] | ||
|
|
||
| protocol = service["metadata"]["protocol"] | ||
|
|
||
| operations = AWSMetadataUtilities._generate_high_level_definitions(service_name, protocol, operations, shapes) | ||
|
|
||
| service_path = joinpath(@__DIR__, "services/$service_name.jl") | ||
|
mattBrzezinski marked this conversation as resolved.
Outdated
|
||
| open(service_path, "w") do f | ||
| println(f, "include(\"../AWSServices.jl\")") | ||
| println(f, "using .AWSServices: $service_name\n") | ||
| print(f, join(operations, "\n")) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| end | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.