update aws sdk and move it to 3rdparty
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
14d94abf06
commit
f62e0a33f3
2
3rdparty
2
3rdparty
|
@ -1 +1 @@
|
||||||
Subproject commit b7f163ff14791e747a0303314c6e17539adbc468
|
Subproject commit a5e1de2925f81eeca18414c52c07d5e63020d7f7
|
|
@ -36,10 +36,6 @@
|
||||||
|
|
||||||
namespace OCA\Files_External\Lib\Storage;
|
namespace OCA\Files_External\Lib\Storage;
|
||||||
|
|
||||||
set_include_path(get_include_path() . PATH_SEPARATOR .
|
|
||||||
\OC_App::getAppPath('files_external') . '/3rdparty/aws-sdk-php');
|
|
||||||
require_once 'aws-autoloader.php';
|
|
||||||
|
|
||||||
use Aws\S3\S3Client;
|
use Aws\S3\S3Client;
|
||||||
use Aws\S3\Exception\S3Exception;
|
use Aws\S3\Exception\S3Exception;
|
||||||
use Icewind\Streams\CallbackWrapper;
|
use Icewind\Streams\CallbackWrapper;
|
||||||
|
@ -230,21 +226,29 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$files = array();
|
$files = array();
|
||||||
$result = $this->getConnection()->getIterator('ListObjects', array(
|
$results = $this->getConnection()->getPaginator('ListObjects', [
|
||||||
'Bucket' => $this->bucket,
|
'Bucket' => $this->bucket,
|
||||||
'Delimiter' => '/',
|
'Delimiter' => '/',
|
||||||
'Prefix' => $path
|
'Prefix' => $path,
|
||||||
), array('return_prefixes' => true));
|
]);
|
||||||
|
|
||||||
foreach ($result as $object) {
|
foreach ($results as $result) {
|
||||||
if (isset($object['Key']) && $object['Key'] === $path) {
|
// sub folders
|
||||||
// it's the directory itself, skip
|
if (is_array($result['CommonPrefixes'])) {
|
||||||
continue;
|
foreach ($result['CommonPrefixes'] as $prefix) {
|
||||||
|
$files[] = substr(trim($prefix['Prefix'], '/'), strlen($path));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach ($result['Contents'] as $object) {
|
||||||
|
if (isset($object['Key']) && $object['Key'] === $path) {
|
||||||
|
// it's the directory itself, skip
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$file = basename(
|
||||||
|
isset($object['Key']) ? $object['Key'] : $object['Prefix']
|
||||||
|
);
|
||||||
|
$files[] = $file;
|
||||||
}
|
}
|
||||||
$file = basename(
|
|
||||||
isset($object['Key']) ? $object['Key'] : $object['Prefix']
|
|
||||||
);
|
|
||||||
$files[] = $file;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return IteratorDirectory::wrap($files);
|
return IteratorDirectory::wrap($files);
|
||||||
|
@ -270,7 +274,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
||||||
));
|
));
|
||||||
|
|
||||||
$stat['size'] = $result['ContentLength'] ? $result['ContentLength'] : 0;
|
$stat['size'] = $result['ContentLength'] ? $result['ContentLength'] : 0;
|
||||||
if ($result['Metadata']['lastmodified']) {
|
if (isset($result['Metadata']['lastmodified'])) {
|
||||||
$stat['mtime'] = strtotime($result['Metadata']['lastmodified']);
|
$stat['mtime'] = strtotime($result['Metadata']['lastmodified']);
|
||||||
} else {
|
} else {
|
||||||
$stat['mtime'] = strtotime($result['LastModified']);
|
$stat['mtime'] = strtotime($result['LastModified']);
|
||||||
|
|
|
@ -22,11 +22,7 @@
|
||||||
namespace OC\Files\ObjectStore;
|
namespace OC\Files\ObjectStore;
|
||||||
|
|
||||||
use OCP\Files\ObjectStore\IObjectStore;
|
use OCP\Files\ObjectStore\IObjectStore;
|
||||||
|
use Psr\Http\Message\StreamInterface;
|
||||||
// TODO: proper composer
|
|
||||||
set_include_path(get_include_path() . PATH_SEPARATOR .
|
|
||||||
\OC_App::getAppPath('files_external') . '/3rdparty/aws-sdk-php');
|
|
||||||
require_once 'aws-autoloader.php';
|
|
||||||
|
|
||||||
class S3 implements IObjectStore {
|
class S3 implements IObjectStore {
|
||||||
use S3ConnectionTrait;
|
use S3ConnectionTrait;
|
||||||
|
@ -50,31 +46,17 @@ class S3 implements IObjectStore {
|
||||||
* @since 7.0.0
|
* @since 7.0.0
|
||||||
*/
|
*/
|
||||||
function readObject($urn) {
|
function readObject($urn) {
|
||||||
// Create the command and serialize the request
|
$client = $this->getConnection();
|
||||||
$request = $this->getConnection()->getCommand('GetObject', [
|
$command = $client->getCommand('GetObject', [
|
||||||
'Bucket' => $this->bucket,
|
'Bucket' => $this->bucket,
|
||||||
'Key' => $urn
|
'Key' => $urn
|
||||||
])->prepare();
|
]);
|
||||||
|
$command['@http']['stream'] = true;
|
||||||
|
$result = $client->execute($command);
|
||||||
|
/** @var StreamInterface $body */
|
||||||
|
$body = $result['Body'];
|
||||||
|
|
||||||
$request->dispatch('request.before_send', array(
|
return $body->detach();
|
||||||
'request' => $request
|
|
||||||
));
|
|
||||||
|
|
||||||
$headers = $request->getHeaderLines();
|
|
||||||
$headers[] = 'Connection: close';
|
|
||||||
|
|
||||||
$opts = [
|
|
||||||
'http' => [
|
|
||||||
'method' => "GET",
|
|
||||||
'header' => $headers
|
|
||||||
],
|
|
||||||
'ssl' => [
|
|
||||||
'verify_peer' => true
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$context = stream_context_create($opts);
|
|
||||||
return fopen($request->getUrl(), 'r', false, $context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,7 +53,7 @@ trait S3ConnectionTrait {
|
||||||
$this->bucket = $params['bucket'];
|
$this->bucket = $params['bucket'];
|
||||||
$this->timeout = (!isset($params['timeout'])) ? 15 : $params['timeout'];
|
$this->timeout = (!isset($params['timeout'])) ? 15 : $params['timeout'];
|
||||||
$params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
|
$params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
|
||||||
$params['hostname'] = empty($params['hostname']) ? 's3.amazonaws.com' : $params['hostname'];
|
$params['hostname'] = empty($params['hostname']) ? 's3.' . $params['region'] . '.amazonaws.com' : $params['hostname'];
|
||||||
if (!isset($params['port']) || $params['port'] === '') {
|
if (!isset($params['port']) || $params['port'] === '') {
|
||||||
$params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443;
|
$params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443;
|
||||||
}
|
}
|
||||||
|
@ -76,20 +76,23 @@ trait S3ConnectionTrait {
|
||||||
$base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';
|
$base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';
|
||||||
|
|
||||||
$options = [
|
$options = [
|
||||||
'key' => $this->params['key'],
|
'version' => isset($this->params['version']) ? $this->params['version'] : 'latest',
|
||||||
'secret' => $this->params['secret'],
|
'credentials' => [
|
||||||
'base_url' => $base_url,
|
'key' => $this->params['key'],
|
||||||
|
'secret' => $this->params['secret'],
|
||||||
|
],
|
||||||
|
'endpoint' => $base_url,
|
||||||
'region' => $this->params['region'],
|
'region' => $this->params['region'],
|
||||||
S3Client::COMMAND_PARAMS => [
|
'command.params' => [
|
||||||
'PathStyle' => isset($this->params['use_path_style']) ? $this->params['use_path_style'] : false,
|
'PathStyle' => isset($this->params['use_path_style']) ? $this->params['use_path_style'] : false,
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
if (isset($this->params['proxy'])) {
|
if (isset($this->params['proxy'])) {
|
||||||
$options[S3Client::REQUEST_OPTIONS] = ['proxy' => $this->params['proxy']];
|
$options['request.options'] = ['proxy' => $this->params['proxy']];
|
||||||
}
|
}
|
||||||
$this->connection = S3Client::factory($options);
|
$this->connection = new S3Client($options);
|
||||||
|
|
||||||
if (!$this->connection->isValidBucketName($this->bucket)) {
|
if (!S3Client::isBucketDnsCompatible($this->bucket)) {
|
||||||
throw new \Exception("The configured bucket name is invalid.");
|
throw new \Exception("The configured bucket name is invalid.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,11 +101,6 @@ trait S3ConnectionTrait {
|
||||||
$this->connection->createBucket(array(
|
$this->connection->createBucket(array(
|
||||||
'Bucket' => $this->bucket
|
'Bucket' => $this->bucket
|
||||||
));
|
));
|
||||||
$this->connection->waitUntilBucketExists(array(
|
|
||||||
'Bucket' => $this->bucket,
|
|
||||||
'waiter.interval' => 1,
|
|
||||||
'waiter.max_attempts' => 15
|
|
||||||
));
|
|
||||||
$this->testTimeout();
|
$this->testTimeout();
|
||||||
} catch (S3Exception $e) {
|
} catch (S3Exception $e) {
|
||||||
\OCP\Util::logException('files_external', $e);
|
\OCP\Util::logException('files_external', $e);
|
||||||
|
|
Loading…
Reference in New Issue