Skip to content

Commit

Permalink
feat: add new azure sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Oct 31, 2024
1 parent 5cb99d2 commit aab0e7c
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 31 deletions.
66 changes: 40 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,45 @@
# moodle-tool_objectfs

A remote object storage file system for Moodle. Intended to provide a plug-in that can be installed and configured to work with any supported remote object storage solution.
* [Use cases](#use-cases)
* [Offloading large and old files to save money](#offloading-large-and-old-files-to-save-money)
* [Sharing files across moodles to save disk](#sharing-files-across-moodles-to-save-disk)
* [Sharing files across environments to save time](#sharing-files-across-environments-to-save-time)
* [Sharing files with data washed environments](#sharing-files-with-data-washed-environments)
* [Installation](#installation)
* [Compatible object stores](#compatible-object-stores)
* [Amazon S3](#amazon-s3)
* [Minio.io S3](#minio-s3)
* [Google gcs](#google-gcs)
* [Azure Blob Storage](#azure-blob-storage)
* [DigitalOcean Spaces](#digitalocean-spaces)
* [Openstack Object Storage](#openstack-object-storage)
* [Moodle configuration](#moodle-configuration)
* [General Settings](#general-settings)
* [File Transfer settings](#file-transfer-settings)
* [Pre-Signed URLs Settings](#pre-signed-urls-settings)
* [Amazon S3 settings](#amazon-s3-settings)
* [Minio.io S3 settings](#minio-s3-settings)
* [Azure Blob Storage settings](#azure-blob-storage-settings)
* [DigitalOcean Spaces settings](#digitalocean-spaces-settings)
* [Integration testing](#integration-testing)
* [Applying core patches](#applying-core-patches)
* [Crafted by Catalyst IT](#crafted-by-catalyst-it)
* [Contributing and support](#contributing-and-support)
- [moodle-tool\_objectfs](#moodle-tool_objectfs)
- [Use cases](#use-cases)
- [Offloading large and old files to save money](#offloading-large-and-old-files-to-save-money)
- [Sharing files across moodles to save disk](#sharing-files-across-moodles-to-save-disk)
- [Sharing files across environments to save time](#sharing-files-across-environments-to-save-time)
- [Sharing files with data washed environments](#sharing-files-with-data-washed-environments)
- [GDPR](#gdpr)
- [Branches](#branches)
- [Installation](#installation)
- [Compatible object stores](#compatible-object-stores)
- [Amazon S3](#amazon-s3)
- [Minio S3](#minio-s3)
- [Google GCS](#google-gcs)
- [Azure Blob Storage](#azure-blob-storage)
- [DigitalOcean Spaces](#digitalocean-spaces)
- [Openstack Object Storage](#openstack-object-storage)
- [Moodle configuration](#moodle-configuration)
- [General Settings](#general-settings)
- [File Transfer settings](#file-transfer-settings)
- [File System settings](#file-system-settings)
- [Pre-Signed URLs Settings](#pre-signed-urls-settings)
- [Amazon S3 settings](#amazon-s3-settings)
- [Minio S3 settings](#minio-s3-settings)
- [Azure Blob Storage settings](#azure-blob-storage-settings)
- [DigitalOcean Spaces settings](#digitalocean-spaces-settings)
- [Openstack Object Storage settings](#openstack-object-storage-settings)
- [Integration testing](#integration-testing)
- [Applying core patches](#applying-core-patches)
- [Moodle 3.9:](#moodle-39)
- [Moodle 3.8:](#moodle-38)
- [Moodle 3.4 - 3.7:](#moodle-34---37)
- [Moodle 3.3 and Totara 12:](#moodle-33-and-totara-12)
- [Moodle 3.2 and Totara 11:](#moodle-32-and-totara-11)
- [Moodle 2.9 - 3.1 and Totara 2.9, 9 - 10:](#moodle-29---31-and-totara-29-9---10)
- [Moodle 2.7 - 2.8 and Totara 2.7 - 2.8:](#moodle-27---28-and-totara-27---28)
- [PHPUnit test compatibility](#phpunit-test-compatibility)
- [Contributing and support](#contributing-and-support)
- [Warm thanks](#warm-thanks)
- [Crafted by Catalyst IT](#crafted-by-catalyst-it)

## Use cases
There are a number of different ways you can use this plug in. See [Recommended use case settings](#recommended-use-case-settings) for recommended settings for each one.
Expand Down Expand Up @@ -75,7 +89,7 @@ This plugin is GDPR complient if you enable the deletion of remote objects.
3. Clone this repository into admin/tool/objectfs
4. Install one of the required SDK libraries for the storage file system that you will be using
1. Clone [moodle-local_aws](https://github.com/catalyst/moodle-local_aws) into local/aws for S3 or DigitalOcean Spaces or Google Cloud, or
2. Clone [moodle-local_azure_storage](https://github.com/catalyst/moodle-local_azure_storage) into local/azure_storage for Azure Blob Storage, or
2. Clone [moodle-local_azureblobstorage](https://github.com/catalyst/moodle-local_azureblobstorage) into local/azureblobstorage for Azure Blob Storage, or
3. Clone [moodle-local_openstack](https://github.com/matt-catalyst/moodle-local_openstack.git) into local/openstack for openstack(swift) storage
5. Install the plugins through the moodle GUI.
6. Configure the plugin. See [Moodle configuration](#moodle-configuration)
Expand Down
10 changes: 9 additions & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ $CFG->phpunit_objectfs_s3_integration_test_credentials = array(
's3_region' => 'Your region',
);
```
* Azure:
* Azure (deprecated API):
```php
$CFG->phpunit_objectfs_azure_integration_test_credentials = array(
'azure_accountname' => 'Your account name',
'azure_container' => 'Your container',
'azure_sastoken' => 'Your sas token',
);
```
* Azure Blob Storage:
```php
$CFG->phpunit_objectfs_azure_blob_storage_integration_test_credentials = [
'azure_accountname' => 'Your account name',
'azure_container' => 'Your container',
'azure_sastoken' => 'Your sas token',
];
```
* Swift:
```php
$CFG->phpunit_objectfs_swift_integration_test_credentials = array(
Expand Down
33 changes: 33 additions & 0 deletions classes/azure_blob_storage_file_system.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_objectfs;

use tool_objectfs\local\store\azure_blob_storage\file_system;

/**
* File system for Azure Blob Storage.
* This file tells objectfs that this storage system is available for use.
* E.g. via $CFG->alternative_file_system_class
*
* @package tool_objectfs
* @author Matthew Hilton <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class azure_blob_storage_file_system extends file_system {

}
7 changes: 4 additions & 3 deletions classes/local/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,17 +306,18 @@ public static function check_file_storage_filesystem() {
public static function get_available_fs_list() {
$result[''] = get_string('pleaseselect', OBJECTFS_PLUGIN_NAME);

$filesystems['\tool_objectfs\azure_file_system'] = '\tool_objectfs\azure_file_system';
$filesystems['\tool_objectfs\azure_file_system'] = '\tool_objectfs\azure_file_system [DEPRECATED]';
$filesystems['\tool_objectfs\digitalocean_file_system'] = '\tool_objectfs\digitalocean_file_system';
$filesystems['\tool_objectfs\s3_file_system'] = '\tool_objectfs\s3_file_system';
$filesystems['\tool_objectfs\swift_file_system'] = '\tool_objectfs\swift_file_system';
$filesystems['\tool_objectfs\azure_blob_storage_file_system'] = '\tool_objectfs\azure_blob_storage_file_system';

foreach ($filesystems as $filesystem) {
foreach ($filesystems as $filesystem => $name) {
$clientclass = self::get_client_classname_from_fs($filesystem);
$client = new $clientclass(null);

if ($client && $client->get_availability()) {
$result[$filesystem] = $filesystem;
$result[$filesystem] = $name;
}
}
return $result;
Expand Down
3 changes: 2 additions & 1 deletion classes/local/store/azure/stream_wrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use GuzzleHttp\Psr7\Stream;
use GuzzleHttp\Psr7\CachingStream;
use GuzzleHttp\Psr7;
use GuzzleHttp\Psr7\Utils;
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use MicrosoftAzure\Storage\Blob\Models\BlobProperties;
use MicrosoftAzure\Storage\Blob\Models\SetBlobPropertiesOptions;
Expand Down Expand Up @@ -443,7 +444,7 @@ private function openreadstream() {

try {
$blob = $client->getBlob($params['Container'], $params['Key']);
$this->body = Psr7\stream_for($blob->getContentStream());
$this->body = Utils::streamFor($blob->getContentStream());
} catch (ServiceException $e) {
// Prevent the client from keeping the request open when the content cannot be found.
$response = $e->getResponse();
Expand Down
Loading

0 comments on commit aab0e7c

Please sign in to comment.