Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions classes/local/store/s3/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ public function set_client($config) {
$options['endpoint'] = $config->s3_base_url;
}

if (!empty($config->s3_path_style_endpoint)) {
$options['use_path_style_endpoint'] = (bool) $config->s3_path_style_endpoint;
}

$this->client = \Aws\S3\S3Client::factory($options);
}

Expand Down Expand Up @@ -330,6 +334,9 @@ public function test_connection() {
} catch (\Aws\Exception\CredentialsException $e) {
$connection->success = false;
$connection->details = $this->get_exception_details($e);
} catch (\Aws\Auth\Exception\UnresolvedAuthSchemeException $e) {
$connection->success = false;
$connection->details = $this->get_exception_details($e);
}

return $connection;
Expand Down Expand Up @@ -513,6 +520,13 @@ public function define_client_section($settings, $config) {
''
));

$settings->add(new \admin_setting_configcheckbox(
'tool_objectfs/s3_path_style_endpoint',
new \lang_string('settings:aws:path_style_endpoint', 'tool_objectfs'),
new \lang_string('settings:aws:path_style_endpoint_help', 'tool_objectfs'),
0
));

$settings->add(new \admin_setting_configtext(
'tool_objectfs/key_prefix',
new \lang_string('settings:aws:key_prefix', 'tool_objectfs'),
Expand Down Expand Up @@ -804,6 +818,14 @@ public function define_client_check_sdk($config) {
global $OUTPUT;
$output = '';
if (empty($config->s3_usesdkcreds)) {
// If AWS_ACCESS_KEY_ID is missing from the environment, we assume
// no SDK credentials are available. This prevents the AWS SDK from
// falling back to the Instance Metadata Service
// which causes a 5+ second connection timeout on non-AWS environments.
if (!getenv('AWS_ACCESS_KEY_ID')) {
return '';
}

$config->s3_usesdkcreds = 1;
$this->set_client($config);
$connection = $this->test_connection();
Expand Down
2 changes: 2 additions & 0 deletions lang/en/tool_objectfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
$string['settings:aws:key_help'] = 'Amazon S3 key credential.';
$string['settings:aws:key_prefix'] = 'Prefix to use in bucket';
$string['settings:aws:key_prefix_help'] = 'Prefix to use inside Amazon S3 bucket. Must end with trailing slash when set. Leave blank to use root of bucket.';
$string['settings:aws:path_style_endpoint'] = 'Path style endpoint';
$string['settings:aws:path_style_endpoint_help'] = 'Use path style endpoints for S3 client.';
$string['settings:aws:region'] = 'region';
$string['settings:aws:region_help'] = 'Amazon S3 API gateway region.';
$string['settings:aws:sdkcredserror'] = 'Couldn\'t find AWS credentials. It\'s unsafe to enable this setting. Follow up <a href="https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html">AWS documentation</a>.';
Expand Down