Skip to content

Commit e4a515d

Browse files
committed
Add status check for proxied range request test
1 parent 6ab8e38 commit e4a515d

4 files changed

Lines changed: 89 additions & 2 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace tool_objectfs\check;
18+
use core\check\check;
19+
use core\check\result;
20+
21+
/**
22+
* Status check for objectFS proxied range requests.
23+
*
24+
* @package tool_objectfs
25+
* @author Peter Burnett <peterburnett@catalyst-au.net>
26+
* @copyright Catalyst IT
27+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28+
*/
29+
class proxy_range_request extends check {
30+
/**
31+
* Link to ObjectFS settings page.
32+
*
33+
* @return \action_link|null
34+
*/
35+
public function get_action_link(): ?\action_link {
36+
$url = new \moodle_url('/admin/category.php', ['category' => 'tool_objectfs']);
37+
return new \action_link($url, get_string('pluginname', 'tool_objectfs'));
38+
}
39+
40+
/**
41+
* Check for the success of a proxied range request, if the setting is enabled.
42+
*
43+
* @return result
44+
*/
45+
public function get_result(): result {
46+
$config = \tool_objectfs\local\manager::get_objectfs_config();
47+
$client = \tool_objectfs\local\manager::get_client($config);
48+
49+
$signingsupport = false;
50+
if (!empty($config->filesystem)) {
51+
$signingsupport = (new $config->filesystem())->supports_presigned_urls();
52+
}
53+
54+
$testconn = $client->test_connection();
55+
$connstatus = $testconn->success;
56+
57+
if ($connstatus && $signingsupport) {
58+
$range = $client->test_range_request(new $config->filesystem());
59+
60+
if ($range->result) {
61+
return new result(result::OK, get_string('settings:presignedurl:testrangeok', 'tool_objectfs'));
62+
} else {
63+
return new result(result::WARNING, get_string('settings:presignedurl:testrangeerror', 'tool_objectfs'));
64+
}
65+
}
66+
67+
return new result(result::UNKNOWN, get_string('check:proxyrangerequestsdisabled', 'tool_objectfs'));
68+
}
69+
}

lang/en/tool_objectfs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,6 @@
265265
$string['settings:notconfigured'] = 'Missing configuration.';
266266
$string['total_deleted_dirs'] = 'Total number of deleted directories: ';
267267
$string['backportfiletypesclass'] = 'Backport MDL-53240 is missing. Follow up https://github.com/catalyst/moodle-tool_objectfs#applying-core-patches';
268+
269+
$string['check:proxyrangerequestsdisabled'] = 'The proxy range request setting is disabled.';
270+
$string['checkproxy_range_request'] = 'Pre-signed URL range request proxy';

lib.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,18 @@ function tool_objectfs_pluginfile($course, $cm, context $context, $filearea, arr
110110
send_stored_file($file, $lifetime, 0, $forcedownload, $options);
111111
return true;
112112
}
113+
114+
/**
115+
* Get status checks for tool_objectfs.
116+
*
117+
* @return array
118+
*/
119+
function tool_objectfs_status_checks() {
120+
if (get_config('tool_objectfs', 'proxyrangerequests')) {
121+
return [
122+
new tool_objectfs\check\proxy_range_request()
123+
];
124+
}
125+
126+
return [];
127+
}

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

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

28-
$plugin->version = 2021122301; // The current plugin version (Date: YYYYMMDDXX).
29-
$plugin->release = 2021122301; // Same as version.
28+
$plugin->version = 2021122302; // The current plugin version (Date: YYYYMMDDXX).
29+
$plugin->release = 2021122302; // Same as version.
3030
$plugin->requires = 2013111811; // Requires Filesystem API.
3131
$plugin->component = "tool_objectfs";
3232
$plugin->maturity = MATURITY_STABLE;

0 commit comments

Comments
 (0)