Skip to content
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

WIP check api #592

Draft
wants to merge 5 commits into
base: MOODLE_310_STABLE
Choose a base branch
from
Draft

Conversation

matthewhilton
Copy link
Contributor

@matthewhilton matthewhilton commented Jan 12, 2024

A work in progress update to add some basic checks to objectfs - related to #480

Basically the idea is to expose the current methods we have available in object_client via the check api https://moodledev.io/docs/apis/subsystems/check

  1. test_permissions
  2. test_connection
  3. test_range_request

As well as add a new method:
4. test_configuration to detect any config level problems e.g. missing keys, missing config, etc...

1,2,3 are basically the same code, just calling a different method, so these share a check API class. 3. is only enabled if range requests are enabled.

4 is special since it runs only if the $CFG->alternative_file_system is set, whereas 1,2,3 only run if the configuration is OK (i.e. 4 is passing)

Note this only targets MOODLE_310_STABLE since lower versions (< 3.9) do not have the check API.

TODO

  • Improve consistency in return value of test_* functions - return check results.
  • Delete check/proxy_range_request ? Seems redundant now.
  • Check for usages of test_* methods to try to avoid any regressions with the function signature change.
  • Look at replacing get_client_checks and make them all use the check API
  • Check performance - should we run these all the time or only some of the time ?
  • PHPDoc + phpcs + lang strings
  • Unit tests ?

classes/check/store.php Outdated Show resolved Hide resolved
classes/local/store/azure/client.php Show resolved Hide resolved
@@ -89,25 +91,40 @@ public function generate_presigned_url($contenthash, $headers = array()) {
*/
public function define_client_check() {
global $OUTPUT;

// TODO use MDL check api admin setting if available ???
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO use https://tracker.moodle.org/browse/MDL-67898 if available, since it uses Ajax so page loading times are very quick

classes/local/store/object_client_base.php Outdated Show resolved Hide resolved
classes/local/store/object_client_base.php Outdated Show resolved Hide resolved
Comment on lines 302 to 304
$summarystr = $status == result::OK ? 'check:passed' : 'check:failed';
$summary = get_string($summarystr, 'tool_objectfs');
return new result($status, $summary, $details);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per above, just return an OK result here and remove the variables

Comment on lines 325 to 369
$this->client->putObject([
'Bucket' => $this->bucket,
'Key' => $this->bucketkeyprefix . 'permissions_check_file',
'Body' => 'test content'));
'Body' => 'test content',
]);
} catch (\Aws\S3\Exception\S3Exception $e) {
$details = $this->get_exception_details($e);
$permissions->messages[get_string('settings:writefailure', 'tool_objectfs') . $details] = 'notifyproblem';
$permissions->success = false;
$exdetails = $this->get_exception_details($e);
$details .= get_string('settings:writefailure', 'tool_objectfs') . $exdetails;
$status = result::ERROR;
}

// Try to get an object.
try {
$result = $this->client->getObject(array(
$this->client->getObject([
'Bucket' => $this->bucket,
'Key' => $this->bucketkeyprefix . 'permissions_check_file'));
'Key' => $this->bucketkeyprefix . 'permissions_check_file',
]);
} catch (\Aws\S3\Exception\S3Exception $e) {
$errorcode = $e->getAwsErrorCode();
// Write could have failed.
if ($errorcode !== 'NoSuchKey') {
$details = $this->get_exception_details($e);
$permissions->messages[get_string('settings:permissionreadfailure', 'tool_objectfs') . $details] = 'notifyproblem';
$permissions->success = false;
$exdetails = $this->get_exception_details($e);
$details .= get_string('settings:permissionreadfailure', 'tool_objectfs') . $exdetails;
$status = result::ERROR;
}
}

// Try to delete an object.
if ($testdelete) {
try {
$result = $this->client->deleteObject(array('Bucket' => $this->bucket, 'Key' => $this->bucketkeyprefix . 'permissions_check_file'));
$permissions->messages[get_string('settings:deletesuccess', 'tool_objectfs')] = 'warning';
$permissions->success = false;
$this->client->deleteObject([
'Bucket' => $this->bucket,
'Key' => $this->bucketkeyprefix . 'permissions_check_file',
]);
$details .= get_string('settings:deletesuccess', 'tool_objectfs');
} catch (\Aws\S3\Exception\S3Exception $e) {
$errorcode = $e->getAwsErrorCode();
// Something else went wrong.
if ($errorcode !== 'AccessDenied') {
$details = $this->get_exception_details($e);
$permissions->messages[get_string('settings:deleteerror', 'tool_objectfs') . $details] = 'notifyproblem';
$permissions->success = false;
$details .= get_string('settings:deleteerror', 'tool_objectfs') . $details;
$status = result::ERROR;
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally revert this back to previous and just implode the array of messages at the end - a bit simpler and less diff

}
}

return $connection;
return new result(result::OK, get_string('check:success', 'tool_objectfs'));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lang string should be check:passed not check:success

}

public function test_permissions($testdelete) {
public function test_permissions($testdelete): result {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP doc required

new tool_objectfs\check\store(\tool_objectfs\check\store::TYPE_PERMISSIONS),
new tool_objectfs\check\store(\tool_objectfs\check\store::TYPE_CONNECTION),
];

if (get_config('tool_objectfs', 'proxyrangerequests')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check signing support here as well ? That's checked inside the proxy_range_request check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant