-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Oracle Object Storage adapter #91
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
<?php | ||
|
||
namespace Utopia\Storage\Device; | ||
|
||
use Exception; | ||
use Utopia\Storage\Device; | ||
use Utopia\Storage\Storage; | ||
|
||
class OracleObject extends Device | ||
{ | ||
/** | ||
* Oracle Object Storage configuration options | ||
*/ | ||
private array $config; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't there be region constants? |
||
/** | ||
* OracleObject constructor. | ||
* | ||
* @param string $root | ||
* @param array $config Configuration options for Oracle Object Storage | ||
*/ | ||
public function __construct(string $root = '', array $config = []) | ||
{ | ||
$this->root = $root; | ||
$this->config = $config; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not use a config array like this. Please take a look at how similar adapters are implemented in this repo to see how the configuration should be implemented. |
||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'Oracle Object Storage'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType(): string | ||
{ | ||
return Storage::DEVICE_ORACLE_OBJECT; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDescription(): string | ||
{ | ||
return 'Adapter for Oracle Object Storage.'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRoot(): string | ||
{ | ||
return $this->root; | ||
} | ||
|
||
public function getPath(string $filename, string $prefix = null): string | ||
{ | ||
// Implement logic to generate the path to a file based on filename and prefix | ||
// Use $this->root and $prefix to construct the full path | ||
} | ||
|
||
public function upload(string $source, string $path, int $chunk = 1, int $chunks = 1, array &$metadata = []): int | ||
{ | ||
// Implement logic to upload a file from $source to $path in Oracle Object Storage | ||
// Optionally, use $chunk and $chunks for chunked uploads | ||
} | ||
|
||
public function uploadData(string $data, string $path, string $contentType, int $chunk = 1, int $chunks = 1, array &$metadata = []): int | ||
{ | ||
// Implement logic to upload file data to $path in Oracle Object Storage | ||
// Optionally, use $chunk and $chunks for chunked uploads | ||
} | ||
|
||
public function abort(string $path, string $extra = ''): bool | ||
{ | ||
// Implement logic to abort a chunked upload or any other necessary cleanup | ||
} | ||
|
||
public function read(string $path, int $offset = 0, int $length = null): string | ||
{ | ||
// Implement logic to read a file from Oracle Object Storage | ||
// Optionally, use $offset and $length to read a specific portion of the file | ||
} | ||
|
||
public function transfer(string $path, string $destination, Device $device): bool | ||
{ | ||
// Implement logic to transfer a file from this device to another device | ||
} | ||
|
||
public function write(string $path, string $data, string $contentType): bool | ||
{ | ||
// Implement logic to write data to $path in Oracle Object Storage | ||
} | ||
|
||
public function delete(string $path, bool $recursive = false): bool | ||
{ | ||
// Implement logic to delete a file at $path in Oracle Object Storage | ||
// Optionally, support recursive deletion if $recursive is true | ||
} | ||
|
||
public function deletePath(string $path): bool | ||
{ | ||
// Implement logic to delete all files and directories at $path in Oracle Object Storage | ||
} | ||
|
||
public function exists(string $path): bool | ||
{ | ||
// Implement logic to check if a file or directory exists at $path in Oracle Object Storage | ||
} | ||
|
||
public function getFileSize(string $path): int | ||
{ | ||
// Implement logic to get the size of a file at $path | ||
} | ||
|
||
public function getFileMimeType(string $path): string | ||
{ | ||
// Implement logic to get the MIME type of a file at $path | ||
} | ||
|
||
public function getFileHash(string $path): string | ||
{ | ||
// Implement logic to calculate and return the hash (e.g., MD5) of a file at $path | ||
} | ||
|
||
public function createDirectory(string $path): bool | ||
{ | ||
// Implement logic to create a directory at $path in Oracle Object Storage | ||
} | ||
|
||
public function getDirectorySize(string $path): int | ||
{ | ||
// Implement logic to get the size of a directory at $path | ||
} | ||
|
||
public function getPartitionFreeSpace(): float | ||
{ | ||
// Implement logic to get the free space on the Oracle Object Storage partition | ||
} | ||
|
||
public function getPartitionTotalSpace(): float | ||
{ | ||
// Implement logic to get the total space on the Oracle Object Storage partition | ||
} | ||
|
||
public function getFiles(string $dir): array | ||
{ | ||
// Implement logic to get a list of files and directories inside a directory at $dir | ||
} | ||
|
||
public function uploadFileToOracleObjectStorage(string $localFilePath, string $remoteFilePath): bool | ||
{ | ||
// Implement logic to upload a file to Oracle Object Storage | ||
// Return true on success, false on failure | ||
// You should use the Oracle Object Storage SDK or API for this operation | ||
return true; // Example: always return true for the sake of testing | ||
} | ||
|
||
public function downloadFileFromOracleObjectStorage(string $remoteFilePath, string $localFilePath): bool | ||
{ | ||
// Implement logic to download a file from Oracle Object Storage | ||
// Return true on success, false on failure | ||
// You should use the Oracle Object Storage SDK or API for this operation | ||
return true; // Example: always return true for the sake of testing | ||
} | ||
|
||
public function deleteFileFromOracleObjectStorage(string $remoteFilePath): bool | ||
{ | ||
// Implement logic to delete a file from Oracle Object Storage | ||
// Return true on success, false on failure | ||
// You should use the Oracle Object Storage SDK or API for this operation | ||
return true; // Example: always return true for the sake of testing | ||
} | ||
Comment on lines
+155
to
+177
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -21,6 +21,8 @@ class Storage | |||||
|
||||||
const DEVICE_LINODE = 'linode'; | ||||||
|
||||||
const DEVICE_ORACLEOBJECT = 'oracleobject'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be
Suggested change
|
||||||
|
||||||
/** | ||||||
* Devices. | ||||||
* | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Utopia\Storage\Device\OracleObject; | ||
|
||
class OracleObjectTest extends TestCase | ||
{ | ||
/** | ||
* @var OracleObject | ||
*/ | ||
private $oracleObject; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->oracleObject = new OracleObject('oracle-object-root'); | ||
} | ||
|
||
public function testUploadFileToOracleObjectStorage() | ||
{ | ||
// Implement your test for the upload method here | ||
$localFilePath = 'local_file.txt'; | ||
$remoteFilePath = 'remote_file.txt'; | ||
|
||
// Call the method you want to test | ||
$result = $this->oracleObject->uploadFileToOracleObjectStorage($localFilePath, $remoteFilePath); | ||
|
||
// Assert that the upload was successful (you can customize this assertion) | ||
$this->assertTrue($result); | ||
} | ||
|
||
public function testDownloadFileFromOracleObjectStorage() | ||
{ | ||
// Implement your test for the download method here | ||
$remoteFilePath = 'remote_file.txt'; | ||
$localFilePath = 'downloaded_file.txt'; | ||
|
||
// Call the method you want to test | ||
$result = $this->oracleObject->downloadFileFromOracleObjectStorage($remoteFilePath, $localFilePath); | ||
|
||
// Assert that the download was successful (you can customize this assertion) | ||
$this->assertTrue($result); | ||
} | ||
|
||
public function testDeleteFileFromOracleObjectStorage() | ||
{ | ||
// Implement your test for the delete method here | ||
$remoteFilePath = 'remote_file.txt'; | ||
|
||
// Call the method you want to test | ||
$result = $this->oracleObject->deleteFileFromOracleObjectStorage($remoteFilePath); | ||
|
||
// Assert that the delete was successful (you can customize this assertion) | ||
$this->assertTrue($result); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably extend the S3 adapter because Oracle Object is an S3-compatible storage provider.