generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 7
Decaf endpoints #223
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
Decaf endpoints #223
Changes from 5 commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
bcfc937
Port hearth endpoint rules module
alextwoods 355a83a
Add bindings to codegen
alextwoods 43e4caa
Generation of endpoint parameters
alextwoods 9ef8233
Skeleton endpoint provider
alextwoods 784ff6a
endpoint plugin with basic config
alextwoods fe46555
Merge branch 'decaf' into decaf_endpoints
alextwoods 9724b49
PR Cleanups
alextwoods 8d791d0
More pr cleanups
alextwoods 599d4aa
Merge branch 'decaf' into decaf_endpoints
alextwoods f00e788
Rubocop fixes
alextwoods 6de786b
Fix specs
alextwoods 6f5b086
Merge branch 'decaf' into decaf_endpoints
alextwoods b9e8bbc
Rubocop
alextwoods 79b7b14
Add generated resolver spec (templates/view, not working yet)
alextwoods ba682bb
Some rubocop cleanups
alextwoods dae2110
Merge branch 'decaf' into decaf_endpoints
alextwoods b3f5fe4
Endpoint spec generation
alextwoods 5a4be49
Merge branch 'decaf' into decaf_endpoints
alextwoods 4ebf372
endpoint provider interface spec
alextwoods 9a52cb1
WIP - add handler code + per operation parameters
alextwoods 3feea81
Merge branch 'decaf' into decaf_endpoints
alextwoods cb91d68
Possible weld spec fix
alextwoods 97bfc55
Merge branch 'decaf' into decaf_endpoints
alextwoods a40a16f
Add new endpoint test model + fix issues in trait usage
alextwoods 6bc541f
Generate create for operation parameters
alextwoods 313dc33
Merge branch 'decaf' into decaf_endpoints
alextwoods 959762b
Working parameters spec for operations
alextwoods 0a23ea5
rubocop
alextwoods 2e39864
Run all endpoint specs
alextwoods 96c1cc7
fix rubocop
alextwoods 418d80f
Simplify spec task
d94f1c1
PR cleanups
alextwoods af7daa6
Run all endpoint specs together
alextwoods fd882a9
Merge branch 'decaf' into decaf_endpoints
alextwoods 9117b45
Remove endpoint bindings from plan. Remove endpoint binding classes
alextwoods 1c38695
Add smithy files for endpoint fixtures
alextwoods bf448d1
Merge branch 'decaf' into decaf_endpoints
alextwoods a98c0e0
fix merge issues
alextwoods 956d432
PR feedback
alextwoods f1a9a60
generated rubocop fixes
alextwoods 0d31124
Rubocop cleanups
alextwoods 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
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
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
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,152 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'cgi' | ||
| require 'ipaddr' | ||
| require 'uri' | ||
|
|
||
| module Smithy | ||
| module Client | ||
| # Functions in the Smithy rules engine are named routines that | ||
| # operate on a finite set of specified inputs, returning an output. | ||
| # The rules engine has a set of included functions that can be | ||
| # invoked without additional dependencies, called the standard library. | ||
| module EndpointRules | ||
| # An Authentication Scheme supported by an Endpoint | ||
| class AuthScheme | ||
| # @param [String] :scheme_id | ||
| # @param [Hash] :properties ({}) | ||
| def initialize(scheme_id:, properties: {}) | ||
| @scheme_id = scheme_id | ||
| @properties = properties | ||
| end | ||
|
|
||
| # The identifier of the authentication scheme. | ||
| # @return [String] | ||
| attr_accessor :scheme_id | ||
|
|
||
| # Additional properties of the authentication scheme. | ||
| # @return [Hash] | ||
| attr_accessor :properties | ||
| end | ||
|
|
||
| # An Endpoint resolved by an EndpointProvider | ||
| class Endpoint | ||
| # @param [String] :uri | ||
| # @param [Array<AuthScheme>] :auth_schemes ([]) | ||
| # @param [Hash] :headers ({}) | ||
| def initialize(uri:, auth_schemes: [], headers: {}) | ||
| @uri = uri | ||
| @auth_schemes = auth_schemes | ||
| @headers = headers | ||
| end | ||
|
|
||
| # The URI of the endpoint. | ||
| # @return [String] | ||
| attr_accessor :uri | ||
|
|
||
| # The authentication schemes supported by the endpoint. | ||
| # @return [Array<AuthScheme>] | ||
| attr_accessor :auth_schemes | ||
|
|
||
| # The headers to include in requests to the endpoint. | ||
| # @return [Hash] | ||
| attr_accessor :headers | ||
| end | ||
|
|
||
| # Evaluates whether the input string is a compliant RFC 1123 host segment. | ||
| # When allowSubDomains is true, evaluates whether the input string is | ||
| # composed of values that are each compliant RFC 1123 host segments | ||
| # joined by dot (.) characters. | ||
| # @api private | ||
| # rubocop:disable Style/OptionalBooleanParameter | ||
mullermp marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| def self.valid_host_label?(value, allow_sub_domains = false) | ||
| return false if value.empty? | ||
|
|
||
| if allow_sub_domains | ||
| labels = value.split('.', -1) | ||
| return labels.all? { |l| valid_host_label?(l, false) } | ||
| end | ||
|
|
||
| !!(value =~ /\A(?!-)[a-zA-Z0-9-]{1,63}(?<!-)\z/) | ||
| end | ||
| # rubocop:enable Style/OptionalBooleanParameter | ||
|
|
||
| # Computes a URL structure given an input string. | ||
| # @api private | ||
| def self.parse_url(value) | ||
| URL.new(value).as_json | ||
| rescue ArgumentError, URI::InvalidURIError | ||
| nil | ||
| end | ||
|
|
||
| # Computes a portion of a given string based on | ||
| # the provided start and end indices. | ||
| # @api private | ||
| def self.substring(input, start, stop, reverse) | ||
| return nil if start >= stop || input.size < stop | ||
|
|
||
| return nil if input.chars.any? { |c| c.ord > 127 } | ||
|
|
||
| return input[start...stop] unless reverse | ||
|
|
||
| r_start = input.size - stop | ||
| r_stop = input.size - start | ||
| input[r_start...r_stop] | ||
| end | ||
|
|
||
| # Performs RFC 3986#section-2.1 defined percent-encoding on the input value. | ||
| # @api private | ||
| def self.uri_encode(value) | ||
| CGI.escape(value.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~') | ||
| end | ||
|
|
||
| # @api private | ||
| class URL | ||
| def initialize(url) | ||
| uri = URI(url) | ||
| @scheme = uri.scheme | ||
| # only support http and https schemes | ||
| raise ArgumentError unless %w[https http].include?(@scheme) | ||
|
|
||
| # do not support query | ||
| raise ArgumentError if uri.query | ||
|
|
||
| @authority = _authority(url, uri) | ||
| @path = uri.path | ||
| @normalized_path = uri.path + (uri.path[-1] == '/' ? '' : '/') | ||
| @is_ip = _is_ip(uri.host) | ||
| end | ||
|
|
||
| attr_reader :scheme, :authority, :path, :normalized_path, :is_ip | ||
|
|
||
| def as_json(_options = {}) | ||
jterapin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| 'scheme' => scheme, | ||
| 'authority' => authority, | ||
| 'path' => path, | ||
| 'normalizedPath' => normalized_path, | ||
| 'isIp' => is_ip | ||
| } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def _authority(url, uri) | ||
alextwoods marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # don't include port if it's default and not parsed originally | ||
| if uri.default_port == uri.port && !url.include?(":#{uri.port}") | ||
| uri.host | ||
| else | ||
| "#{uri.host}:#{uri.port}" | ||
| end | ||
| end | ||
|
|
||
| def _is_ip(authority) | ||
| IPAddr.new(authority) | ||
mullermp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| true | ||
| rescue IPAddr::InvalidAddressError | ||
| false | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file was deleted.
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.
Uh oh!
There was an error while loading. Please reload this page.