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

[DO NOT MERGE][Duplicate] autoloading strategy (testing) #3104

Closed
wants to merge 12 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,27 @@ def generated_src_warning
GENERATED_SRC_WARNING
end

# @return [String]
def module_name
@service.module_name
end

# @return [Boolean]
def customization_file_exists?
File.exist?(File.join(__dir__, "../../../../../gems/aws-sdk-#{gem_name}/lib/aws-sdk-#{gem_name}/customizations/errors.rb"))
end

# @return [String]
def customization_file_path
"aws-sdk-#{gem_name}/customizations/errors"
end

private

# @return [String]
def gem_name
module_name.split('::').last.downcase
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,26 @@ def identifiers?
@identifiers.size > 0
end

# @return [Boolean]
def customization_file_exists?
File.exist?(File.join(__dir__, "../../../../../gems/#{gem_name}/lib/#{gem_name}/customizations/#{underscored_name}.rb"))
end

# @return [String]
def resource_customization
"#{gem_name}/customizations/#{underscored_name}"
end

private

def gem_name
"aws-sdk-#{module_name.split('::').last.downcase}"
end

def underscored_name
class_name.gsub(/([a-z])([A-Z])/, '\1_\2').downcase
end

def build_associations(options)
ResourceAssociation.build_list(
class_name: options.fetch(:class_name),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def initialize(options)
paginators: options.fetch(:paginators)
)
@custom = options.fetch(:custom)
@name = @module_name.split('::').last.downcase
end

# @return [String]
Expand Down Expand Up @@ -53,6 +54,16 @@ def documentation?
actions? || associations?
end

# @return [Boolean]
def customization_file_exists?
File.exist?(File.join(__dir__, "../../../../../gems/aws-sdk-#{@name}/lib/aws-sdk-#{@name}/customizations/resource.rb"))
end

# @return [String]
def customization_file_path
"aws-sdk-#{@name}/customizations/resource"
end

end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ServiceModule < View
def initialize(options)
@service = options.fetch(:service)
@prefix = options.fetch(:prefix)
@codegenerated_plugins = options.fetch(:codegenerated_plugins)
@codegenerated_plugins = options.fetch(:codegenerated_plugins) || []
end

# @return [String|nil]
Expand Down Expand Up @@ -61,15 +61,13 @@ def require_core_guard?
end

# @return [Array<String>]
def relative_requires
def autoloads
paths = Set.new
paths << "#{@prefix}/types"
paths << "#{@prefix}/client_api"

# these must be required before the client
if @codegenerated_plugins
paths += @codegenerated_plugins.map { | p| p.path }
end
paths += @codegenerated_plugins.map { |p| p.path }

paths << "#{@prefix}/client"
paths << "#{@prefix}/errors"
Expand All @@ -94,13 +92,32 @@ def relative_requires
end
paths << "#{@prefix}/customizations"
if @service.api['metadata']['protocolSettings'] &&
@service.api['metadata']['protocolSettings']['h2'] == 'eventstream'
@service.api['metadata']['protocolSettings']['h2'] == 'eventstream'
paths << "#{@prefix}/async_client"
paths << "#{@prefix}/event_streams"
elsif eventstream_shape?
paths << "#{@prefix}/event_streams"
end
paths.to_a

plugin_paths = @codegenerated_plugins.map { |p| [p.path, p] }.to_h || {}

results = paths.map do |path|
class_name = File.basename(path).split('.').first.split('_').map(&:capitalize).join

# Handle the Db -> DB case for AWS database-related constants
class_name = class_name.gsub(/Db(?=[A-Z]|$)/, 'DB')
{
file_path: path,
class_name: class_name,
is_plugin: plugin_paths.key?(path)
}
end

results.reject { |r| r[:class_name].include?('Customizations') }
end

def service_identifier
@prefix
end

def example_var_name
Expand All @@ -109,6 +126,7 @@ def example_var_name

def example_operation_name
raise "no operations found for the service" if @service.api['operations'].empty?

underscore(@service.api['operations'].keys.first)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,20 @@ def eventstreams
end
end

# @return [Array<String>]
def types_customizations
Dir.glob(File.join(__dir__, "../../../../../gems/#{gem_name}/lib/#{gem_name}/customizations/types", '*.rb')).map do |file|
filename = File.basename(file, '.rb')
"#{gem_name}/customizations/types/#{filename}"
end
end

private

def gem_name
"aws-sdk-#{module_name.split('::').last.downcase}"
end

def struct_members(shape)
return if shape['members'].nil?
members = shape['members'].map do |member_name, member_ref|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{#generated_src_warning}}
{{generated_src_warning}}
{{/generated_src_warning}}

module {{module_name}}
# @api private
module ClientApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@ module {{module_name}}
{{/errors}}
end
end
{{#customization_file_exists?}}

# Load customizations if they exist
require '{{customization_file_path}}'
{{/customization_file_exists?}}
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,8 @@ module {{module_name}}
{{/batch_actions?}}
end
end
{{#customization_file_exists?}}

# Load customizations if they exist
require '{{resource_customization}}'
{{/customization_file_exists?}}
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ module {{module_name}}

end
end
{{#customization_file_exists?}}

# Load customizations if they exist
require '{{customization_file_path}}'
{{/customization_file_exists?}}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ require '{{.}}'
{{/requires}}
{{/require_core_guard?}}

{{#relative_requires}}
require_relative '{{.}}'
{{/relative_requires}}

# This module provides support for {{full_name}}. This module is available in the
# `{{gem_name}}` gem.
#
Expand Down Expand Up @@ -52,7 +48,19 @@ require_relative '{{.}}'
#
# @!group service
module {{module_name}}
{{#autoloads}}
{{#is_plugin}}
module Plugins
autoload :{{class_name}}, '{{file_path}}'
end
{{/is_plugin}}
{{^is_plugin}}
autoload :{{class_name}}, '{{file_path}}'
{{/is_plugin}}
{{/autoloads}}

GEM_VERSION = '{{gem_version}}'

end

require_relative '{{service_identifier}}/customizations'
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ module {{module_name}}

end
end
{{#types_customizations}}
require "{{.}}"
{{/types_customizations}}
10 changes: 7 additions & 3 deletions gems/aws-sdk-cloudfront/lib/aws-sdk-cloudfront/customizations.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# frozen_string_literal: true

# utility classes
require 'aws-sdk-cloudfront/signer'
require 'aws-sdk-cloudfront/url_signer'
require 'aws-sdk-cloudfront/cookie_signer'
module Aws
module CloudFront
autoload :Signer, 'aws-sdk-cloudfront/signer'
autoload :UrlSigner, 'aws-sdk-cloudfront/url_signer'
autoload :CookieSigner, 'aws-sdk-cloudfront/cookie_signer'
end
end
1 change: 1 addition & 0 deletions gems/aws-sdk-cloudfront/spec/cookie_signer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'spec_helper'
require 'aws-sdk-cloudfront/customizations'

module Aws
module CloudFront
Expand Down
1 change: 1 addition & 0 deletions gems/aws-sdk-cloudfront/spec/url_signer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require_relative 'spec_helper'
require 'aws-sdk-cloudfront/customizations'

module Aws
module CloudFront
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

require 'aws-sdk-cognitoidentity/customizations/cognito_identity_credentials'
module Aws
module CognitoIdentity
autoload :CognitoIdentityCredentials, 'aws-sdk-cognitoidentity/customizations/cognito_identity_credentials'
end
end
2 changes: 2 additions & 0 deletions gems/aws-sdk-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Unreleased Changes
------------------

* Feature - Use autoloading at the service level to load service clients and resources.

3.205.0 (2024-09-11)
------------------

Expand Down
94 changes: 93 additions & 1 deletion gems/aws-sdk-core/lib/aws-sdk-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,99 @@

module Aws

CORE_GEM_VERSION = File.read(File.expand_path('../../VERSION', __FILE__)).strip
# tokens and token providers
autoload :Token, 'aws-sdk-core/token'
autoload :TokenProvider, 'aws-sdk-core/token_provider'
autoload :StaticTokenProvider, 'aws-sdk-core/static_token_provider'
autoload :RefreshingToken, 'aws-sdk-core/refreshing_token'
autoload :SSOTokenProvider, 'aws-sdk-core/sso_token_provider'
autoload :TokenProviderChain, 'aws-sdk-core/token_provider_chain'

module Plugins
autoload :BearerAuthorization, 'aws-sdk-core/plugins/bearer_authorization'
end

# client modules
autoload :ClientStubs, 'aws-sdk-core/client_stubs'
autoload :AsyncClientStubs, 'aws-sdk-core/async_client_stubs'
autoload :EagerLoader, 'aws-sdk-core/eager_loader'
autoload :Errors, 'aws-sdk-core/errors'
autoload :PageableResponse, 'aws-sdk-core/pageable_response'
autoload :Pager, 'aws-sdk-core/pager'
autoload :ParamConverter, 'aws-sdk-core/param_converter'
autoload :ParamValidator, 'aws-sdk-core/param_validator'
autoload :SharedConfig, 'aws-sdk-core/shared_config'
autoload :Structure, 'aws-sdk-core/structure'
autoload :EmptyStructure, 'aws-sdk-core/structure'
autoload :TypeBuilder, 'aws-sdk-core/type_builder'
autoload :Util, 'aws-sdk-core/util'

# resource classes
module Resources
autoload :Collection, 'aws-sdk-core/resources/collection'
end

# logging
module Log
autoload :Formatter, 'aws-sdk-core/log/formatter'
autoload :ParamFilter, 'aws-sdk-core/log/param_filter'
autoload :ParamFormatter, 'aws-sdk-core/log/param_formatter'
end

# stubbing
module Stubbing
autoload :EmptyStub, 'aws-sdk-core/stubbing/empty_stub'
autoload :DataApplicator, 'aws-sdk-core/stubbing/data_applicator'
autoload :StubData, 'aws-sdk-core/stubbing/stub_data'
autoload :XmlError, 'aws-sdk-core/stubbing/xml_error'

module Protocols
autoload :Json, 'aws-sdk-core/stubbing/protocols/json'
autoload :Rest, 'aws-sdk-core/stubbing/protocols/rest'
autoload :RestJson, 'aws-sdk-core/stubbing/protocols/rest_json'
autoload :RestXml, 'aws-sdk-core/stubbing/protocols/rest_xml'
autoload :Query, 'aws-sdk-core/stubbing/protocols/query'
autoload :EC2, 'aws-sdk-core/stubbing/protocols/ec2'
autoload :RpcV2, 'aws-sdk-core/stubbing/protocols/rpc_v2'
autoload :ApiGateway, 'aws-sdk-core/stubbing/protocols/api_gateway'
end
end

# protocols
autoload :ErrorHandler, 'aws-sdk-core/error_handler'
autoload :Rest, 'aws-sdk-core/rest'
autoload :Xml, 'aws-sdk-core/xml'
autoload :Json, 'aws-sdk-core/json'
autoload :Query, 'aws-sdk-core/query'
autoload :RpcV2, 'aws-sdk-core/rpc_v2'

# event stream
autoload :Binary, 'aws-sdk-core/binary'
autoload :EventEmitter, 'aws-sdk-core/event_emitter'

# endpoint discovery
autoload :EndpointCache, 'aws-sdk-core/endpoint_cache'

# client metrics
module ClientSideMonitoring
autoload :RequestMetrics, 'aws-sdk-core/client_side_monitoring/request_metrics'
autoload :Publisher, 'aws-sdk-core/client_side_monitoring/publisher'
end

# utilities
autoload :ARN, 'aws-sdk-core/arn'
autoload :ARNParser, 'aws-sdk-core/arn_parser'
autoload :EC2Metadata, 'aws-sdk-core/ec2_metadata'
autoload :LRUCache, 'aws-sdk-core/lru_cache'

# dynamic endpoints
autoload :Endpoints, 'aws-sdk-core/endpoints'

module Plugins
autoload :SignatureV4, 'aws-sdk-core/plugins/signature_v4'
end

CORE_GEM_VERSION = File.read(File.expand_path('../VERSION', __dir__)).strip

@config = {}

Expand Down
Loading
Loading