-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathendpoint_plugin.erb
More file actions
65 lines (55 loc) · 1.74 KB
/
endpoint_plugin.erb
File metadata and controls
65 lines (55 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
# This is generated code!
module <%= module_name %>
module Plugins
# @api private
class Endpoint < Smithy::Client::Plugin
option(
:endpoint,
doc_type: 'String',
docstring: <<~DOCS
The endpoint to send requests to.
The endpoint should be a URI formatted like "http://example.com:123"'
DOCS
)
option(
:endpoint_provider,
doc_type: '#resolve(parameters)',
doc_default: '<%= module_name %>::EndpointProvider',
rbs_type: '<%= module_name %>::EndpointProvider',
docstring: 'An object that provides an endpoint to use for the request.'
) do |_config|
EndpointProvider.new
end
<% parameters.select(&:client_context?).each do |param| -%>
option(
:<%= param.name %>,
doc_type: "<%= param.documentation_type %>",
docstring: "<%= param.client_context_doc %>"
)
<% end -%>
option(:endpoint_auth_schemes) do
<%= endpoint_auth_scheme_bindings %>
end
# @api private
class Handler < Smithy::Client::Handler
def call(context)
params = EndpointParameters.create(context)
context[:endpoint_params] = params
endpoint = context.config.endpoint_provider.resolve(params)
context[:resolved_endpoint] = endpoint
apply_endpoint(context, endpoint)
@handler.call(context)
end
private
def apply_endpoint(context, endpoint)
context.http_request.endpoint = endpoint.url
endpoint.headers.each do |key, value|
context.http_request.headers[key] = value
end
end
end
handler(Handler, priority: 75)
end
end
end