Skip to content

Commit

Permalink
Remove local_aws dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Nov 20, 2024
1 parent 713d9fa commit 0b98be5
Showing 6 changed files with 111 additions and 34 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -77,6 +77,7 @@ This plugin is GDPR complient if you enable the deletion of remote objects.

| Moodle version | Totara version | Branch | PHP | MySQL | PostgreSQL |
|-------------------|--------------------------|----------------------------------------------------------------------------------------------|------|---------|-------------|
| Moodle 4.4+ | | [MOODLE_404_STABLE](https://github.com/catalyst/moodle-tool_objectfs/tree/MOODLE_402_STABLE) | 8.1+ | 8.0+ | 13+ |
| Moodle 4.2+ | | [MOODLE_402_STABLE](https://github.com/catalyst/moodle-tool_objectfs/tree/MOODLE_402_STABLE) | 8.0+ | 8.0+ | 13+ |
| Moodle 3.10 - 4.1 | | [MOODLE_310_STABLE](https://github.com/catalyst/moodle-tool_objectfs/tree/MOODLE_310_STABLE) | 7.2+ | 5.7+ | 12+ |
| Moodle 3.3 - 3.9 | Totara 12 | [MOODLE_33_STABLE](https://github.com/catalyst/moodle-tool_objectfs/tree/MOODLE_33_STABLE) | 7.1+ | 5.6+ | 9.5+ |
@@ -88,7 +89,7 @@ This plugin is GDPR complient if you enable the deletion of remote objects.
2. Setup your remote object storage. See [Remote object storage setup](#amazon-s3)
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
1. AWS SDK: the SDK is already integrated into Moodle 4.4+
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.
14 changes: 9 additions & 5 deletions classes/local/store/digitalocean/client.php
Original file line number Diff line number Diff line change
@@ -31,25 +31,29 @@
* client
*/
class client extends s3_client {

/**
* construct
* @param \stdClass $config
* @return void
*/
public function __construct($config) {
global $CFG;
$this->autoloader = $CFG->dirroot . '/local/aws/sdk/aws-autoloader.php';

if ($this->get_availability() && !empty($config)) {
require_once($this->autoloader);
$this->bucket = $config->do_space;
$this->set_client($config);
} else {
parent::__construct($config);
}
}

/**
* We do not need to check for the autoloader as AWS SDK is integrated in to Moodle 4.4
*
* @return bool
*/
public function get_availability() {
return true;
}

/**
* Check if the client configured properly.
*
87 changes: 87 additions & 0 deletions classes/local/store/s3/admin_settings_aws_region.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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/>.

/**
* Admin setting for AWS regions.
*
* @package tool_cloudmetrics
* @author Dmitrii Metelkin <dmitriim@catalyst-au.net>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_objectfs\local\store\s3;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/lib/adminlib.php');

/**
* Admin setting for a list of AWS regions.
*
* @package tool_cloudmetrics
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class admin_settings_aws_region extends \admin_setting_configtext {

/**
* Return part of form with setting.
*
* @param mixed $data array or string depending on setting
* @param string $query
* @return string
*/
public function output_html($data, $query='') {
global $CFG;

$default = $this->get_defaultsetting();

$options = [];

$all = require($CFG->dirroot . '/lib/aws-sdk/src/data/endpoints.json.php');
$ends = $all['partitions'][0]['regions'];
if ($ends) {
foreach ($ends as $key => $value) {
$options[] = [
'value' => $key,
'label' => $key . ' - ' . $value['description'],
];
}
}

$inputparams = array(
'type' => 'text',
'list' => $this->get_full_name(),
'name' => $this->get_full_name(),
'value' => $data,
'size' => $this->size,
'id' => $this->get_id(),
'class' => 'form-control text-ltr',
);

$element = \html_writer::start_tag('div', array('class' => 'form-text defaultsnext'));
$element .= \html_writer::empty_tag('input', $inputparams);
$element .= \html_writer::start_tag('datalist', array('id' => $this->get_full_name()));
foreach ($options as $option) {
$element .= \html_writer::tag('option', $option['label'], array('value' => $option['value']));
}
$element .= \html_writer::end_tag('datalist');
$element .= \html_writer::end_tag('div');

return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query);
}
}
31 changes: 9 additions & 22 deletions classes/local/store/s3/client.php
Original file line number Diff line number Diff line change
@@ -28,7 +28,6 @@
use tool_objectfs\local\manager;
use tool_objectfs\local\store\object_client_base;
use tool_objectfs\local\store\signed_url;
use local_aws\admin_settings_aws_region;

define('AWS_API_VERSION', '2006-03-01');
define('AWS_CAN_READ_OBJECT', 0);
@@ -69,11 +68,9 @@ class client extends object_client_base {
*/
public function __construct($config) {
global $CFG;
$this->autoloader = $CFG->dirroot . '/local/aws/sdk/aws-autoloader.php';
$this->config = $config;

if ($this->get_availability() && !empty($config)) {
require_once($this->autoloader);
// Using the multipart upload methods , you can upload objects from 5 MB to 5 TB in size.
// See https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-multipart-upload.html.
$this->maxupload = OBJECTFS_BYTES_IN_TERABYTE * 5;
@@ -89,6 +86,15 @@ public function __construct($config) {
}
}

/**
* We do not need to check for the autoloader as AWS SDK is integrated in to Moodle 4.4
*
* @return bool
*/
public function get_availability() {
return true;
}

/**
* sleep
* @return array
@@ -432,25 +438,6 @@ protected function get_exception_details($exception) {
*/
public function define_client_section($settings, $config) {
global $OUTPUT;
$plugins = \core_component::get_plugin_list('local');

if (!array_key_exists('aws', $plugins)) {
$text = $OUTPUT->notification(new \lang_string('settings:aws:installneeded', OBJECTFS_PLUGIN_NAME));
$settings->add(new \admin_setting_heading('tool_objectfs/aws',
new \lang_string('settings:aws:header', 'tool_objectfs'), $text));
return $settings;
}

$plugin = (object)['version' => null];
if (file_exists($plugins['aws'].'/version.php')) {
include($plugins['aws'].'/version.php');
}
if (empty($plugin->version) || $plugin->version < 2020051200) {
$text = $OUTPUT->notification(new \lang_string('settings:aws:upgradeneeded', OBJECTFS_PLUGIN_NAME));
$settings->add(new \admin_setting_heading('tool_objectfs/aws',
new \lang_string('settings:aws:header', 'tool_objectfs'), $text));
return $settings;
}

$settings->add(new \admin_setting_heading('tool_objectfs/aws',
new \lang_string('settings:aws:header', 'tool_objectfs'), $this->define_client_check()));
2 changes: 0 additions & 2 deletions lang/en/tool_objectfs.php
Original file line number Diff line number Diff line change
@@ -120,8 +120,6 @@
$string['settings:aws:region_help'] = 'Amazon S3 API gateway region.';
$string['settings:aws:base_url'] = 'Base URL';
$string['settings:aws:base_url_help'] = 'Alternate url for cnames or s3 compatible endpoints. Leave blank for normal S3 use.';
$string['settings:aws:upgradeneeded'] = 'Please upgrade \'local_aws\' plugin to the latest supported version.';
$string['settings:aws:installneeded'] = 'Please install \'local_aws\' plugin.';
$string['settings:aws:usesdkcreds'] = 'Use the default credential provider chain to find AWS credentials';
$string['settings:aws:sdkcredsok'] = 'AWS credentials found. This setting can be safely enabled.';
$string['settings:aws:sdkcredserror'] = 'Couldn\'t find AWS credentials. It\'s unsafe to enable this setting. Follow up <a href="https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html">AWS documentation</a>.';
8 changes: 4 additions & 4 deletions version.php
Original file line number Diff line number Diff line change
@@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2024110800; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2024110800; // Same as version.
$plugin->requires = 2023042400; // Requires 4.2.
$plugin->version = 2024112000; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2024112000; // Same as version.
$plugin->requires = 2024042200; // Requires 4.4.
$plugin->component = "tool_objectfs";
$plugin->maturity = MATURITY_STABLE;
$plugin->supported = [402, 405];
$plugin->supported = [404, 405];

0 comments on commit 0b98be5

Please sign in to comment.