Skip to content
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

Reduce memory usage from aws-partitions #3122

Merged
merged 24 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d9e6e1a
Reduce memory usage from aws-partitions
alextwoods Oct 7, 2024
b345948
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 7, 2024
32a3e8e
fix whitespace
alextwoods Oct 7, 2024
167dc31
Fix issue in new aws_partition method
alextwoods Oct 7, 2024
3b43d7c
Fix failures
alextwoods Oct 7, 2024
25b35fc
Update partition metadata method to match v4
alextwoods Oct 8, 2024
2c38cd7
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 8, 2024
b9a04ed
Remove commented out code
alextwoods Oct 8, 2024
13f2c57
DEMO ALTERNATIVE: use cfg.endpoint_resolver to resolve config.endpoint
alextwoods Oct 9, 2024
b539c55
Revert "DEMO ALTERNATIVE: use cfg.endpoint_resolver to resolve config…
alextwoods Oct 9, 2024
61e8de1
Update min partition version
alextwoods Oct 9, 2024
5516a5a
Add struct attr_reader on DefaultResolver
alextwoods Oct 9, 2024
3074fce
Remove endpoint plugin from ep2.0 services
alextwoods Oct 9, 2024
5d7415d
Merge remote-tracking branch 'origin/version-3' into optimize_partitions
alextwoods Oct 9, 2024
f8b9164
Revert "Remove endpoint plugin from ep2.0 services"
alextwoods Oct 9, 2024
3ea1baf
New approach - use the EndpointProvider (ep2) to resolve a default en…
alextwoods Oct 9, 2024
d47a8c5
Revert changes to searhose endpoint plugin
alextwoods Oct 10, 2024
a17e870
Fix tests
alextwoods Oct 10, 2024
1e9ffce
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 15, 2024
f329550
New approach, change endpoint generation and add create class method
alextwoods Oct 15, 2024
bc78ca6
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 15, 2024
8f903a3
PR cleanups
alextwoods Oct 16, 2024
01a729c
Bump mincore versions
alextwoods Oct 16, 2024
2d04869
Merge branch 'version-3' into optimize_partitions
alextwoods Oct 17, 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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require_relative 'aws-sdk-code-generator/client_response_structure_example'
require_relative 'aws-sdk-code-generator/crosslink'
require_relative 'aws-sdk-code-generator/docstring'
require_relative 'aws-sdk-code-generator/endpoint_parameter'
require_relative 'aws-sdk-code-generator/hash_formatter'
require_relative 'aws-sdk-code-generator/helper'
require_relative 'aws-sdk-code-generator/plugin_list'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# frozen_string_literal: true

module AwsSdkCodeGenerator
class EndpointParameter
def initialize(name, definition, service, operation=nil)
@name = name

@value, @source = endpoint_parameter_value(name, definition, service, operation)

@type = definition['type']
@built_in = definition['builtIn']
@default = definition['default']
@required = definition['required']
@documentation = "# @!attribute #{key}\n"
if definition['documentation']
@documentation += " # #{definition['documentation']}\n"
end
if deprecated = definition['deprecated']
@documentation += " #\n # @deprecated\n"
if deprecated['message']
@documentation += " # #{deprecated['message']}\n"
end
if deprecated['since']
@documentation += " # Since: #{deprecated['since']}\n"
end
end
@documentation += " #\n # @return [#{@type}]\n #"
end

# @return [String]
attr_reader :name

# @return [String]
attr_reader :documentation

# @return [Boolean]
attr_reader :required

# @return [String]
attr_reader :source

# @return [String]
attr_reader :value

# @return [String,Boolean,Array]
def default
case @default
when String
"\"#{@default}\""
else
@default.to_s
end
end

def default?
[email protected]?
end

def validate_required?
required && !default?
end

def key
alextwoods marked this conversation as resolved.
Show resolved Hide resolved
Underscore.underscore(name)
end

private

# Most to least
# staticContextParams
# contextParam
# operationContextParams
# clientContextParams (always sourced from config)
# Built-In Bindings (sourced from config in most cases, context in some cases to allow operation level overrides)
# Built-in binding default values
# @retyrn [value, source]. source may be one of [operation, config, default]
def endpoint_parameter_value(param_name, param_data, service, operation)
unless operation.nil?
value, source = [
static_context_param(operation, param_name), 'operation'
]
value, source = [
context_param_value(service, operation, param_name), 'operation'
] unless value
value, source = [
operation_context_param_value(operation, param_name), 'operation'
] unless value
end

value, source = [
client_context_param_value(service, param_name, param_data),
'config'
] unless value


# built-ins may be sourced from operation context in some cases
unless value
value, source = built_in_param_value(service, param_data)
end

[value || 'nil', source || 'default']
end

def client_context_param_value(service, param_name, param_data)
if service.api['clientContextParams']&.key?(param_name) &&
!param_data['builtIn']
"config.#{Underscore.underscore(param_name)}"
end
end

# built-ins may be sourced from operation context in some cases
def built_in_param_value(service, param_data)
source = 'config'
value =
case param_data['builtIn']
when 'AWS::Region'
'config.region'
when 'AWS::UseFIPS'
'config.use_fips_endpoint'
when 'AWS::UseDualStack'
if service.name == 'S3' || service.name == 'S3Control'
source = 'operation'
'context[:use_dualstack_endpoint]'
else
'config.use_dualstack_endpoint'
end
when 'AWS::Auth::AccountId'
'config.credentials.credentials.account_id'
when 'AWS::Auth::AccountIdEndpointMode'
'config.account_id_endpoint_mode'
when 'AWS::STS::UseGlobalEndpoint'
"config.sts_regional_endpoints == 'legacy'"
when 'AWS::S3::UseGlobalEndpoint'
"config.s3_us_east_1_regional_endpoint == 'legacy'"
when 'AWS::S3::Accelerate'
if service.name == 'S3' || service.name == 'S3Control'
source = 'operation'
'context[:use_accelerate_endpoint]'
else
'config.use_accelerate_endpoint'
end
when 'AWS::S3::ForcePathStyle'
'config.force_path_style'
when 'AWS::S3::UseArnRegion', 'AWS::S3Control::UseArnRegion'
'config.s3_use_arn_region'
when 'AWS::S3::DisableMultiRegionAccessPoints'
'config.s3_disable_multiregion_access_points'
when 'SDK::Endpoint'
'(config.endpoint.to_s unless config.regional_endpoint)'
else
source = nil
nil # no value, not a default
end
[value, source]
end

def context_param_value(service, operation, param_name)
return nil unless operation['input']

input_shape = operation['input']['shape']
members = service.api['shapes'][input_shape].fetch('members', {})
members.detect do |(member_name, member)|
context_param = member.fetch('contextParam', {})
if context_param.fetch('name', nil) == param_name
break "context.params[:#{Underscore.underscore(member_name)}]"
end
end
end

def operation_context_param_value(operation, param_name)
return nil unless operation['input']

binding = operation.fetch('operationContextParams', {})[param_name]

return nil unless binding

"JMESPath.search(\"#{Underscore.underscore_jmespath(binding['path'])}\", context.params)"
end

def static_context_param(operation, param_name)
value = operation.fetch('staticContextParams', {})
.fetch(param_name, {}).fetch('value', nil)
if !value.nil? && value.is_a?(String)
"\"#{value}\""
else
value
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@ def initialize(options)
@service = options.fetch(:service)
if (parameters = @service.endpoint_rules&.fetch('parameters'))
@parameters = parameters.map do |k,p|
EndpointParameter.new(k, p)
EndpointParameter.new(k, p, @service)
end
end
end

# @return [Array<EndpointParameter>]
attr_reader :parameters

# @return [Array<EndpointParameter>]
def config_parameters
parameters.select { |p| p.source == 'config' }
end

# @return [String|nil]
def generated_src_warning
return if @service.protocol == 'api-gateway'
Expand All @@ -26,58 +31,6 @@ def generated_src_warning
def module_name
@service.module_name
end

class EndpointParameter
def initialize(name, definition={})
@name = name
@type = definition['type']
@built_in = definition['builtIn']
@default = definition['default']
@required = definition['required']
@documentation = "# @!attribute #{underscore_name}\n"
if definition['documentation']
@documentation += " # #{definition['documentation']}\n"
end
if deprecated = definition['deprecated']
@documentation += " #\n # @deprecated\n"
if deprecated['message']
@documentation += " # #{deprecated['message']}\n"
end
if deprecated['since']
@documentation += " # Since: #{deprecated['since']}\n"
end
end
@documentation += " #\n # @return [#{@type}]\n #"
end

# @return [String]
attr_reader :name

# @return [String]
attr_reader :documentation

# @return [Boolean]
attr_reader :required

# @return [String,Boolean,Array]
def default
case @default
when String
"\"#{@default}\""
else
@default.to_s
end
end

def default?
[email protected]?
end

def underscore_name
Underscore.underscore(name)
end
end

end
end
end
Loading
Loading