-
Notifications
You must be signed in to change notification settings - Fork 78
WIP check api #592
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
Draft
matthewhilton
wants to merge
5
commits into
MOODLE_310_STABLE
Choose a base branch
from
310-stable-add-check-api
base: MOODLE_310_STABLE
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
WIP check api #592
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?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\check; | ||
|
|
||
| use action_link; | ||
| use core\check\check; | ||
| use core\check\result; | ||
| use moodle_url; | ||
| use tool_objectfs\local\manager; | ||
|
|
||
| /** | ||
| * Configuration check. | ||
| * | ||
| * @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 configuration extends check { | ||
| /** | ||
| * Gets the result of the check | ||
| * @return result | ||
| */ | ||
| public function get_result(): result { | ||
| // Load objectfs and run a test. | ||
| $config = manager::get_objectfs_config(); | ||
| $client = manager::get_client($config); | ||
|
|
||
| // Something is very wrong if this is false. | ||
| if (empty($client)) { | ||
| return new result(result::UNKNOWN, get_string('check:configuration:empty', 'tool_objectfs')); | ||
| } | ||
|
|
||
| return $client->test_configuration(); | ||
| } | ||
|
|
||
| /** | ||
| * Return action link | ||
| * @return action_link | ||
| */ | ||
| public function get_action_link(): ?action_link { | ||
| $str = get_string('check:settings', 'tool_objectfs'); | ||
| $url = new moodle_url('/admin/category.php', ['category' => 'tool_objectfs']); | ||
| return new action_link($url, $str); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| <?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\check; | ||
|
|
||
| use action_link; | ||
| use coding_exception; | ||
| use core\check\check; | ||
| use core\check\result; | ||
| use moodle_url; | ||
| use Throwable; | ||
| use tool_objectfs\local\manager; | ||
|
|
||
| /** | ||
| * Store check. | ||
| * | ||
| * @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 store extends check { | ||
| /** @var string The selected type of store check **/ | ||
| private $type; | ||
|
|
||
| /** @var string Connection test type **/ | ||
| public const TYPE_CONNECTION = 'connection'; | ||
|
|
||
| /** @var string Permissions test type **/ | ||
| public const TYPE_PERMISSIONS = 'permissions'; | ||
|
|
||
| /** @var string Range request test type **/ | ||
| public const TYPE_RANGEREQUEST = 'rangerequest'; | ||
|
|
||
| /** @var array Available test types **/ | ||
| public const TYPES = [self::TYPE_CONNECTION, self::TYPE_PERMISSIONS, self::TYPE_RANGEREQUEST]; | ||
|
|
||
| /** | ||
| * Create a store check for a given type | ||
| * @param string $type one of TYPES | ||
| */ | ||
| public function __construct(string $type) { | ||
| if (!in_array($type, self::TYPES)) { | ||
| throw new coding_exception("Given test type " . $type . " is not valid."); | ||
| } | ||
|
|
||
| $this->type = $type; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the id - differs based on the type | ||
| * @return string | ||
| */ | ||
| public function get_id(): string { | ||
| return "store_check_" . $this->type; | ||
| } | ||
|
|
||
| /** | ||
| * Return the result | ||
| * @return result | ||
| */ | ||
| public function get_result(): result { | ||
| try { | ||
| // Check if configured first, and report NA if not configured. | ||
| if (!\tool_objectfs\local\manager::check_file_storage_filesystem()) { | ||
| return new result(result::NA, get_string('check:notenabled', 'tool_objectfs')); | ||
| } | ||
|
|
||
| // Load objectfs and run a test. | ||
| $config = manager::get_objectfs_config(); | ||
| $client = manager::get_client($config); | ||
|
|
||
| // Something is very wrong if this is empty. | ||
| if (empty($client)) { | ||
| return new result(result::UNKNOWN, get_string('check:configuration:empty', 'tool_objectfs')); | ||
| } | ||
|
|
||
| // If not configured yet, don't bother testing connection or permissions. | ||
| if ($client->test_configuration()->get_status() != result::OK) { | ||
| return new result(result::NA, get_string('check:storecheck:notconfiguredskip', 'tool_objectfs')); | ||
| } | ||
|
|
||
| switch($this->type) { | ||
| case self::TYPE_CONNECTION: | ||
| return $client->test_connection(false); | ||
|
|
||
| case self::TYPE_RANGEREQUEST: | ||
| // Range requests require presigned url support. If not supported, return N/A. | ||
| if (!$client->support_presigned_urls()) { | ||
| return new result(result::NA, get_string('check:storecheck:unsupportedrangerequest', 'tool_objectfs')); | ||
| } | ||
|
|
||
| return $client->test_range_request(new $config->filesystem()); | ||
|
|
||
| case self::TYPE_PERMISSIONS: | ||
| return $client->test_permissions(false); | ||
| } | ||
| } catch (Throwable $e) { | ||
| // Usually the SDKs will throw exceptions if something doesn't work, so we want to catch these. | ||
| return new result(result::ERROR, get_string('check:storecheck:error', 'tool_objectfs') | ||
| . $this->type . ': ' . $e->getMessage(), $e->getTraceAsString()); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Return action link | ||
| * @return action_link | ||
| */ | ||
| public function get_action_link(): ?action_link { | ||
| $str = get_string('check:settings', 'tool_objectfs'); | ||
| $url = new moodle_url('/admin/category.php', ['category' => 'tool_objectfs']); | ||
| return new action_link($url, $str); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.