Skip to content

Commit

Permalink
MDL-49104 repository_s3: backport of MDL-43725
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Bennett committed Mar 9, 2015
1 parent f4dc567 commit 116f2c5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions repository/s3/lang/en/repository_s3.php 100644 → 100755
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
23 changes: 21 additions & 2 deletions 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 @@ -229,16 +233,31 @@ public function global_search() {
}

public static function get_type_option_names() {
return array('access_key', 'secret_key', 'pluginname');
return array('access_key', 'secret_key', 'endpoint', 'pluginname');
}

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);
$mform->addElement('select', 'endpoint', get_string('endpoint', 'repository_s3'), $endpointselect);
$mform->setDefault('endpoint', '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
3 changes: 3 additions & 0 deletions repository/s3/tests/generator/lib.php 100644 → 100755
Expand Up @@ -47,6 +47,9 @@ protected function prepare_type_record(array $record) {
if (!isset($record['secret_key'])) {
$record['secret_key'] = 'secret_key';
}
if (!isset($record['endpoint'])) {
$record['endpoint'] = 'endpoint';
}
return $record;
}

Expand Down

0 comments on commit 116f2c5

Please sign in to comment.