Skip to content

Commit

Permalink
MDL-43752 repository_s3: added endpoint select box to settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Bennett authored and root committed Feb 2, 2015
1 parent 4c27f52 commit 9b71e3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions repository/s3/lang/en/repository_s3.php
Expand Up @@ -25,6 +25,7 @@

$string['access_key'] = 'Access key';
$string['configplugin'] = 'Amazon S3 settings';
$string['endpoint'] = 'Amazon S3 Endpoint';
$string['needaccesskey'] = 'Access key must be provided';
$string['pluginname'] = 'Amazon S3';
$string['secret_key'] = 'Secret key';
Expand Down
21 changes: 20 additions & 1 deletion repository/s3/lib.php 100644 → 100755
Expand Up @@ -46,7 +46,11 @@ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = a
parent::__construct($repositoryid, $context, $options);
$this->access_key = get_config('s3', 'access_key');
$this->secret_key = get_config('s3', 'secret_key');
$this->s = new S3($this->access_key, $this->secret_key);
$this->endpoint = get_config('s3', 'endpoint');
if ($this->endpoint === false) { // If no endpoint has been set, use the default.
$this->endpoint = 's3.amazonaws.com';
}
$this->s = new S3($this->access_key, $this->secret_key, false, $this->endpoint);
$this->s->setExceptions(true);
}

Expand Down Expand Up @@ -235,10 +239,25 @@ public static function get_type_option_names() {
public static function type_config_form($mform, $classname = 'repository') {
parent::type_config_form($mform);
$strrequired = get_string('required');
$endpointselect = array( // List of possible Amazon S3 Endpoints.
"s3.amazonaws.com" => "s3.amazonaws.com",
"s3-external-1.amazonaws.com" => "s3-external-1.amazonaws.com",
"s3-us-west-2.amazonaws.com" => "s3-us-west-2.amazonaws.com",
"s3-us-west-1.amazonaws.com" => "s3-us-west-1.amazonaws.com",
"s3-eu-west-1.amazonaws.com" => "s3-eu-west-1.amazonaws.com",
"s3.eu-central-1.amazonaws.com" => "s3.eu-central-1.amazonaws.com",
"s3-eu-central-1.amazonaws.com" => "s3-eu-central-1.amazonaws.com",
"s3-ap-southeast-1.amazonaws.com" => "s3-ap-southeast-1.amazonaws.com",
"s3-ap-southeast-2.amazonaws.com" => "s3-ap-southeast-2.amazonaws.com",
"s3-ap-northeast-1.amazonaws.com" => "s3-ap-northeast-1.amazonaws.com",
"s3-sa-east-1.amazonaws.com" => "s3-sa-east-1.amazonaws.com"
);
$mform->addElement('text', 'access_key', get_string('access_key', 'repository_s3'));
$mform->setType('access_key', PARAM_RAW_TRIMMED);
$mform->addElement('text', 'secret_key', get_string('secret_key', 'repository_s3'));
$mform->setType('secret_key', PARAM_RAW_TRIMMED);
$endpointselected = $mform->addElement('select', 'endpoint', get_string('endpoint', 'repository_s3'), $endpointselect);
$endpointselected->setSelected('s3.amazonaws.com'); // Default to US Endpoint.
$mform->addRule('access_key', $strrequired, 'required', null, 'client');
$mform->addRule('secret_key', $strrequired, 'required', null, 'client');
}
Expand Down

0 comments on commit 9b71e3a

Please sign in to comment.