@@ -4,62 +4,70 @@ module Aws
4
4
module Plugins
5
5
# @api private
6
6
class EndpointPattern < Seahorse ::Client ::Plugin
7
-
8
- option ( :disable_host_prefix_injection ,
7
+ option (
8
+ :disable_host_prefix_injection ,
9
9
default : false ,
10
10
doc_type : 'Boolean' ,
11
- docstring : <<-DOCS
12
- Set to true to disable SDK automatically adding host prefix
13
- to default service endpoint when available.
14
- DOCS
15
- )
11
+ docstring : 'When `true`, the SDK will not prepend the modeled host prefix to the endpoint.'
12
+ ) do |cfg |
13
+ resolve_disable_host_prefix_injection ( cfg )
14
+ end
16
15
17
- def add_handlers ( handlers , config )
16
+ def add_handlers ( handlers , _config )
18
17
handlers . add ( Handler , priority : 10 )
19
18
end
20
19
21
- class Handler < Seahorse ::Client ::Handler
20
+ class << self
21
+ private
22
+
23
+ def resolve_disable_host_prefix_injection ( cfg )
24
+ value = ENV [ 'AWS_DISABLE_HOST_PREFIX_INJECTION' ] ||
25
+ Aws . shared_config . disable_host_prefix_injection ( profile : cfg . profile ) ||
26
+ 'false'
27
+ value = Aws ::Util . str_2_bool ( value )
28
+ unless [ true , false ] . include? ( value )
29
+ raise ArgumentError ,
30
+ 'Must provide either `true` or `false` for ' \
31
+ 'disable_host_prefix_injection profile option or for ' \
32
+ 'ENV[\'AWS_DISABLE_HOST_PREFIX_INJECTION\']'
33
+ end
34
+ value
35
+ end
36
+ end
22
37
38
+ # @api private
39
+ class Handler < Seahorse ::Client ::Handler
23
40
def call ( context )
24
- if ! context . config . disable_host_prefix_injection
41
+ unless context . config . disable_host_prefix_injection
25
42
endpoint_trait = context . operation . endpoint_pattern
26
- if endpoint_trait && !endpoint_trait . empty?
27
- _apply_endpoint_trait ( context , endpoint_trait )
28
- end
43
+ apply_endpoint_trait ( context , endpoint_trait ) if endpoint_trait && !endpoint_trait . empty?
29
44
end
30
45
@handler . call ( context )
31
46
end
32
47
33
48
private
34
49
35
- def _apply_endpoint_trait ( context , trait )
36
- # currently only support host pattern
37
- ori_host = context . http_request . endpoint . host
38
- if pattern = trait [ 'hostPrefix' ]
39
- host_prefix = pattern . gsub ( /\{ .+?\} / ) do |label |
40
- label = label . delete ( "{}" )
41
- _replace_label_value (
42
- ori_host , label , context . operation . input , context . params )
43
- end
44
- context . http_request . endpoint . host = host_prefix + context . http_request . endpoint . host
50
+ def apply_endpoint_trait ( context , trait )
51
+ pattern = trait [ 'hostPrefix' ]
52
+ return unless pattern
53
+
54
+ host_prefix = pattern . gsub ( /\{ .+?}/ ) do |label |
55
+ label = label . delete ( '{}' )
56
+ replace_label_value ( label , context . operation . input , context . params )
45
57
end
58
+ context . http_request . endpoint . host = host_prefix + context . http_request . endpoint . host
46
59
end
47
60
48
- def _replace_label_value ( ori , label , input_ref , params )
61
+ def replace_label_value ( label , input_ref , params )
49
62
name = nil
50
63
input_ref . shape . members . each do |m_name , ref |
51
- if ref [ 'hostLabel' ] && ref [ 'hostLabelName' ] == label
52
- name = m_name
53
- end
54
- end
55
- if name . nil? || params [ name ] . nil?
56
- raise Errors ::MissingEndpointHostLabelValue . new ( name )
64
+ name = m_name if ref [ 'hostLabel' ] && ref [ 'hostLabelName' ] == label
57
65
end
66
+ raise Errors ::MissingEndpointHostLabelValue , name if name . nil? || params [ name ] . nil?
67
+
58
68
params [ name ]
59
69
end
60
-
61
70
end
62
-
63
71
end
64
72
end
65
73
end
0 commit comments