-
Notifications
You must be signed in to change notification settings - Fork 72
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
base: MOODLE_310_STABLE
Are you sure you want to change the base?
WIP check api #592
Conversation
@@ -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 ??? |
There was a problem hiding this comment.
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/s3/client.php
Outdated
$summarystr = $status == result::OK ? 'check:passed' : 'check:failed'; | ||
$summary = get_string($summarystr, 'tool_objectfs'); | ||
return new result($status, $summary, $details); |
There was a problem hiding this comment.
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
classes/local/store/s3/client.php
Outdated
$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; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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
classes/local/store/swift/client.php
Outdated
} | ||
} | ||
|
||
return $connection; | ||
return new result(result::OK, get_string('check:success', 'tool_objectfs')); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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')) { |
There was a problem hiding this comment.
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
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/checktest_permissions
test_connection
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
test_*
functions - return check results.test_*
methods to try to avoid any regressions with the function signature change.get_client_checks
and make them all use the check API