Adds a new 'S3-Compatible Storage' provider that works with any
S3-API-compatible object storage service, including MinIO, Ceph,
Cloudflare R2, Backblaze B2, and others.
Changes:
- New provider class: classes/providers/storage/s3-compatible-provider.php
- Provider key: s3compatible
- Reads user-configured endpoint URL from settings
- Uses path-style URL access (required by most S3-compatible services)
- Supports credentials via AS3CF_S3COMPAT_ACCESS_KEY_ID /
AS3CF_S3COMPAT_SECRET_ACCESS_KEY wp-config.php constants
- Disables AWS-specific features (Block Public Access, Object Ownership)
- New provider SVG icons (s3compatible.svg, -link.svg, -round.svg)
- Registered provider in main plugin class with endpoint setting support
- Updated StorageProviderSubPage to show endpoint URL input for S3-compatible
- Built pro settings bundle with rollup (Svelte 4.2.19)
- Added package.json and updated rollup.config.mjs for pro-only builds
72 lines
3.1 KiB
PHP
72 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws\S3;
|
|
|
|
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Api\Service;
|
|
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Arn\ArnInterface;
|
|
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Arn\S3\OutpostsArnInterface;
|
|
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Endpoint\PartitionEndpointProvider;
|
|
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Exception\InvalidRegionException;
|
|
/**
|
|
* @internal
|
|
*/
|
|
trait EndpointRegionHelperTrait
|
|
{
|
|
/** @var array */
|
|
private $config;
|
|
/** @var PartitionEndpointProvider */
|
|
private $partitionProvider;
|
|
/** @var string */
|
|
private $region;
|
|
/** @var Service */
|
|
private $service;
|
|
private function getPartitionSuffix(ArnInterface $arn, PartitionEndpointProvider $provider)
|
|
{
|
|
$partition = $provider->getPartition($arn->getRegion(), $arn->getService());
|
|
return $partition->getDnsSuffix();
|
|
}
|
|
private function getSigningRegion($region, $service, PartitionEndpointProvider $provider)
|
|
{
|
|
$partition = $provider->getPartition($region, $service);
|
|
$data = $partition->toArray();
|
|
if (isset($data['services'][$service]['endpoints'][$region]['credentialScope']['region'])) {
|
|
return $data['services'][$service]['endpoints'][$region]['credentialScope']['region'];
|
|
}
|
|
return $region;
|
|
}
|
|
private function isMatchingSigningRegion($arnRegion, $clientRegion, $service, PartitionEndpointProvider $provider)
|
|
{
|
|
$arnRegion = \DeliciousBrains\WP_Offload_Media\Aws3\Aws\strip_fips_pseudo_regions(\strtolower($arnRegion));
|
|
$clientRegion = \strtolower($clientRegion);
|
|
if ($arnRegion === $clientRegion) {
|
|
return \true;
|
|
}
|
|
if ($this->getSigningRegion($clientRegion, $service, $provider) === $arnRegion) {
|
|
return \true;
|
|
}
|
|
return \false;
|
|
}
|
|
private function validateFipsConfigurations(ArnInterface $arn)
|
|
{
|
|
$useFipsEndpoint = !empty($this->config['use_fips_endpoint']);
|
|
if ($arn instanceof OutpostsArnInterface) {
|
|
if (empty($this->config['use_arn_region']) || !$this->config['use_arn_region']->isUseArnRegion()) {
|
|
$region = $this->region;
|
|
} else {
|
|
$region = $arn->getRegion();
|
|
}
|
|
if (\DeliciousBrains\WP_Offload_Media\Aws3\Aws\is_fips_pseudo_region($region)) {
|
|
throw new InvalidRegionException('Fips is currently not supported with S3 Outposts access' . ' points. Please provide a non-fips region or do not supply an' . ' access point ARN.');
|
|
}
|
|
}
|
|
}
|
|
private function validateMatchingRegion(ArnInterface $arn)
|
|
{
|
|
if (!$this->isMatchingSigningRegion($arn->getRegion(), $this->region, $this->service->getEndpointPrefix(), $this->partitionProvider)) {
|
|
if (empty($this->config['use_arn_region']) || !$this->config['use_arn_region']->isUseArnRegion()) {
|
|
throw new InvalidRegionException('The region' . " specified in the ARN (" . $arn->getRegion() . ") does not match the client region (" . "{$this->region}).");
|
|
}
|
|
}
|
|
}
|
|
}
|