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
2 changes: 2 additions & 0 deletions classes/local/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ public static function get_objectfs_config() {
$config->s3_bucket_acl = 'private';
$config->s3_region = 'us-east-1';
$config->s3_base_url = '';
$config->s3_endpoint_style = 'virtual'; // 'virtual' or 'path'
$config->key_prefix = '';

// Digital ocean file system.
$config->do_key = '';
$config->do_secret = '';
$config->do_space = '';
$config->do_region = 'sfo2';
$config->do_endpoint_style = 'virtual'; // 'virtual' or 'path'

// Azure file system.
$config->azure_accountname = '';
Expand Down
22 changes: 20 additions & 2 deletions classes/local/store/digitalocean/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,19 @@ public function set_client($config) {
return;
}

$this->client = \Aws\S3\S3Client::factory([
$options = [
'credentials' => ['key' => $config->do_key, 'secret' => $config->do_secret],
'region' => $config->do_region,
'endpoint' => 'https://' . $config->do_region . '.digitaloceanspaces.com',
'version' => AWS_API_VERSION,
]);
];

// Set path style endpoint if configured.
if (isset($config->do_endpoint_style) && $config->do_endpoint_style === 'path') {
$options['use_path_style_endpoint'] = true;
}

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

/**
Expand Down Expand Up @@ -140,6 +147,17 @@ public function define_client_section($settings, $config) {
$regionoptions
));

$settings->add(new \admin_setting_configselect(
'tool_objectfs/do_endpoint_style',
new \lang_string('settings:aws:endpoint_style', 'tool_objectfs'),
new \lang_string('settings:aws:endpoint_style_help', 'tool_objectfs'),
'virtual',
[
'virtual' => get_string('settings:aws:endpoint_style_virtual', 'tool_objectfs'),
'path' => get_string('settings:aws:endpoint_style_path', 'tool_objectfs'),
]
));

return $settings;
}
}
15 changes: 15 additions & 0 deletions classes/local/store/s3/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ public function set_client($config) {
// Support base_url config for aws api compatible endpoints.
if ($config->s3_base_url) {
$options['endpoint'] = $config->s3_base_url;
// Set path style endpoint if configured.
if (isset($config->s3_endpoint_style) && $config->s3_endpoint_style === 'path') {
$options['use_path_style_endpoint'] = true;
}
}

$this->client = \Aws\S3\S3Client::factory($options);
Expand Down Expand Up @@ -513,6 +517,17 @@ public function define_client_section($settings, $config) {
''
));

$settings->add(new \admin_setting_configselect(
'tool_objectfs/s3_endpoint_style',
new \lang_string('settings:aws:endpoint_style', 'tool_objectfs'),
new \lang_string('settings:aws:endpoint_style_help', 'tool_objectfs'),
'virtual',
[
'virtual' => get_string('settings:aws:endpoint_style_virtual', 'tool_objectfs'),
'path' => get_string('settings:aws:endpoint_style_path', 'tool_objectfs'),
]
));

$settings->add(new \admin_setting_configtext(
'tool_objectfs/key_prefix',
new \lang_string('settings:aws:key_prefix', 'tool_objectfs'),
Expand Down
4 changes: 4 additions & 0 deletions lang/en/tool_objectfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@
$string['settings'] = 'Settings';
$string['settings:aws:base_url'] = 'Base URL';
$string['settings:aws:base_url_help'] = 'Alternate url for cnames or s3 compatible endpoints. Leave blank for normal S3 use.';
$string['settings:aws:endpoint_style'] = 'S3 endpoint style';
$string['settings:aws:endpoint_style_help'] = 'Select the endpoint style for S3-compatible services. Virtual hosted style includes the bucket name in the domain (e.g., bucket.s3.amazonaws.com). Path style includes the bucket name in the URL path (e.g., s3.amazonaws.com/bucket).';
$string['settings:aws:endpoint_style_virtual'] = 'Virtual hosted (bucket in domain)';
$string['settings:aws:endpoint_style_path'] = 'Path style (bucket in path)';
$string['settings:aws:bucket'] = 'Bucket';
$string['settings:aws:bucket_acl'] = 'Bucket ACL';
$string['settings:aws:bucket_acl_help'] = 'Access permission for files created inside the S3 bucket.';
Expand Down