Skip to content

Commit

Permalink
Issue catalyst#38: 3. Return bool only from are_requirements_met func…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
hdagheda committed Oct 5, 2020
1 parent d4daab4 commit b971dfb
Showing 1 changed file with 44 additions and 25 deletions.
69 changes: 44 additions & 25 deletions classes/converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,10 @@ private function delete_converted_file($objectkey) {

/**
* Whether the plugin is configured and requirements are met.
* @param string $rettype BASIC|SDK|CONNECTION.
* @param string $rettype BASIC|SDK
* @return bool
*/
public static function are_requirements_met($rettype = 'BASIC') {
global $OUTPUT;
if ($rettype == 'SDK') {
$config = array('usesdkcreds' => true);
$converter = new \fileconverter_librelambda\converter($config);
Expand All @@ -310,10 +309,8 @@ public static function are_requirements_met($rettype = 'BASIC') {
if ($rettype == 'BASIC') {
debugging('fileconverter_librelambda configuration not set');
return false;
} else if ($rettype == 'SDK') {
} else {
return false;
} else if ($rettype == 'CONNECTION') {
return $OUTPUT->notification('fileconverter_librelambda configuration not set', 'notifyproblem');
}
}

Expand All @@ -325,11 +322,8 @@ public static function are_requirements_met($rettype = 'BASIC') {
if ($rettype == 'BASIC') {
debugging('fileconverter_librelambda cannot connect to input bucket');
return false;
} else if ($rettype == 'SDK') {
} else {
return false;
} else if ($rettype == 'CONNECTION') {
$output = get_string('settings:aws:input_bucket', 'fileconverter_librelambda') .': '. $connection->message;
return $OUTPUT->notification($output, 'notifyproblem');
}
}

Expand All @@ -339,11 +333,8 @@ public static function are_requirements_met($rettype = 'BASIC') {
if ($rettype == 'BASIC') {
debugging('fileconverter_librelambda cannot connect to output bucket');
return false;
} else if ($rettype == 'SDK') {
} else {
return false;
} else if ($rettype == 'CONNECTION') {
$output = get_string('settings:aws:output_bucket', 'fileconverter_librelambda') .': '.$connection->message;
return $OUTPUT->notification($output, 'notifyproblem');
}
}

Expand All @@ -354,11 +345,8 @@ public static function are_requirements_met($rettype = 'BASIC') {
if ($rettype == 'BASIC') {
debugging('fileconverter_librelambda permissions failure on input bucket');
return false;
} else if ($rettype == 'SDK') {
} else {
return false;
} else if ($rettype == 'CONNECTION') {
$output = get_string('settings:aws:input_bucket', 'fileconverter_librelambda') .': '. $connection->message;
return $OUTPUT->notification($output, 'notifyproblem');
}
}

Expand All @@ -369,16 +357,10 @@ public static function are_requirements_met($rettype = 'BASIC') {
if ($rettype == 'BASIC') {
debugging('fileconverter_librelambda permissions failure on output bucket');
return false;
} else if ($rettype == 'SDK') {
} else {
return false;
} else if ($rettype == 'CONNECTION') {
$output = get_string('settings:aws:output_bucket', 'fileconverter_librelambda') .': '.$connection->message;
return $OUTPUT->notification($output, 'notifyproblem');
}
}
if ($rettype == 'CONNECTION') {
return $OUTPUT->notification(get_string('settings:connectionsuccess', 'fileconverter_librelambda'), 'notifysuccess');
}
return true;
}

Expand Down Expand Up @@ -577,7 +559,44 @@ public function define_client_check_sdk() {
* @throws /coding_exception
*/
public function define_client_check() {
global $OUTPUT;
$converter = new \fileconverter_librelambda\converter();
return $converter::are_requirements_met('CONNECTION');
if (!self::is_config_set($converter)) {
return $OUTPUT->notification('fileconverter_librelambda configuration not set', 'notifyproblem');
}

$converter->create_client();

// Check that we can access the input S3 Bucket.
$connection = self::is_bucket_accessible($converter, $converter->config->s3_input_bucket);
if (!$connection->success) {
$output = get_string('settings:aws:input_bucket', 'fileconverter_librelambda') .': '. $connection->message;
return $OUTPUT->notification($output, 'notifyproblem');
}

// Check that we can access the output S3 Bucket.
$connection = self::is_bucket_accessible($converter, $converter->config->s3_output_bucket);
if (!$connection->success) {
$output = get_string('settings:aws:output_bucket', 'fileconverter_librelambda') .': '.$connection->message;
return $OUTPUT->notification($output, 'notifyproblem');
}

// Check input bucket permissions.
$bucket = $converter->config->s3_input_bucket;
$permissions = self::have_bucket_permissions($converter, $bucket);
if (!$permissions->success) {
$output = get_string('settings:aws:input_bucket', 'fileconverter_librelambda') .': '. $connection->message;
return $OUTPUT->notification($output, 'notifyproblem');
}

// Check output bucket permissions.
$bucket = $converter->config->s3_output_bucket;
$permissions = self::have_bucket_permissions($converter, $bucket);
if (!$permissions->success) {
$output = get_string('settings:aws:output_bucket', 'fileconverter_librelambda') .': '.$connection->message;
return $OUTPUT->notification($output, 'notifyproblem');
}

return $OUTPUT->notification(get_string('settings:connectionsuccess', 'fileconverter_librelambda'), 'notifysuccess');
}
}

0 comments on commit b971dfb

Please sign in to comment.