-
Notifications
You must be signed in to change notification settings - Fork 6
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
Implement protocol plugin and rpcv2 protocol #264
Merged
Merged
Changes from 74 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
a57acd6
Add protocol base class and draft rpcv2 protocol implementation
jterapin 4d3a7f4
Add example implementation of codegenerated plugin
jterapin 036d2d8
Update smithy model to use rpcv2 trait for testing
jterapin fb17908
Add projections
jterapin c7c672c
Merge decaf into branch
jterapin 787f763
Update RPCV2 protocol
jterapin 37c2508
Add protocols weld
jterapin 578478e
Update protocol weld
jterapin c168be0
Update protocol weld to include a TODO
jterapin 2d098e4
Add more TODO guidance
jterapin 885ae8b
Update protocol plugin
jterapin 20abd06
Update protocol plugin and other components
jterapin aa367c8
Update handler syntax
jterapin 589feaa
Appease specs
jterapin 8e4c0f3
Update projections
jterapin 03e7699
Remove base class
jterapin 318b0cd
Remove unnecessary method
jterapin c29eb20
Merge branch 'decaf' into add_cbor_protocol
jterapin d5413e6
Update protocol modules
jterapin 68713d1
Update documentation
jterapin 5418ba0
Update endpoint specs to handle protocol plugin
jterapin 1f475c2
Move handler classes to smithy-client
jterapin 42114fa
Updates based on feedbacks
jterapin 2656ba7
Sync fixtures
jterapin 86c777d
Update handlers
jterapin 2014c1c
Add rbs file
jterapin 1a26319
Revert "Sync fixtures"
jterapin 1ed8b04
Add protocol plugin specs
jterapin f7922a9
Update fixture model to recongize config file
jterapin a4ef87c
update projections
jterapin f4cb90d
Revert "Update fixture model to recongize config file"
jterapin fd361e9
Fix config flag for fixtures
jterapin 659a1ea
Fix documentation
jterapin f3360c3
Merge decaf into branch
jterapin 7952f0e
Merge branch 'decaf' into add_cbor_protocol
jterapin b4354a9
Update plugin docs
jterapin 44f1898
Fix config documentation
jterapin 4b1ed95
Fix specs based on merged changes
jterapin 15cf0aa
Handle endpoints
jterapin 9a9afb6
Resolve failures relating to content-type and accept headers
jterapin 3f35c47
Add shapes change coverage
jterapin 69208d9
Merge branch 'decaf' into add_cbor_protocol
jterapin 0edce81
Fix codec deserialization
jterapin 046227d
Add possible rbs fix
jterapin 0687fd4
Add header fixes
jterapin 7a9a8f3
Update rbs
jterapin e05f941
Merge branch 'decaf' into add_cbor_protocol
jterapin 3bc1683
Merge branch 'decaf' into add_cbor_protocol
jterapin 8e201a6
Merge decaf into branch
jterapin 0ae5b87
Adding member names to shape
jterapin 36fe4a5
Update based on refactor
jterapin c175478
Merge decaf into branch
jterapin 936d4ec
Temp fix
jterapin d3875d1
Add to reference service shape name
jterapin eb3255a
Fix failures related to protocol tests
jterapin c5adb00
Fix top model changes
jterapin a65325d
Fix rbs
jterapin cebe5c4
Appease rubocop
jterapin 70dd666
Update syntax
jterapin 52a8d15
Update helpful commands
jterapin fcb34b1
Update schema and its shapes
jterapin bd0d912
Update cbor
jterapin f7358e5
Merge branch 'decaf' into add_cbor_protocol
jterapin 402f07a
Clean up README
jterapin 86995e0
Update Protocol Plugin to hold generic handlers
jterapin 8a29c33
Update based on feedbacks
jterapin 668d9b0
Add DummyWeldProtocol
jterapin cafe0a9
Fix failure
jterapin 37ca72d
Update existing spec const
jterapin 7d590d8
Fix protocol test failures
jterapin 3ec2dd0
Add members by name to shapes with members
jterapin 75837df
Remove dup method
jterapin 7ba096f
Refactor protocol weld tests
mullermp 8ea5ea0
Refactor weld testing with protocol welds
mullermp 0ab8632
Fix build
mullermp 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 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative 'protocols/rpc_v2' | ||
|
||
module Smithy | ||
module Client | ||
# In Smithy, a protocol is a named set of rules that defines the | ||
# syntax and semantics of how a client and server communicate. To | ||
# use a {Smithy::Client}, a protocol is required to be set on | ||
# {Configuration}. | ||
# | ||
# We currently support the following protocols: | ||
# | ||
# - {RPCv2}, a RPC-based protocol over HTTP that sends requests | ||
# and responses with CBOR payloads. | ||
# | ||
# You could also create a custom protocol to pass into the client | ||
# configuration. The given protocol must provide the following | ||
# functionalities: | ||
# | ||
# - `build` - builds the request | ||
# - `parse` - parse the response | ||
# - `error` - extracts the error from response | ||
# | ||
# See {RPCv2} as an example implementation. | ||
module Protocols; end | ||
end | ||
end |
This file contains 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,82 @@ | ||
# frozen_string_literal: true | ||
|
||
module Smithy | ||
module Client | ||
module Protocols | ||
# A RPC-based protocol over HTTP that sends requests | ||
# and responses with CBOR payloads. | ||
# | ||
# TODO: Refactor methods to handle eventstreams | ||
class RPCv2 | ||
# @api private | ||
SHAPE_ID = 'smithy.protocols#rpcv2Cbor' | ||
|
||
# @param options [Hash] Protocol options | ||
# @option options [Boolean] :query_compatible (nil) | ||
def initialize(options = {}) | ||
@query_compatible = options[:query_compatible] | ||
jterapin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
|
||
# @api private | ||
def build(context) | ||
codec = Client::Codecs::CBOR.new(setting(context)) | ||
context.request.body = codec.serialize(context.params, context.operation.input) | ||
context.request.http_method = 'POST' | ||
jterapin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
apply_headers(context) | ||
build_url(context) | ||
end | ||
|
||
# @api private | ||
def parse(context) | ||
output_shape = context.operation.output | ||
codec = Client::Codecs::CBOR.new(setting(context)) | ||
codec.deserialize(context.response.body.read, output_shape) | ||
end | ||
|
||
# @api private | ||
# TODO: To implement after error handling | ||
def error(_context, _response); end | ||
|
||
private | ||
|
||
def apply_headers(context) | ||
context.request.headers['X-Amzn-Query-Mode'] = 'true' if query_compatible?(context) | ||
context.request.headers['Smithy-Protocol'] = 'rpc-v2-cbor' | ||
apple_content_type(context) | ||
apply_accept_header(context) | ||
# TODO: Implement Content-Length Plugin/Handler | ||
context.request.headers['Content-Length'] = context.request.body.size | ||
end | ||
|
||
def apply_accept_header(context) | ||
# TODO: Needs an update when streaming is handled | ||
context.request.headers['Accept'] = 'application/cbor' | ||
end | ||
|
||
def apple_content_type(context) | ||
return if context.operation.input == Model::Shapes::Prelude::Unit | ||
|
||
# TODO: Needs an update when streaming is handled | ||
context.request.headers['Content-Type'] = 'application/cbor' | ||
end | ||
|
||
def build_url(context) | ||
base = context.request.endpoint | ||
base.path += | ||
"/service/#{context.config.service.name}/operation/#{context.operation.name}" | ||
end | ||
|
||
def setting(context) | ||
{}.tap do |h| | ||
h[:query_compatible] = true if query_compatible?(context) | ||
end | ||
end | ||
jterapin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def query_compatible?(context) | ||
@query_compatible || | ||
context.config.service.traits.one? { |k, _v| k == 'aws.protocols#awsQuery' } | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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,11 @@ | ||
module Smithy | ||
module Client | ||
module Protocols | ||
# A RPC-based protocol over HTTP that sends requests | ||
# and responses with CBOR payloads. | ||
class RPCv2 | ||
def initialize: (?::Hash[untyped, untyped] options) -> void | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to implement the (de)serialization of union shapes in a separate PR since I have some questions before implementing. Will be a small follow-up PR most likely.