Compare commits

...

16 Commits

Author SHA1 Message Date
Roeland Jago Douma 4cfed32803
Merge pull request #9378 from nextcloud/backport/9364/swift-v3
[swiftv3] Log mount and storage issues in getFileInfo
2018-05-03 12:32:13 +02:00
Robin Appelman 0bfda02e14
Log mount and storage issues in getFileInfo
Signed-off-by: Robin Appelman <robin@icewind.nl>
2018-05-03 12:05:11 +02:00
Morris Jobke d6dea09f48
Merge pull request #9323 from nextcloud/backport/9322/swift-v3
[swift]  Better swift V3 token handling
2018-04-26 22:55:58 +02:00
Roeland Jago Douma 1dd7193047
generateTokenFromCache is only valid for V3
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2018-04-26 22:10:29 +02:00
Roeland Jago Douma a1e379986b
json_decode an associative array for the swift cached token
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2018-04-26 22:10:23 +02:00
Roeland Jago Douma e0e687f2a7
Merge pull request #9287 from nextcloud/backport/9280/stable-swift-v3
[swift] Swift v3 requires setting a scope
2018-04-24 11:05:18 +02:00
Roeland Jago Douma 7969301976
Swift v3 requires setting a scope
Unscoped auth is not guaranteed to return a catalog. So require the
scope to be set properly.

See https://developer.openstack.org/api-ref/identity/v3/index.html#password-authentication-with-unscoped-authorization

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2018-04-24 09:50:22 +02:00
Morris Jobke 04eed20a64
Merge pull request #9149 from nextcloud/swift-updates
[swift] Fix searchdav
2018-04-11 15:54:22 +02:00
Roeland Jago Douma 196a10ad4d
Update 3rdparty
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2018-04-11 14:49:57 +02:00
Roeland Jago Douma 9edd8a62c1
Make displayname selectable
It is dav. so if it is not properly set we just return a 404 anyway.
2018-04-11 14:49:22 +02:00
Roeland Jago Douma 1358d617ab
Bump openstack to 3.0.5
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2018-03-22 10:15:20 +01:00
Robin Appelman 4ff31c0eca
verify cached swift token
Signed-off-by: Robin Appelman <robin@icewind.nl>
2018-03-22 10:15:17 +01:00
Roeland Jago Douma f4ce7753a5
Fix bucket and container usage
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2018-03-22 10:15:11 +01:00
Roeland Jago Douma 1cf77b4483
Properly cache swift v3 token
The V3 token has an export function. Without this the token is
effectively never cached.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
2018-03-22 10:15:05 +01:00
Robin Appelman 195db56c22
disable part files for object stores
Signed-off-by: Robin Appelman <robin@icewind.nl>
2018-03-22 10:14:55 +01:00
Robin Appelman 34ea14af1d
don't read existing file when overwriting using object store
Signed-off-by: Robin Appelman <robin@icewind.nl>
2018-03-22 10:14:46 +01:00
8 changed files with 79 additions and 29 deletions

@ -1 +1 @@
Subproject commit 8168fc1d0f33445ec4158867421dfaa9a0e241d7 Subproject commit 49a3f672142d047a901329a6e1ea2ad582b7d681

View File

@ -113,7 +113,7 @@ class FileSearchBackend implements ISearchBackend {
//todo dynamically load all propfind properties that are supported //todo dynamically load all propfind properties that are supported
return [ return [
// queryable properties // queryable properties
new SearchPropertyDefinition('{DAV:}displayname', true, false, true), new SearchPropertyDefinition('{DAV:}displayname', true, true, true),
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME), new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER), new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),

View File

@ -194,7 +194,11 @@ class Swift extends \OC\Files\Storage\Common {
$this->params = $params; $this->params = $params;
// FIXME: private class... // FIXME: private class...
$this->objectCache = new \OC\Cache\CappedMemoryCache(); $this->objectCache = new \OC\Cache\CappedMemoryCache();
$this->connectionFactory = new SwiftFactory(\OC::$server->getMemCacheFactory()->createDistributed('swift/'), $this->params); $this->connectionFactory = new SwiftFactory(
\OC::$server->getMemCacheFactory()->createDistributed('swift/'),
$this->params,
\OC::$server->getLogger()
);
$this->objectStore = new \OC\Files\ObjectStore\Swift($this->params, $this->connectionFactory); $this->objectStore = new \OC\Files\ObjectStore\Swift($this->params, $this->connectionFactory);
$this->bucket = $params['bucket']; $this->bucket = $params['bucket'];
} }

View File

@ -1226,13 +1226,21 @@ $CONFIG = array(
'password' => 'swift', 'password' => 'swift',
'domain' => [ 'domain' => [
'name' => 'default', 'name' => 'default',
] ],
],
'scope' => [
'project' => [
'name' => 'service',
'domain' => [
'name' => 'default',
],
],
], ],
'tenantName' => 'service', 'tenantName' => 'service',
'serviceName' => 'swift', 'serviceName' => 'swift',
'region' => 'regionOne', 'region' => 'regionOne',
'url' => "http://yourswifthost:5000/v3", 'url' => 'http://yourswifthost:5000/v3',
'bucket' => 'nextcloud' 'bucket' => 'nextcloud',
], ],
], ],

View File

@ -261,6 +261,12 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
public function fopen($path, $mode) { public function fopen($path, $mode) {
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
switch ($mode) { switch ($mode) {
case 'r': case 'r':
case 'rb': case 'rb':
@ -280,21 +286,21 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
} }
case 'w': case 'w':
case 'wb': case 'wb':
case 'w+':
case 'wb+':
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
$handle = fopen($tmpFile, $mode);
return CallbackWrapper::wrap($handle, null, null, function () use ($path, $tmpFile) {
$this->writeBack($tmpFile, $path);
});
case 'a': case 'a':
case 'ab': case 'ab':
case 'r+': case 'r+':
case 'w+':
case 'wb+':
case 'a+': case 'a+':
case 'x': case 'x':
case 'x+': case 'x+':
case 'c': case 'c':
case 'c+': case 'c+':
if (strrpos($path, '.') !== false) {
$ext = substr($path, strrpos($path, '.'));
} else {
$ext = '';
}
$tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext); $tmpFile = \OC::$server->getTempManager()->getTemporaryFile($ext);
if ($this->file_exists($path)) { if ($this->file_exists($path)) {
$source = $this->fopen($path, 'r'); $source = $this->fopen($path, 'r');
@ -423,4 +429,8 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common {
public function hasUpdated($path, $time) { public function hasUpdated($path, $time) {
return false; return false;
} }
public function needsPartFile() {
return false;
}
} }

View File

@ -36,16 +36,15 @@ class Swift implements IObjectStore {
*/ */
private $params; private $params;
/**
* @var \OpenStack\ObjectStore\v1\Models\Container|null
*/
private $container = null;
/** @var SwiftFactory */ /** @var SwiftFactory */
private $swiftFactory; private $swiftFactory;
public function __construct($params, SwiftFactory $connectionFactory = null) { public function __construct($params, SwiftFactory $connectionFactory = null) {
$this->swiftFactory = $connectionFactory ?: new SwiftFactory(\OC::$server->getMemCacheFactory()->createDistributed('swift::'), $params); $this->swiftFactory = $connectionFactory ?: new SwiftFactory(
\OC::$server->getMemCacheFactory()->createDistributed('swift::'),
$params,
\OC::$server->getLogger()
);
$this->params = $params; $this->params = $params;
} }
@ -62,6 +61,10 @@ class Swift implements IObjectStore {
* @return string the container name where objects are stored * @return string the container name where objects are stored
*/ */
public function getStorageId() { public function getStorageId() {
if (isset($this->params['bucket'])) {
return $this->params['bucket'];
}
return $this->params['container']; return $this->params['container'];
} }

View File

@ -30,6 +30,7 @@ use GuzzleHttp\HandlerStack;
use OCP\Files\StorageAuthException; use OCP\Files\StorageAuthException;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\ICache; use OCP\ICache;
use OCP\ILogger;
use OpenStack\Common\Error\BadResponseError; use OpenStack\Common\Error\BadResponseError;
use OpenStack\Common\Auth\Token; use OpenStack\Common\Auth\Token;
use OpenStack\Identity\v2\Service as IdentityV2Service; use OpenStack\Identity\v2\Service as IdentityV2Service;
@ -44,23 +45,30 @@ class SwiftFactory {
private $params; private $params;
/** @var Container|null */ /** @var Container|null */
private $container = null; private $container = null;
private $logger;
public function __construct(ICache $cache, array $params) { public function __construct(ICache $cache, array $params, ILogger $logger) {
$this->cache = $cache; $this->cache = $cache;
$this->params = $params; $this->params = $params;
$this->logger = $logger;
} }
private function getCachedToken(string $cacheKey) { private function getCachedToken(string $cacheKey) {
$cachedTokenString = $this->cache->get($cacheKey . '/token'); $cachedTokenString = $this->cache->get($cacheKey . '/token');
if ($cachedTokenString) { if ($cachedTokenString) {
return json_decode($cachedTokenString); return json_decode($cachedTokenString, true);
} else { } else {
return null; return null;
} }
} }
private function cacheToken(Token $token, string $cacheKey) { private function cacheToken(Token $token, string $cacheKey) {
$this->cache->set($cacheKey . '/token', json_encode($token)); if ($token instanceof \OpenStack\Identity\v3\Models\Token) {
$value = json_encode($token->export());
} else {
$value = json_encode($token);
}
$this->cache->set($cacheKey . '/token', $value);
} }
/** /**
@ -72,7 +80,7 @@ class SwiftFactory {
$this->params['container'] = $this->params['bucket']; $this->params['container'] = $this->params['bucket'];
} }
if (!isset($this->params['container'])) { if (!isset($this->params['container'])) {
$this->params['container'] = 'owncloud'; $this->params['container'] = 'nextcloud';
} }
if (!isset($this->params['autocreate'])) { if (!isset($this->params['autocreate'])) {
// should only be true for tests // should only be true for tests
@ -90,12 +98,9 @@ class SwiftFactory {
$this->params['tenantName'] = $this->params['tenant']; $this->params['tenantName'] = $this->params['tenant'];
} }
$cacheKey = $userName . '@' . $this->params['url'] . '/' . $this->params['bucket']; $cacheKey = $userName . '@' . $this->params['url'] . '/' . $this->params['container'];
$token = $this->getCachedToken($cacheKey); $token = $this->getCachedToken($cacheKey);
$hasToken = is_array($token) && (new \DateTimeImmutable($token['expires_at'])) > (new \DateTimeImmutable('now')); $this->params['cachedToken'] = $token;
if ($hasToken) {
$this->params['cachedToken'] = $token;
}
$httpClient = new Client([ $httpClient = new Client([
'base_uri' => TransportUtils::normalizeUrl($this->params['url']), 'base_uri' => TransportUtils::normalizeUrl($this->params['url']),
@ -103,6 +108,10 @@ class SwiftFactory {
]); ]);
if (isset($this->params['user']) && isset($this->params['user']['name'])) { if (isset($this->params['user']) && isset($this->params['user']['name'])) {
if (!isset($this->params['scope'])) {
throw new StorageAuthException('Scope has to be defined for V3 requests');
}
return $this->auth(IdentityV3Service::factory($httpClient), $cacheKey); return $this->auth(IdentityV3Service::factory($httpClient), $cacheKey);
} else { } else {
return $this->auth(IdentityV2Service::factory($httpClient), $cacheKey); return $this->auth(IdentityV2Service::factory($httpClient), $cacheKey);
@ -120,7 +129,20 @@ class SwiftFactory {
$this->params['authUrl'] = $this->params['url']; $this->params['authUrl'] = $this->params['url'];
$client = new OpenStack($this->params); $client = new OpenStack($this->params);
if (!isset($this->params['cachedToken'])) { $cachedToken = $this->params['cachedToken'];
$hasValidCachedToken = false;
if (\is_array($cachedToken) && ($authService instanceof IdentityV3Service)) {
$token = $authService->generateTokenFromCache($cachedToken);
if (\is_null($token->catalog)) {
$this->logger->warning('Invalid cached token for swift, no catalog set: ' . json_encode($cachedToken));
} else if ($token->hasExpired()) {
$this->logger->debug('Cached token for swift expired');
} else {
$hasValidCachedToken = true;
}
}
if (!$hasValidCachedToken) {
try { try {
$token = $authService->generateToken($this->params); $token = $authService->generateToken($this->params);
$this->cacheToken($token, $cacheKey); $this->cacheToken($token, $cacheKey);

View File

@ -1360,6 +1360,7 @@ class View {
$mount = Filesystem::getMountManager()->find($path); $mount = Filesystem::getMountManager()->find($path);
if (!$mount) { if (!$mount) {
\OC::$server->getLogger()->warning('Mountpoint not found for path: ' . $path);
return false; return false;
} }
$storage = $mount->getStorage(); $storage = $mount->getStorage();
@ -1391,6 +1392,8 @@ class View {
} }
return $info; return $info;
} else {
\OC::$server->getLogger()->warning('Storage not valid for mountpoint: ' . $mount->getMountPoint());
} }
return false; return false;