Skip to content

Commit

Permalink
CTP-3951 Set up AWS SQS connection for SORA
Browse files Browse the repository at this point in the history
  • Loading branch information
aydevworks committed Oct 31, 2024
1 parent bd64fe5 commit 8964e20
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 1 deletion.
90 changes: 90 additions & 0 deletions classes/aws/sqs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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 local_sitsgradepush\aws;

use Aws\Sqs\SqsClient;
use core\aws\client_factory;

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

require_once($CFG->dirroot . '/lib/aws-sdk/src/functions.php');
require_once($CFG->dirroot . '/lib/guzzlehttp/guzzle/src/functions.php');

/**
* Class for SQS client.
*
* @package local_sitsgradepush
* @copyright 2024 onwards University College London {@link https://www.ucl.ac.uk/}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Alex Yeung <[email protected]>
*/
class sqs {

/** @var SqsClient AWS client */
protected SqsClient $client;

/**
* Constructor.
*
* @throws \moodle_exception
*/
public function __construct() {
// Check required configs are set.
$configs = $this->check_required_configs_are_set();

$this->client = client_factory::get_client('\Aws\Sqs\SqsClient', [
'region' => $configs->aws_region,
'version' => 'latest',
'credentials' => [
'key' => $configs->aws_key,
'secret' => $configs->aws_secret,
],
]);
}

/**
* Get the client.
*
* @return SqsClient
*/
public function get_client(): SqsClient {
return $this->client;
}

/**
* Check required configs are set.
*
* @return object
* @throws \moodle_exception
*/
private function check_required_configs_are_set(): \stdClass {
$requiredfields = ['aws_region', 'aws_key', 'aws_secret'];

$configs = [];
foreach ($requiredfields as $field) {
// Get the config value.
$config = get_config('local_sitsgradepush', $field);

// Check if the config is empty.
if (empty($config)) {
throw new \moodle_exception('error:missingrequiredconfigs', 'local_sitsgradepush');
}
$configs[$field] = $config;
}
return (object) $configs;
}
}
11 changes: 11 additions & 0 deletions lang/en/local_sitsgradepush.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
$string['error:mapassessment'] = 'You do not have permission to map assessment.';
$string['error:marks_transfer_failed'] = 'Marks transfer failed.';
$string['error:missingparams'] = 'Missing parameters.';
$string['error:missingrequiredconfigs'] = 'Missing required configs.';
$string['error:mks_scheme_not_supported'] = 'Marking Scheme is not supported for marks transfer';
$string['error:multiplemappingsnotsupported'] = 'Multiple assessment component mappings is not supported by {$a}';
$string['error:no_mab_found'] = 'No assessment component found for this module delivery.';
Expand Down Expand Up @@ -192,6 +193,16 @@
$string['settings:apiclient'] = 'API client';
$string['settings:apiclient:desc'] = 'Choose which API client to use';
$string['settings:apiclientselect'] = 'Select API client';
$string['settings:awskey'] = 'AWS Key';
$string['settings:awskey:desc'] = 'AWS access key id';
$string['settings:awsregion'] = 'AWS Region';
$string['settings:awsregion:desc'] = 'AWS Server Region';
$string['settings:awssecret'] = 'AWS Secret';
$string['settings:awssecret:desc'] = 'AWS secret access key';
$string['settings:awssettings'] = 'AWS';
$string['settings:awssettings:desc'] = 'Settings for AWS';
$string['settings:awssoraqueueurl'] = 'AWS SORA Queue URL';
$string['settings:awssoraqueueurl:desc'] = 'URL for receiving SORA SQS messages';
$string['settings:concurrenttasks'] = 'Number of concurrent tasks allowed';
$string['settings:concurrenttasks:desc'] = 'Number of concurrent ad-hoc tasks allowed';
$string['settings:enable'] = 'Enable Marks Transfer';
Expand Down
34 changes: 34 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,40 @@
get_string('settings:enableextension:desc', 'local_sitsgradepush'),
'0'
));

// Setting for AWS.
$settings->add(new admin_setting_heading('local_sitsgradepush_aws_settings',
get_string('settings:awssettings', 'local_sitsgradepush'),
get_string('settings:awssettings:desc', 'local_sitsgradepush')
));

// AWS region.
$settings->add(new admin_setting_configtext('local_sitsgradepush/aws_region',
get_string('settings:awsregion', 'local_sitsgradepush'),
get_string('settings:awsregion:desc', 'local_sitsgradepush'),
'eu-west-2'
));

// AWS key.
$settings->add(new admin_setting_configtext('local_sitsgradepush/aws_key',
get_string('settings:awskey', 'local_sitsgradepush'),
get_string('settings:awskey:desc', 'local_sitsgradepush'),
'AKIAX3UE2A7B2VLXHL2O'
));

// AWS secret.
$settings->add(new admin_setting_configpasswordunmask('local_sitsgradepush/aws_secret',
get_string('settings:awssecret', 'local_sitsgradepush'),
get_string('settings:awssecret:desc', 'local_sitsgradepush'),
'CHANGEME'
));

// AWS SORA queue URL.
$settings->add(new admin_setting_configtext('local_sitsgradepush/aws_sora_sqs_queue_url',
get_string('settings:awssoraqueueurl', 'local_sitsgradepush'),
get_string('settings:awssoraqueueurl:desc', 'local_sitsgradepush'),
'https://sqs.eu-west-2.amazonaws.com/540370667459/person-sora-dev'
));
}

$subplugins = core_plugin_manager::instance()->get_plugins_of_type('sitsapiclient');
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

$plugin->component = 'local_sitsgradepush';
$plugin->release = '0.1.0';
$plugin->version = 2024101100;
$plugin->version = 2024103000;
$plugin->requires = 2024042200;
$plugin->maturity = MATURITY_ALPHA;
$plugin->dependencies = [
Expand Down

0 comments on commit 8964e20

Please sign in to comment.