Skip to content

Commit

Permalink
MDL-80736 libraries: Move AWS helper code from factor_sms to core\aws
Browse files Browse the repository at this point in the history
  • Loading branch information
marxjohnson committed Jan 29, 2024
1 parent f30110b commit 2f351c5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

namespace factor_sms\local\smsgateway;

use factor_sms\admin_settings_aws_region;
use core\aws\admin_settings_aws_region;
use core\aws\aws_helper;
use factor_sms\event\sms_sent;
use factor_sms\local\aws_helper;

/**
* AWS SNS SMS Gateway class
Expand Down Expand Up @@ -122,9 +122,6 @@ public function send_sms_message(string $messagecontent, string $phonenumber): b
* @return void
*/
public static function add_settings(\admin_settingpage $settings): void {
global $CFG;

require_once($CFG->dirroot . '/admin/tool/mfa/factor/sms/classes/admin_settings_aws_region.php');
$settings->add(new \admin_setting_configcheckbox('factor_sms/usecredchain',
get_string('settings:aws:usecredchain', 'factor_sms'), '', 0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/**
* Admin setting for AWS regions.
*
* @package factor_sms
* @package core
* @author Dmitrii Metelkin <[email protected]>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace factor_sms;
namespace core\aws;

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

Expand All @@ -32,7 +32,7 @@
/**
* Admin setting for a list of AWS regions.
*
* @package factor_sms
* @package core
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
Expand All @@ -50,7 +50,9 @@ public function output_html($data, $query='') {

$default = $this->get_defaultsetting();
$options = [];
$all = require_once($CFG->dirroot . '/lib/aws-sdk/src/data/endpoints.json.php');
// We do require() not require_once() here, as the file returns a value and we may need to get
// this value more than once.
$all = require($CFG->dirroot . '/lib/aws-sdk/src/data/endpoints.json.php');
$ends = $all['partitions'][0]['regions'];
if ($ends) {
foreach ($ends as $key => $value) {
Expand All @@ -69,7 +71,7 @@ public function output_html($data, $query='') {
'size' => $this->size,
'options' => $options,
];
$element = $OUTPUT->render_from_template('factor_sms/setting_aws_region', $context);
$element = $OUTPUT->render_from_template('core/aws/setting_aws_region', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/**
* AWS helper class. Contains useful functions when interacting with the SDK.
*
* @package factor_sms
* @package core
* @author Peter Burnett <[email protected]>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace factor_sms\local;
namespace core\aws;

use Aws\CommandInterface;
use Aws\AwsClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
/**
* AWS Client factory. Retrieves a client with moodle specific HTTP configuration.
*
* @package factor_sms
* @package core
* @author Peter Burnett <[email protected]>
* @copyright 2022 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace factor_sms\local;
namespace core\aws;
use Aws\AwsClient;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template factor_sms/setting_aws_region
@template core/aws/setting_aws_region
Admin aws region setting template.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
/**
* factor_sms unit tests.
*
* @package factor_sms
* @package core
* @author Mikhail Golenkov <[email protected]>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace factor_sms;
namespace core\aws;

/**
* Testcase for the list of AWS regions admin setting.
*
* @package factor_sms
* @package core
* @author Mikhail Golenkov <[email protected]>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \admin_settings_aws_region_test
* @covers \core\aws\admin_settings_aws_region
*/
class admin_settings_aws_region_test extends \advanced_testcase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* factor_sms unit tests.
* aws_helper unit tests.
*
* @package factor_sms
* @package core
* @author Peter Burnett <[email protected]>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \factor_sms\local\aws_helper
* @covers \core\aws\aws_helper
*/

namespace factor_sms;

use factor_sms\local\aws_helper;
namespace core\aws;

/**
* Testcase for the AWS helper.
Expand All @@ -35,7 +33,7 @@
* @author Peter Burnett <[email protected]>
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @covers \factor_sms\classes\local\aws_helper
* @covers \core\aws\aws_helper
*/
class aws_helper_test extends \advanced_testcase {

Expand Down

0 comments on commit 2f351c5

Please sign in to comment.