updated-packages
This commit is contained in:
55
vendor/aws/aws-sdk-php/src/TraceMiddleware.php
vendored
55
vendor/aws/aws-sdk-php/src/TraceMiddleware.php
vendored
@@ -1,11 +1,14 @@
|
||||
<?php
|
||||
namespace Aws;
|
||||
|
||||
use Aws\Api\Service;
|
||||
use Aws\Exception\AwsException;
|
||||
use GuzzleHttp\Promise\RejectedPromise;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use RecursiveArrayIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
/**
|
||||
* Traces state changes between middlewares.
|
||||
@@ -16,6 +19,9 @@ class TraceMiddleware
|
||||
private $prevInput;
|
||||
private $config;
|
||||
|
||||
/** @var Service */
|
||||
private $service;
|
||||
|
||||
private static $authHeaders = [
|
||||
'X-Amz-Security-Token' => '[TOKEN]',
|
||||
];
|
||||
@@ -56,7 +62,7 @@ class TraceMiddleware
|
||||
* headers contained in this array will be replaced with the if
|
||||
* "scrub_auth" is set to true.
|
||||
*/
|
||||
public function __construct(array $config = [])
|
||||
public function __construct(array $config = [], Service $service = null)
|
||||
{
|
||||
$this->config = $config + [
|
||||
'logfn' => function ($value) { echo $value; },
|
||||
@@ -69,6 +75,7 @@ class TraceMiddleware
|
||||
|
||||
$this->config['auth_strings'] += self::$authStrings;
|
||||
$this->config['auth_headers'] += self::$authHeaders;
|
||||
$this->service = $service;
|
||||
}
|
||||
|
||||
public function __invoke($step, $name)
|
||||
@@ -153,7 +160,7 @@ class TraceMiddleware
|
||||
return [
|
||||
'instance' => spl_object_hash($cmd),
|
||||
'name' => $cmd->getName(),
|
||||
'params' => $cmd->toArray()
|
||||
'params' => $this->getRedactedArray($cmd)
|
||||
];
|
||||
}
|
||||
|
||||
@@ -279,9 +286,11 @@ class TraceMiddleware
|
||||
private function flushHttpDebug(CommandInterface $command)
|
||||
{
|
||||
if ($res = $command['@http']['debug']) {
|
||||
rewind($res);
|
||||
$this->write(stream_get_contents($res));
|
||||
fclose($res);
|
||||
if (is_resource($res)) {
|
||||
rewind($res);
|
||||
$this->write(stream_get_contents($res));
|
||||
fclose($res);
|
||||
}
|
||||
$command['@http']['debug'] = null;
|
||||
}
|
||||
}
|
||||
@@ -311,4 +320,40 @@ class TraceMiddleware
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CommandInterface $cmd
|
||||
* @return array
|
||||
*/
|
||||
private function getRedactedArray(CommandInterface $cmd)
|
||||
{
|
||||
if (!isset($this->service["shapes"])) {
|
||||
return $cmd->toArray();
|
||||
}
|
||||
$shapes = $this->service["shapes"];
|
||||
$cmdArray = $cmd->toArray();
|
||||
$iterator = new RecursiveIteratorIterator(
|
||||
new RecursiveArrayIterator($cmdArray),
|
||||
RecursiveIteratorIterator::SELF_FIRST
|
||||
);
|
||||
foreach ($iterator as $parameter => $value) {
|
||||
if (isset($shapes[$parameter]['sensitive']) &&
|
||||
$shapes[$parameter]['sensitive'] === true
|
||||
) {
|
||||
$redactedValue = is_string($value) ? "[{$parameter}]" : ["[{$parameter}]"];
|
||||
$currentDepth = $iterator->getDepth();
|
||||
for ($subDepth = $currentDepth; $subDepth >= 0; $subDepth--) {
|
||||
$subIterator = $iterator->getSubIterator($subDepth);
|
||||
$subIterator->offsetSet(
|
||||
$subIterator->key(),
|
||||
($subDepth === $currentDepth
|
||||
? $redactedValue
|
||||
: $iterator->getSubIterator(($subDepth+1))->getArrayCopy()
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $iterator->getArrayCopy();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user