@@ -67,15 +67,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
67
67
68
68
/** @var ConsoleOutputInterface $output */
69
69
$ manifest = $ this ->loadManifest ();
70
+ $ endpoints = $ this ->loadFile ($ manifest ['endpoints ' ], 'endpoints ' );
70
71
$ serviceNames = $ this ->getServiceNames ($ input ->getArgument ('service ' ), $ input ->getOption ('all ' ), $ io , $ manifest ['services ' ]);
71
72
if (\is_int ($ serviceNames )) {
72
73
return $ serviceNames ;
73
74
}
74
75
75
76
if (\count ($ serviceNames ) > 1 && $ input ->getOption ('all ' ) && \extension_loaded ('pcntl ' )) {
76
- $ manifest = $ this ->generateServicesParallel ($ io , $ input , $ output , $ manifest , $ serviceNames );
77
+ $ manifest = $ this ->generateServicesParallel ($ io , $ input , $ output , $ manifest , $ endpoints , $ serviceNames );
77
78
} else {
78
- $ manifest = $ this ->generateServicesSequential ($ io , $ input , $ output , $ manifest , $ serviceNames );
79
+ $ manifest = $ this ->generateServicesSequential ($ io , $ input , $ output , $ manifest , $ endpoints , $ serviceNames );
79
80
}
80
81
81
82
if (\is_int ($ manifest )) {
@@ -88,7 +89,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
88
89
return 0 ;
89
90
}
90
91
91
- private function generateServicesParallel (SymfonyStyle $ io , InputInterface $ input , ConsoleOutputInterface $ output , array $ manifest , array $ serviceNames )
92
+ private function generateServicesParallel (SymfonyStyle $ io , InputInterface $ input , ConsoleOutputInterface $ output , array $ manifest , array $ endpoints , array $ serviceNames )
92
93
{
93
94
$ progress = (new SymfonyStyle ($ input , $ output ->section ()))->createProgressBar ();
94
95
$ progress ->setFormat (' [%bar%] %message% ' );
@@ -102,7 +103,7 @@ private function generateServicesParallel(SymfonyStyle $io, InputInterface $inpu
102
103
throw new \RuntimeException ('Failed to fork ' );
103
104
}
104
105
if (!$ pid ) {
105
- $ code = $ this ->generateService ($ io , $ input , $ manifest , $ serviceName );
106
+ $ code = $ this ->generateService ($ io , $ input , $ manifest , $ endpoints , $ serviceName );
106
107
if (\is_int ($ code )) {
107
108
die ($ code );
108
109
}
@@ -128,7 +129,7 @@ private function generateServicesParallel(SymfonyStyle $io, InputInterface $inpu
128
129
return $ manifest ;
129
130
}
130
131
131
- private function generateServicesSequential (SymfonyStyle $ io , InputInterface $ input , ConsoleOutputInterface $ output , array $ manifest , array $ serviceNames )
132
+ private function generateServicesSequential (SymfonyStyle $ io , InputInterface $ input , ConsoleOutputInterface $ output , array $ manifest , array $ endpoints , array $ serviceNames )
132
133
{
133
134
if (\count ($ serviceNames ) > 1 ) {
134
135
$ progress = (new SymfonyStyle ($ input , $ output ->section ()))->createProgressBar ();
@@ -138,7 +139,7 @@ private function generateServicesSequential(SymfonyStyle $io, InputInterface $in
138
139
}
139
140
140
141
foreach ($ serviceNames as $ serviceName ) {
141
- $ manifest = $ this ->generateService ($ io , $ input , $ manifest , $ serviceName );
142
+ $ manifest = $ this ->generateService ($ io , $ input , $ manifest , $ endpoints , $ serviceName );
142
143
if (\is_int ($ manifest )) {
143
144
return $ manifest ;
144
145
}
@@ -157,9 +158,80 @@ private function generateServicesSequential(SymfonyStyle $io, InputInterface $in
157
158
return $ manifest ;
158
159
}
159
160
160
- private function generateService (SymfonyStyle $ io , InputInterface $ input , array $ manifest , string $ serviceName )
161
+ private function extractEndpointsForService (array $ endpoints , string $ prefix ): array
162
+ {
163
+ $ serviceEndpoints = [];
164
+ foreach ($ endpoints ['partitions ' ] as $ partition ) {
165
+ $ suffix = $ partition ['dnsSuffix ' ];
166
+ $ service = $ partition ['services ' ][$ prefix ] ?? [];
167
+ foreach ($ service ['endpoints ' ] ?? [] as $ region => $ config ) {
168
+ $ hostname = $ config ['hostname ' ] ?? $ service ['defaults ' ]['hostname ' ] ?? $ partition ['defaults ' ]['hostname ' ];
169
+ $ protocols = $ config ['protocols ' ] ?? $ service ['defaults ' ]['protocols ' ] ?? $ partition ['defaults ' ]['protocols ' ] ?? [];
170
+ $ signRegion = $ config ['credentialScope ' ]['region ' ] ?? $ service ['defaults ' ]['credentialScope ' ]['region ' ] ?? $ partition ['defaults ' ]['credentialScope ' ]['region ' ] ?? $ region ;
171
+ $ signService = $ config ['credentialScope ' ]['service ' ] ?? $ service ['defaults ' ]['credentialScope ' ]['service ' ] ?? $ partition ['defaults ' ]['credentialScope ' ]['service ' ] ?? $ prefix ;
172
+ $ signVersions = \array_unique ($ config ['signatureVersions ' ] ?? $ service ['defaults ' ]['signatureVersions ' ] ?? $ partition ['defaults ' ]['signatureVersions ' ] ?? []);
173
+
174
+ if (empty ($ config )) {
175
+ if (!isset ($ serviceEndpoints ['_default ' ][$ partition ['partition ' ]])) {
176
+ $ endpoint = strtr (sprintf ('http%s://%s ' , \in_array ('https ' , $ protocols ) ? 's ' : '' , $ hostname ), [
177
+ '{service} ' => $ prefix ,
178
+ '{region} ' => '%region% ' ,
179
+ '{dnsSuffix} ' => $ suffix ,
180
+ ]);
181
+ $ serviceEndpoints ['_default ' ][$ partition ['partition ' ]] = [
182
+ 'endpoint ' => $ endpoint ,
183
+ 'regions ' => [$ region ],
184
+ 'signService ' => $ signService ,
185
+ 'signVersions ' => $ signVersions ,
186
+ ];
187
+ } else {
188
+ $ serviceEndpoints ['_default ' ][$ partition ['partition ' ]]['regions ' ][] = $ region ;
189
+ }
190
+ } else {
191
+ $ endpoint = strtr (sprintf ('http%s://%s ' , \in_array ('https ' , $ protocols ) ? 's ' : '' , $ hostname ), [
192
+ '{service} ' => $ prefix ,
193
+ '{region} ' => $ region ,
194
+ '{dnsSuffix} ' => $ suffix ,
195
+ ]);
196
+
197
+ $ serviceEndpoints [$ region ] = [
198
+ 'endpoint ' => $ endpoint ,
199
+ 'signRegion ' => $ signRegion ,
200
+ 'signService ' => $ signService ,
201
+ 'signVersions ' => $ signVersions ,
202
+ ];
203
+ }
204
+ }
205
+ if (isset ($ service ['partitionEndpoint ' ])) {
206
+ if (!isset ($ serviceEndpoints [$ service ['partitionEndpoint ' ]])) {
207
+ throw new \RuntimeException ('Missing global region config ' );
208
+ }
209
+ $ serviceEndpoints ['_global ' ][$ partition ['partition ' ]] = $ serviceEndpoints [$ service ['partitionEndpoint ' ]];
210
+ unset($ serviceEndpoints [$ service ['partitionEndpoint ' ]]);
211
+ unset($ serviceEndpoints ['_global ' ][$ partition ['partition ' ]]['region ' ]);
212
+ $ serviceEndpoints ['_global ' ][$ partition ['partition ' ]]['regions ' ] = [];
213
+ if (!($ service ['isRegionalized ' ] ?? true )) {
214
+ foreach ($ partition ['regions ' ] as $ region => $ _ ) {
215
+ if (isset ($ serviceEndpoints [$ region ])) {
216
+ continue ;
217
+ }
218
+ if (\in_array ($ region , $ serviceEndpoints ['_default ' ][$ partition ['partition ' ]]['regions ' ] ?? [])) {
219
+ continue ;
220
+ }
221
+ $ serviceEndpoints ['_global ' ][$ partition ['partition ' ]]['regions ' ][] = $ region ;
222
+ }
223
+ }
224
+ }
225
+ }
226
+
227
+ return $ serviceEndpoints ;
228
+ }
229
+
230
+ private function generateService (SymfonyStyle $ io , InputInterface $ input , array $ manifest , array $ endpoints , string $ serviceName )
161
231
{
162
232
$ definitionArray = $ this ->loadFile ($ manifest ['services ' ][$ serviceName ]['source ' ], "$ serviceName-source " );
233
+ $ endpoints = $ this ->extractEndpointsForService ($ endpoints , $ definitionArray ['metadata ' ]['endpointPrefix ' ]);
234
+
163
235
$ documentationArray = $ this ->loadFile ($ manifest ['services ' ][$ serviceName ]['documentation ' ], "$ serviceName-documentation " );
164
236
$ paginationArray = $ this ->loadFile ($ manifest ['services ' ][$ serviceName ]['pagination ' ], "$ serviceName-pagination " );
165
237
$ waiterArray = isset ($ manifest ['services ' ][$ serviceName ]['waiter ' ]) ? $ this ->loadFile ($ manifest ['services ' ][$ serviceName ]['waiter ' ], "$ serviceName-waiter " ) : ['waiters ' => []];
@@ -171,7 +243,7 @@ private function generateService(SymfonyStyle $io, InputInterface $input, array
171
243
}
172
244
173
245
$ managedOperations = \array_unique (\array_merge ($ manifest ['services ' ][$ serviceName ]['methods ' ], $ operationNames ));
174
- $ definition = new ServiceDefinition ($ serviceName , $ definitionArray , $ documentationArray , $ paginationArray , $ waiterArray , $ exampleArray );
246
+ $ definition = new ServiceDefinition ($ serviceName , $ endpoints , $ definitionArray , $ documentationArray , $ paginationArray , $ waiterArray , $ exampleArray );
175
247
$ serviceGenerator = $ this ->generator ->service ($ manifest ['services ' ][$ serviceName ]['namespace ' ] ?? \sprintf ('AsyncAws \\%s ' , $ serviceName ), $ managedOperations );
176
248
177
249
$ clientClass = $ serviceGenerator ->client ()->generate ($ definition );
0 commit comments