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 all 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
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,186 @@ | ||
| # 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 | ||
| # Regex that extracts anything in square brackets | ||
| BRACKET_REGEX = /\[(.*?)\]/ | ||
|
|
||
| # An Endpoint resolved by an EndpointProvider | ||
| class Endpoint | ||
| # @param [String] :uri | ||
| # @param [Array<AuthScheme>] :auth_schemes ([]) | ||
| # @param [Hash] :headers ({}) | ||
| def initialize(uri:, properties: {}, headers: {}) | ||
| @uri = uri | ||
| @properties = properties | ||
| @headers = headers | ||
| end | ||
|
|
||
| # The URI of the endpoint. | ||
| # @return [String] | ||
| attr_accessor :uri | ||
|
|
||
| # The authentication schemes supported by the endpoint. | ||
| # @return [Hash] | ||
| attr_accessor :properties | ||
|
|
||
| # 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 | ||
| def self.valid_host_label?(value, allow_sub_domains) | ||
| 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 | ||
|
|
||
| # 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 | ||
|
|
||
| # isSet(value: Option<T>) bool | ||
| # @api private | ||
| def self.set?(value) | ||
| !value.nil? | ||
| end | ||
|
|
||
| # not(value: bool) bool | ||
| # @api private | ||
| def self.not(bool) | ||
| !bool | ||
| end | ||
|
|
||
| # getAttr(value: Object | Array, path: string) Document | ||
| # @api private | ||
| def self.attr(value, path) | ||
| parts = path.split('.') | ||
|
|
||
| val = attr_brackets(parts, value) | ||
|
|
||
| if parts.size == 1 | ||
| val | ||
| else | ||
| attr_reader(val, parts.slice(1..-1).join('.')) | ||
| end | ||
| end | ||
|
|
||
| # stringEquals(value1: string, value2: string) bool | ||
| # @api private | ||
| def self.string_equals?(value1, value2) | ||
| value1 == value2 | ||
| end | ||
|
|
||
| # booleanEquals(value1: bool, value2: bool) bool | ||
| # @api private | ||
| def self.boolean_equals?(value1, value2) | ||
| value1 == value2 | ||
| 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 = extract_authority(url, uri) | ||
| @path = uri.path | ||
| @normalized_path = uri.path + (uri.path[-1] == '/' ? '' : '/') | ||
| @is_ip = ip?(uri.host) | ||
| end | ||
|
|
||
| attr_reader :scheme, :authority, :path, :normalized_path, :is_ip | ||
|
|
||
| def as_json(*) | ||
| { | ||
| 'scheme' => scheme, | ||
| 'authority' => authority, | ||
| 'path' => path, | ||
| 'normalizedPath' => normalized_path, | ||
| 'isIp' => is_ip | ||
| } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def extract_authority(url, uri) | ||
| # 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 ip?(authority) | ||
| IPAddr.new(authority) | ||
mullermp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| true | ||
| rescue IPAddr::InvalidAddressError | ||
| false | ||
| end | ||
| end | ||
|
|
||
| def self.attr_brackets(parts, value) | ||
| if (index = parts.first[BRACKET_REGEX, 1]) | ||
| # remove brackets and index from part before indexing | ||
| if (base = parts.first.gsub(BRACKET_REGEX, '')) && !base.empty? | ||
| value[base][index.to_i] | ||
| else | ||
| value[index.to_i] | ||
| end | ||
| else | ||
| value[parts.first] | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file was deleted.
Oops, something went wrong.
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
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.
Is there a better way to express this one?
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.
Do you mean the
model_path.split('/')[-2]part? I could domodel_path.split('/').last(2).firstinstead, but that felt worse. Alternatively we coudl use regex to extract it, but I think splitting on / is simpler here.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.
Was thinking in terms of readability. What exactly is extracted? It's otherwise fine.