Permalink
Browse files

Simplify S3 as we embed the sdk, no need to handle v2 / v3 case anymo…

…re, VHOST_UNSUPPORTED not required either.
  • Loading branch information...
1 parent 00c1338 commit 0af9d4ea3ec71fb43c82b06d90da4dc59ba30d3b @cdujeu cdujeu committed Sep 21, 2016
Showing with 24 additions and 57 deletions.
  1. +24 −55 core/src/plugins/access.s3/S3AccessWrapper.php
  2. +0 −2 core/src/plugins/access.s3/manifest.xml
@@ -85,45 +85,29 @@ protected static function getClientForContext(ContextInterface $ctx, $registerSt
if (!empty($signatureVersion)) {
$options['signature'] = $signatureVersion;
}
- $baseURL = $repoObject->getContextOption($ctx, "STORAGE_URL");
- if (!empty($baseURL)) {
- $options["base_url"] = $baseURL;
+ $apiVersion = $repoObject->getContextOption($ctx, "API_VERSION");
+ if ($apiVersion === "") {
+ $apiVersion = "latest";
}
+ $config = [
+ "version" => $apiVersion,
+ "credentials" => $options
+ ];
$region = $repoObject->getContextOption($ctx, "REGION");
if (!empty($region)) {
- $options["region"] = $region;
+ $config["region"] = $region;
}
$proxy = $repoObject->getContextOption($ctx, "PROXY");
if (!empty($proxy)) {
- $options['request.options'] = array('proxy' => $proxy);
- }
- $apiVersion = $repoObject->getContextOption($ctx, "API_VERSION");
- if ($apiVersion === "") {
- $apiVersion = "latest";
+ $config['http'] = array('proxy' => $proxy);
}
- //SDK_VERSION IS A GLOBAL PARAM
- ConfService::getConfStorageImpl()->_loadPluginConfig("access.s3", $globalOptions);
- $sdkVersion = $globalOptions["SDK_VERSION"];
- if ($sdkVersion !== "v2" && $sdkVersion !== "v3") {
- $sdkVersion = "v2";
- }
- if ($sdkVersion === "v3") {
- require_once("S3Client.php");
- $s3Client = new S3Client([
- "version" => $apiVersion,
- "region" => $region,
- "credentials" => $options
- ]);
- $s3Client->registerStreamWrapper($repoObject->getId());
- } else {
- $s3Client = \Aws\S3\S3Client::factory($options);
- if ($repoObject->getContextOption($ctx, "VHOST_NOT_SUPPORTED")) {
- // Use virtual hosted buckets when possible
- require_once("ForcePathStyleListener.php");
- $s3Client->addSubscriber(new \Pydio\Access\Driver\StreamProvider\S3\ForcePathStyleStyleListener());
- }
- $s3Client->registerStreamWrapper();
+ $baseURL = $repoObject->getContextOption($ctx, "STORAGE_URL");
+ if (!empty($baseURL)) {
+ $config["endpoint"] = $baseURL;
}
+ require_once("S3Client.php");
+ $s3Client = new S3Client($config);
+ $s3Client->registerStreamWrapper($repoObject->getId());
self::$clients[$repoObject->getId()] = $s3Client;
}
return self::$clients[$repoObject->getId()];
@@ -403,31 +387,16 @@ public function rename($from, $to)
$toDelete[] = $currentFrom;
}
Logger::debug(__CLASS__, __FUNCTION__, "S3 Execute batch on " . count($batch) . " objects");
- ConfService::getConfStorageImpl()->_loadPluginConfig("access.s3", $globalOptions);
- $sdkVersion = $globalOptions["SDK_VERSION"];
- if ($sdkVersion === "v3") {
- foreach ($batch as $command) {
- $successful = $s3Client->execute($command);
- }
- //We must delete the "/" in $fromKeyname because we want to delete the folder
- $clear = \Aws\S3\BatchDelete::fromIterator($s3Client, $bucket, $s3Client->getIterator('ListObjects', array(
- 'Bucket' => $bucket,
- 'Prefix' => $fromKeyname
- )));
- $clear->delete();
- } else {
- try {
- $successful = $s3Client->execute($batch);
- $clear = new \Aws\S3\Model\ClearBucket($s3Client, $bucket);
- $iterator->rewind();
- $clear->setIterator($iterator);
- $clear->clear();
- $failed = array();
- } catch (\Guzzle\Service\Exception\CommandTransferException $e) {
- $successful = $e->getSuccessfulCommands();
- $failed = $e->getFailedCommands();
- }
+ foreach ($batch as $command) {
+ $successful = $s3Client->execute($command);
}
+ //We must delete the "/" in $fromKeyname because we want to delete the folder
+ $clear = \Aws\S3\BatchDelete::fromIterator($s3Client, $bucket, $s3Client->getIterator('ListObjects', array(
+ 'Bucket' => $bucket,
+ 'Prefix' => $fromKeyname
+ )));
+ $clear->delete();
+
if (count($failed)) {
foreach ($failed as $c) {
// $c is a Aws\S3\Command\S3Command
@@ -16,9 +16,7 @@
<param name="API_VERSION" group="CONF_MESSAGE[API]" type="string" label="CONF_MESSAGE[API Version]" description="CONF_MESSAGE[The API Version of AS3 is a date (like 2006-03-01). If not sure, put latest ]" mandatory="true" default="latest"/>
<param name="PROXY" group="CONF_MESSAGE[Custom Storage]" type="string" label="CONF_MESSAGE[Proxy]" description="CONF_MESSAGE[If you are using a proxy, for example: 127.0.0.1:80 or username:password@127.0.0.1:8080]" mandatory="false"/>
<param name="STORAGE_URL" group="CONF_MESSAGE[Custom Storage]" type="string" label="CONF_MESSAGE[Storage URL]" description="CONF_MESSAGE[Replace default AWS access points (built from region). Set a full URL, including protocol]" mandatory="false"/>
- <param name="VHOST_NOT_SUPPORTED" group="CONF_MESSAGE[Custom Storage]" type="boolean" label="CONF_MESSAGE[Disable Virtual Host Syntax]" description="CONF_MESSAGE[S3 backends can be queried using protocol://bucket.host/. Some backend do not support this, use this option to force using protocol://host/bucket instead]" mandatory="false"/>
<param name="IS_VIPR" group="CONF_MESSAGE[Custom Storage]" type="boolean" label="CONF_MESSAGE[Is ViPR]" description="CONF_MESSAGE[If the backend storage is an EMC ViPR storage]" mandatory="false"/>
- <global_param name="SDK_VERSION" type="select" choices="v2|SDK Version 2,v3|SDK Version 3" label="CONF_MESSAGE[SDK Version]" description="CONF_MESSAGE[The AWS SDK version]" mandatory="true" default="v2" />
</server_settings>
<registry_contributions>
<external_file filename="plugins/access.fs/fsTemplatePart.xml" include="client_configs/*" exclude=""/>

0 comments on commit 0af9d4e

Please sign in to comment.