diff --git a/classes/local/manager.php b/classes/local/manager.php index b5268667..c9d2045e 100644 --- a/classes/local/manager.php +++ b/classes/local/manager.php @@ -79,6 +79,7 @@ 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. @@ -86,6 +87,7 @@ public static function get_objectfs_config() { $config->do_secret = ''; $config->do_space = ''; $config->do_region = 'sfo2'; + $config->do_endpoint_style = 'virtual'; // 'virtual' or 'path' // Azure file system. $config->azure_accountname = ''; diff --git a/classes/local/store/digitalocean/client.php b/classes/local/store/digitalocean/client.php index ad5471ce..edf5d72e 100644 --- a/classes/local/store/digitalocean/client.php +++ b/classes/local/store/digitalocean/client.php @@ -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); } /** @@ -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; } } diff --git a/classes/local/store/s3/client.php b/classes/local/store/s3/client.php index 5f4a297f..379b9b6d 100644 --- a/classes/local/store/s3/client.php +++ b/classes/local/store/s3/client.php @@ -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); @@ -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'), diff --git a/lang/en/tool_objectfs.php b/lang/en/tool_objectfs.php index 257350db..42966573 100644 --- a/lang/en/tool_objectfs.php +++ b/lang/en/tool_objectfs.php @@ -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.';