From 53f4ae981aa5dab32b2d3e0c3d1efa16fd488fef Mon Sep 17 00:00:00 2001 From: isma91 Date: Wed, 17 Feb 2016 15:48:13 +0100 Subject: [PATCH] [access.s3] Adding SDKv3 compatibility --- .../access.s3/class.s3AccessDriver.php | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/core/src/plugins/access.s3/class.s3AccessDriver.php b/core/src/plugins/access.s3/class.s3AccessDriver.php index 7f7744110a..193af78205 100755 --- a/core/src/plugins/access.s3/class.s3AccessDriver.php +++ b/core/src/plugins/access.s3/class.s3AccessDriver.php @@ -19,11 +19,9 @@ * The latest code can be found at . * */ - defined('AJXP_EXEC') or die( 'Access not allowed'); -use Aws\S3\S3Client; use Guzzle\Plugin\Log\LogPlugin; - +use AccessS3\S3Client; /** * AJXP_Plugin to access a webdav enabled server * @package AjaXplorer_Plugins @@ -56,9 +54,10 @@ public function detectStreamWrapper($register = false){ if(isSet($this->repository)){ require_once("aws.phar"); + require_once __DIR__ . DIRECTORY_SEPARATOR . 'class.pydioS3Client.php'; $options = array( 'key' => $this->repository->getOption("API_KEY"), - 'secret' => $this->repository->getOption("SECRET_KEY") + 'secret' => $this->repository->getOption("SECRET_KEY"), ); $signatureVersion = $this->repository->getOption("SIGNATURE_VERSION"); if(!empty($signatureVersion) && $signatureVersion != "-1"){ @@ -76,13 +75,26 @@ public function detectStreamWrapper($register = false){ if(!empty($proxy)){ $options['request.options'] = array('proxy' => $proxy); } - $this->s3Client = S3Client::factory($options); - - if($this->repository->getOption("VHOST_NOT_SUPPORTED")){ - // Use virtual hosted buckets when possible - require_once("ForcePathStyleListener.php"); - $this->s3Client->addSubscriber(new \Aws\S3\ForcePathStyleStyleListener()); + $apiVersion = $this->repository->getOption("API_VERSION"); + if ($apiVersion === "") { + $apiVersion = "latest"; } + $sdkVersion = $this->getFilteredOption("SDK_VERSION"); + if ($sdkVersion === "v3") { + $this->s3Client = new S3Client([ + "version" => $apiVersion, + "region" => $region, + "credentials" => $options + ]); + } else { + $this->s3Client = S3Client::factory($options); + if($this->repository->getOption("VHOST_NOT_SUPPORTED")){ + // Use virtual hosted buckets when possible + require_once("ForcePathStyleListener.php"); + $this->s3Client->addSubscriber(new \Aws\S3\ForcePathStyleStyleListener()); + } + } + $this->s3Client->registerStreamWrapper(); }