11<?php
22namespace Codeception \Lib \Connector ;
33
4+ use Aws \Credentials \Credentials ;
5+ use Aws \Signature \SignatureV4 ;
46use Codeception \Util \Uri ;
57use GuzzleHttp \Exception \RequestException ;
68use GuzzleHttp \Message \Response ;
@@ -19,6 +21,8 @@ class Guzzle extends Client
1921 ];
2022 protected $ refreshMaxInterval = 0 ;
2123
24+ protected $ awsCredentials = null ;
25+ protected $ awsSignature = null ;
2226
2327 /** @var \GuzzleHttp\Client */
2428 protected $ client ;
@@ -198,7 +202,11 @@ protected function doRequest($request)
198202
199203 // Let BrowserKit handle redirects
200204 try {
201- $ response = $ this ->client ->send ($ guzzleRequest );
205+ if (null !== $ this ->awsCredentials ) {
206+ $ response = $ this ->client ->send ($ this ->awsSignature ->signRequest ($ guzzleRequest , $ this ->awsCredentials ));
207+ } else {
208+ $ response = $ this ->client ->send ($ guzzleRequest );
209+ }
202210 } catch (RequestException $ e ) {
203211 if ($ e ->hasResponse ()) {
204212 $ response = $ e ->getResponse ();
@@ -278,4 +286,10 @@ protected function extractCookies(BrowserKitRequest $request)
278286 {
279287 return $ this ->getCookieJar ()->allRawValues ($ request ->getUri ());
280288 }
289+
290+ public function setAwsAuth ($ config )
291+ {
292+ $ this ->awsCredentials = new Credentials ($ config ['key ' ], $ config ['secret ' ]);
293+ $ this ->awsSignature = new SignatureV4 ($ config ['service ' ], $ config ['region ' ]);
294+ }
281295}
0 commit comments