fix(proxy): reaching s3 storage behind some http proxy

Signed-off-by: Maxime Besson <maxime.besson@worteks.com>
pull/26463/head
Samuel 2021-03-13 12:05:27 +07:00 committed by Maxime Besson
parent 32551b9ff7
commit 03fe74b95e
2 changed files with 15 additions and 2 deletions

@ -57,6 +57,9 @@ trait S3ConnectionTrait {
/** @var int */ /** @var int */
protected $timeout; protected $timeout;
/** @var string */
protected $proxy;
/** @var int */ /** @var int */
protected $uploadPartSize; protected $uploadPartSize;
@ -71,6 +74,7 @@ trait S3ConnectionTrait {
$this->test = isset($params['test']); $this->test = isset($params['test']);
$this->bucket = $params['bucket']; $this->bucket = $params['bucket'];
$this->proxy = isset($params['proxy']) ? $params['proxy'] : false;
$this->timeout = !isset($params['timeout']) ? 15 : $params['timeout']; $this->timeout = !isset($params['timeout']) ? 15 : $params['timeout'];
$this->uploadPartSize = !isset($params['uploadPartSize']) ? 524288000 : $params['uploadPartSize']; $this->uploadPartSize = !isset($params['uploadPartSize']) ? 524288000 : $params['uploadPartSize'];
$params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region']; $params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
@ -86,6 +90,10 @@ trait S3ConnectionTrait {
return $this->bucket; return $this->bucket;
} }
public function getProxy() {
return $this->proxy;
}
/** /**
* Returns the connection * Returns the connection
* *
@ -123,7 +131,7 @@ trait S3ConnectionTrait {
'csm' => false, 'csm' => false,
]; ];
if (isset($this->params['proxy'])) { if (isset($this->params['proxy'])) {
$options['request.options'] = ['proxy' => $this->params['proxy']]; $options['http'] = [ 'proxy' => $this->params['proxy'] ];
} }
if (isset($this->params['legacy_auth']) && $this->params['legacy_auth']) { if (isset($this->params['legacy_auth']) && $this->params['legacy_auth']) {
$options['signature_version'] = 'v2'; $options['signature_version'] = 'v2';

@ -51,7 +51,8 @@ trait S3ObjectTrait {
*/ */
public function readObject($urn) { public function readObject($urn) {
return SeekableHttpStream::open(function ($range) use ($urn) { return SeekableHttpStream::open(function ($range) use ($urn) {
$command = $this->getConnection()->getCommand('GetObject', [ $connection = $this->getConnection();
$command = $connection->getCommand('GetObject', [
'Bucket' => $this->bucket, 'Bucket' => $this->bucket,
'Key' => $urn, 'Key' => $urn,
'Range' => 'bytes=' . $range, 'Range' => 'bytes=' . $range,
@ -70,6 +71,10 @@ trait S3ObjectTrait {
], ],
]; ];
if ($connection->getProxy()) {
$opts['http']['proxy'] = $connection->getProxy();
}
$context = stream_context_create($opts); $context = stream_context_create($opts);
return fopen($request->getUri(), 'r', false, $context); return fopen($request->getUri(), 'r', false, $context);
}); });