Skip to content

Commit

Permalink
Merge pull request #45059 from nextcloud/backport/44496/stable28
Browse files Browse the repository at this point in the history
[stable28] feat: support "s3-accelerate" endpoint
  • Loading branch information
joshtrichards committed Jun 3, 2024
2 parents 8c3376d + 2f0b200 commit 5ebd562
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/private/Files/ObjectStore/S3ConnectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,17 @@ protected function parseParams($params) {
$this->copySizeLimit = $params['copySizeLimit'] ?? 5242880000;
$this->useMultipartCopy = (bool)($params['useMultipartCopy'] ?? true);
$params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
$params['s3-accelerate'] = $params['hostname'] == 's3-accelerate.amazonaws.com' || $params['hostname'] == 's3-accelerate.dualstack.amazonaws.com';
$params['hostname'] = empty($params['hostname']) ? 's3.' . $params['region'] . '.amazonaws.com' : $params['hostname'];
if (!isset($params['port']) || $params['port'] === '') {
$params['port'] = (isset($params['use_ssl']) && $params['use_ssl'] === false) ? 80 : 443;
}
$params['verify_bucket_exists'] = $params['verify_bucket_exists'] ?? true;

if ($params['s3-accelerate']) {
$params['verify_bucket_exists'] = false;
}

$this->params = $params;
}

Expand Down Expand Up @@ -146,6 +152,13 @@ public function getConnection() {
'http' => ['verify' => $this->getCertificateBundlePath()],
'use_aws_shared_config_files' => false,
];

if ($this->params['s3-accelerate']) {
$options['use_accelerate_endpoint'] = true;
} else {
$options['endpoint'] = $base_url;
}

if ($this->getProxy()) {
$options['http']['proxy'] = $this->getProxy();
}
Expand Down Expand Up @@ -174,7 +187,9 @@ public function getConnection() {
'exception' => $e,
'app' => 'objectstore',
]);
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
if ($e->getAwsErrorCode() !== "BucketAlreadyOwnedByYou") {
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());
}
}
}

Expand Down

0 comments on commit 5ebd562

Please sign in to comment.