Skip to content

Commit

Permalink
add extention interface to provide a debug description of storages
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jan 15, 2024
1 parent 32bf74a commit ebeb85b
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 50 deletions.
7 changes: 6 additions & 1 deletion apps/files_external/lib/Lib/Storage/AmazonS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\ICache;
use OCP\ICacheFactory;
use OCP\Server;
use Psr\Log\LoggerInterface;

class AmazonS3 extends \OC\Files\Storage\Common {
class AmazonS3 extends \OC\Files\Storage\Common implements IStorageDebugInfo {
use S3ConnectionTrait;
use S3ObjectTrait;

Expand Down Expand Up @@ -787,4 +788,8 @@ public function hasUpdated($path, $time) {
return true;
}
}

function debugInfo(): string {
return "s3 bucket {$this->bucket}";
}
}
7 changes: 6 additions & 1 deletion apps/files_external/lib/Lib/Storage/FTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
use OC\Files\Storage\PolyFill\CopyDirectory;
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageNotAvailableException;
use Psr\Log\LoggerInterface;

class FTP extends Common {
class FTP extends Common implements IStorageDebugInfo {
use CopyDirectory;

private $root;
Expand Down Expand Up @@ -377,4 +378,8 @@ public function getDirectoryContent($directory): \Traversable {
yield $data;
}
}

function debugInfo(): string {
return "ftp share {$this->username}@{$this->host}/{$this->root}";
}
}
7 changes: 6 additions & 1 deletion apps/files_external/lib/Lib/Storage/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@
use OCP\Constants;
use OCP\Files\FileInfo;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorageDebugInfo;
use phpseclib\Net\SFTP\Stream;

/**
* Uses phpseclib's Net\SFTP class and the Net\SFTP\Stream stream wrapper to
* provide access to SFTP servers.
*/
class SFTP extends Common {
class SFTP extends Common implements IStorageDebugInfo {
private $host;
private $user;
private $root;
Expand Down Expand Up @@ -584,4 +585,8 @@ public function getMetaData($path) {
$keys = ['size', 'mtime', 'mimetype', 'etag', 'storage_mtime', 'permissions', 'name'];
return array_intersect_key($stat, array_flip($keys));
}

function debugInfo(): string {
return "sftp share {$this->user}@{$this->host}/{$this->root}";
}
}
26 changes: 25 additions & 1 deletion apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
namespace OCA\Files_External\Lib\Storage;

use Icewind\SMB\ACL;
use Icewind\SMB\AnonymousAuth;
use Icewind\SMB\BasicAuth;
use Icewind\SMB\Exception\AlreadyExistsException;
use Icewind\SMB\Exception\ConnectException;
Expand All @@ -47,7 +48,9 @@
use Icewind\SMB\Exception\NotFoundException;
use Icewind\SMB\Exception\OutOfSpaceException;
use Icewind\SMB\Exception\TimedOutException;
use Icewind\SMB\IAuth;
use Icewind\SMB\IFileInfo;
use Icewind\SMB\KerberosAuth;
use Icewind\SMB\Native\NativeServer;
use Icewind\SMB\Options;
use Icewind\SMB\ServerFactory;
Expand All @@ -64,11 +67,12 @@
use OCP\Files\Notify\IRenameChange;
use OCP\Files\NotPermittedException;
use OCP\Files\Storage\INotifyStorage;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageAuthException;
use OCP\Files\StorageNotAvailableException;
use Psr\Log\LoggerInterface;

class SMB extends Common implements INotifyStorage {
class SMB extends Common implements INotifyStorage, IStorageDebugInfo {
/**
* @var \Icewind\SMB\IServer
*/
Expand Down Expand Up @@ -98,10 +102,14 @@ class SMB extends Common implements INotifyStorage {
/** @var bool */
protected $checkAcl;

private array $params;
private IAuth $auth;

public function __construct($params) {
if (!isset($params['host'])) {
throw new \Exception('Invalid configuration, no host provided');
}
$this->params = $params;

if (isset($params['auth'])) {
$auth = $params['auth'];
Expand Down Expand Up @@ -133,6 +141,7 @@ public function __construct($params) {
}
}
$serverFactory = new ServerFactory($options);
$this->auth = $auth;
$this->server = $serverFactory->createServer($params['host'], $auth);
$this->share = $this->server->getShare(trim($params['share'], '/'));

Expand Down Expand Up @@ -782,4 +791,19 @@ public function notify($path) {
$shareNotifyHandler = $this->share->notify($this->buildPath($path));
return new SMBNotifyHandler($shareNotifyHandler, $this->root);
}

public function debugInfo(): string {
$share = "//{$this->server->getHost()}/{$this->share->getName()}{$this->root}";
if (isset($this->params['user'])) {
$share = "{$this->params['user']}@$share";
}
if ($this->auth instanceof KerberosAuth) {
$auth = "kerberos";
} else if ($this->auth instanceof AnonymousAuth) {
$auth = "anonymous";
} else {
$auth = "password";
}
return "SMB share $share using $auth authentication";
}
}
7 changes: 6 additions & 1 deletion apps/files_external/lib/Lib/Storage/Swift.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@
use Icewind\Streams\IteratorDirectory;
use OC\Files\ObjectStore\SwiftFactory;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageBadConfigException;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\ObjectStore\v1\Models\StorageObject;
use Psr\Log\LoggerInterface;

class Swift extends \OC\Files\Storage\Common {
class Swift extends \OC\Files\Storage\Common implements IStorageDebugInfo {
/** @var SwiftFactory */
private $connectionFactory;
/**
Expand Down Expand Up @@ -627,4 +628,8 @@ public function hasUpdated($path, $time) {
public static function checkDependencies() {
return true;
}

function debugInfo(): string {
return "swift bucket {$this->bucket}";
}
}
7 changes: 6 additions & 1 deletion apps/files_sharing/lib/External/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IReliableEtagStorage;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageInvalidException;
use OCP\Files\StorageNotAvailableException;
use OCP\Http\Client\IClientService;
Expand All @@ -60,7 +61,7 @@
use OCP\Server;
use Psr\Log\LoggerInterface;

class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, IReliableEtagStorage {
class Storage extends DAV implements ISharedStorage, IDisableEncryptionStorage, IReliableEtagStorage, IStorageDebugInfo {
private ICloudId $cloudId;
private string $mountPoint;
private string $token;
Expand Down Expand Up @@ -453,4 +454,8 @@ protected function getDefaultPermissions(string $path): int {
public function free_space($path) {
return parent::free_space("");
}

function debugInfo(): string {
return "external share from {$this->getRemoteUser()}@{$this->getRemote()}";
}
}
38 changes: 37 additions & 1 deletion apps/files_sharing/lib/SharedStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,15 @@
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IDisableEncryptionStorage;
use OCP\Files\Storage\IStorage;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Lock\ILockingProvider;
use OCP\Share\IShare;
use Psr\Log\LoggerInterface;

/**
* Convert target path to source path and pass the function call to the correct storage provider
*/
class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage, IDisableEncryptionStorage {
class SharedStorage extends \OC\Files\Storage\Wrapper\Jail implements ISharedStorage, IDisableEncryptionStorage, IStorageDebugInfo {
/** @var \OCP\Share\IShare */
private $superShare;

Expand Down Expand Up @@ -562,4 +563,39 @@ public function getUnjailedPath($path) {
$this->init();
return parent::getUnjailedPath($path);
}

function debugInfo(): string {
$share = $this->getShare();
$shares = $this->groupedShares;
$sharedBy = array_map(function (IShare $share) {
$shareType = $this->formatShareType($share);
if ($shareType) {
return $share->getSharedBy() . " (via " . $shareType . " " . $share->getSharedWith() . ")";
} else {
return $share->getSharedBy();
}
}, $shares);
$description = "shared by " . implode(', ', $sharedBy);
if ($share->getSharedBy() !== $share->getShareOwner()) {
$description .= " owned by " . $share->getShareOwner();
}
return $description;
}

private function formatShareType(IShare $share): ?string {
switch ($share->getShareType()) {
case IShare::TYPE_GROUP:
return "group";
case IShare::TYPE_CIRCLE:
return "circle";
case IShare::TYPE_DECK:
return "deck";
case IShare::TYPE_ROOM:
return "room";
case IShare::TYPE_USER:
return null;
default:
return "Unknown (" . $share->getShareType() . ")";
}
}
}
50 changes: 10 additions & 40 deletions core/Command/Info/FileUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\Files\Mount\IMountPoint;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Share\IShare;
use OCP\Util;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -123,48 +124,17 @@ public function formatPermissions(string $type, int $permissions): string {
*/
public function formatMountType(IMountPoint $mountPoint): string {
$storage = $mountPoint->getStorage();
if ($storage && $storage->instanceOfStorage(IHomeStorage::class)) {
return "home storage";
} elseif ($mountPoint instanceof SharedMount) {
$share = $mountPoint->getShare();
$shares = $mountPoint->getGroupedShares();
$sharedBy = array_map(function (IShare $share) {
$shareType = $this->formatShareType($share);
if ($shareType) {
return $share->getSharedBy() . " (via " . $shareType . " " . $share->getSharedWith() . ")";
} else {
return $share->getSharedBy();
}
}, $shares);
$description = "shared by " . implode(', ', $sharedBy);
if ($share->getSharedBy() !== $share->getShareOwner()) {
$description .= " owned by " . $share->getShareOwner();
}
return $description;
} elseif ($mountPoint instanceof GroupMountPoint) {
return "groupfolder " . $mountPoint->getFolderId();
} elseif ($mountPoint instanceof ExternalMountPoint) {
return "external storage " . $mountPoint->getStorageConfig()->getId();

if ($mountPoint instanceof ExternalMountPoint) {
$prefix = "external storage " . $mountPoint->getStorageConfig()->getId() . ": ";
} elseif ($mountPoint instanceof CircleMount) {
return "circle";
$prefix = "circle: ";
}
return get_class($mountPoint);
}

public function formatShareType(IShare $share): ?string {
switch ($share->getShareType()) {
case IShare::TYPE_GROUP:
return "group";
case IShare::TYPE_CIRCLE:
return "circle";
case IShare::TYPE_DECK:
return "deck";
case IShare::TYPE_ROOM:
return "room";
case IShare::TYPE_USER:
return null;
default:
return "Unknown (" . $share->getShareType() . ")";
if ($storage->instanceOfStorage(IStorageDebugInfo::class)) {
/** @var IStorageDebugInfo $storage */
return $prefix . $storage->debugInfo();
} else {
return $prefix . get_class($mountPoint);
}
}

Expand Down
7 changes: 6 additions & 1 deletion lib/private/Files/ObjectStore/HomeObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
namespace OC\Files\ObjectStore;

use OC\User\User;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\IUser;

class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage {
class HomeObjectStoreStorage extends ObjectStoreStorage implements \OCP\Files\IHomeStorage, IStorageDebugInfo {
/**
* The home user storage requires a user object to create a unique storage id
* @param array $params
Expand Down Expand Up @@ -65,4 +66,8 @@ public function getOwner($path) {
public function getUser($path = null): IUser {
return $this->user;
}

public function debugInfo(): string {
return "Home storage for {$this->user->getUID()} in {$this->getObjectStore()->getStorageId()} object store";
}
}
7 changes: 6 additions & 1 deletion lib/private/Files/Storage/DAV.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use OCP\Files\FileInfo;
use OCP\Files\ForbiddenException;
use OCP\Files\IMimeTypeDetector;
use OCP\Files\Storage\IStorageDebugInfo;
use OCP\Files\StorageInvalidException;
use OCP\Files\StorageNotAvailableException;
use OCP\Http\Client\IClientService;
Expand All @@ -67,7 +68,7 @@
*
* @package OC\Files\Storage
*/
class DAV extends Common {
class DAV extends Common implements IStorageDebugInfo {
/** @var string */
protected $password;
/** @var string */
Expand Down Expand Up @@ -931,4 +932,8 @@ public function getDirectoryContent($directory): \Traversable {
$this->convertException($e, $directory);
}
}

function debugInfo(): string {
return "webdav share {$this->user}@{$this->host}/{$this->root}";
}
}
4 changes: 4 additions & 0 deletions lib/private/Files/Storage/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ public function getUser(): IUser {
public function getOwner($path) {
return $this->user->getUID();
}

public function debugInfo(): string {
return "Home storage for {$this->user->getUID()} at {$this->getSourcePath('')}";
}
}
Loading

0 comments on commit ebeb85b

Please sign in to comment.