Skip to content
Merged
Show file tree
Hide file tree
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 Dec 13, 2024
355a83a
Add bindings to codegen
alextwoods Dec 13, 2024
43e4caa
Generation of endpoint parameters
alextwoods Dec 16, 2024
9ef8233
Skeleton endpoint provider
alextwoods Dec 16, 2024
784ff6a
endpoint plugin with basic config
alextwoods Dec 16, 2024
fe46555
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 17, 2024
9724b49
PR Cleanups
alextwoods Dec 17, 2024
8d791d0
More pr cleanups
alextwoods Dec 17, 2024
599d4aa
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 18, 2024
f00e788
Rubocop fixes
alextwoods Dec 18, 2024
6de786b
Fix specs
alextwoods Dec 18, 2024
6f5b086
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 18, 2024
b9e8bbc
Rubocop
alextwoods Dec 18, 2024
79b7b14
Add generated resolver spec (templates/view, not working yet)
alextwoods Dec 18, 2024
ba682bb
Some rubocop cleanups
alextwoods Dec 18, 2024
dae2110
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 19, 2024
b3f5fe4
Endpoint spec generation
alextwoods Dec 20, 2024
5a4be49
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 21, 2024
4ebf372
endpoint provider interface spec
alextwoods Dec 23, 2024
9a52cb1
WIP - add handler code + per operation parameters
alextwoods Dec 23, 2024
3feea81
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 23, 2024
cb91d68
Possible weld spec fix
alextwoods Dec 23, 2024
97bfc55
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 23, 2024
a40a16f
Add new endpoint test model + fix issues in trait usage
alextwoods Dec 24, 2024
6bc541f
Generate create for operation parameters
alextwoods Dec 24, 2024
313dc33
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 26, 2024
959762b
Working parameters spec for operations
alextwoods Dec 26, 2024
0a23ea5
rubocop
alextwoods Dec 26, 2024
2e39864
Run all endpoint specs
alextwoods Dec 26, 2024
96c1cc7
fix rubocop
alextwoods Dec 26, 2024
418d80f
Simplify spec task
Dec 27, 2024
d94f1c1
PR cleanups
alextwoods Dec 27, 2024
af7daa6
Run all endpoint specs together
alextwoods Dec 27, 2024
fd882a9
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 27, 2024
9117b45
Remove endpoint bindings from plan. Remove endpoint binding classes
alextwoods Dec 27, 2024
1c38695
Add smithy files for endpoint fixtures
alextwoods Dec 30, 2024
bf448d1
Merge branch 'decaf' into decaf_endpoints
alextwoods Dec 30, 2024
a98c0e0
fix merge issues
alextwoods Dec 30, 2024
956d432
PR feedback
alextwoods Dec 30, 2024
f1a9a60
generated rubocop fixes
alextwoods Dec 30, 2024
0d31124
Rubocop cleanups
alextwoods Dec 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ bundle exec smithy-ruby smith types --gem-name some_organization-weather --gem-v
IRB on weather gem
```
irb -I build/smithy/source/smithy-ruby/lib -I gems/smithy-client/lib -r weather
```
```

Build a fixture
```
export SMITHY_PLUGIN_DIR=build/smithy/source/smithy-ruby
bundle exec smithy-ruby smith client --gem-name fixture --gem-version 1.0.0 <<< $(cat gems/smithy/spec/fixtures/endpoints/default-values/model.json)
```
2 changes: 1 addition & 1 deletion gems/smithy-client/lib/smithy-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
require_relative 'smithy-client/plugin_list'
require_relative 'smithy-client/plugin'
require_relative 'smithy-client/handler'
require_relative 'smithy-client/plugins/endpoint'
require_relative 'smithy-client/base'
require_relative 'smithy-client/configuration'
require_relative 'smithy-client/errors'
require_relative 'smithy-client/endpoint_rules'
require_relative 'smithy-client/handler_context'
require_relative 'smithy-client/handler_list'
require_relative 'smithy-client/handler_list_entry'
Expand Down
1 change: 0 additions & 1 deletion gems/smithy-client/lib/smithy-client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Base
# @api private
@plugins = PluginList.new(
[
Plugins::Endpoint,
# Plugins::NetHttp,
# Plugins::RaiseResponseErrors,
# Plugins::ResponseTarget,
Expand Down
152 changes: 152 additions & 0 deletions gems/smithy-client/lib/smithy-client/endpoint_rules.rb
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
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 = {})
{
'scheme' => scheme,
'authority' => authority,
'path' => path,
'normalizedPath' => normalized_path,
'isIp' => is_ip
}
end

private

def _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 _is_ip(authority)
IPAddr.new(authority)
true
rescue IPAddr::InvalidAddressError
false
end
end
end
end
end
48 changes: 0 additions & 48 deletions gems/smithy-client/lib/smithy-client/plugins/endpoint.rb

This file was deleted.

Loading