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
106 lines
3.1 KiB
PHP
106 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace DeliciousBrains\WP_Offload_Media\Aws3\Aws\Credentials;
|
|
|
|
use DeliciousBrains\WP_Offload_Media\Aws3\Aws\Identity\AwsCredentialIdentity;
|
|
/**
|
|
* Basic implementation of the AWS Credentials interface that allows callers to
|
|
* pass in the AWS Access Key and AWS Secret Access Key in the constructor.
|
|
*/
|
|
class Credentials extends AwsCredentialIdentity implements CredentialsInterface, \Serializable
|
|
{
|
|
private $key;
|
|
private $secret;
|
|
private $token;
|
|
private $expires;
|
|
private $accountId;
|
|
/**
|
|
* Constructs a new BasicAWSCredentials object, with the specified AWS
|
|
* access key and AWS secret key
|
|
*
|
|
* @param string $key AWS access key ID
|
|
* @param string $secret AWS secret access key
|
|
* @param string $token Security token to use
|
|
* @param int $expires UNIX timestamp for when credentials expire
|
|
*/
|
|
public function __construct($key, $secret, $token = null, $expires = null, $accountId = null)
|
|
{
|
|
$this->key = \trim((string) $key);
|
|
$this->secret = \trim((string) $secret);
|
|
$this->token = $token;
|
|
$this->expires = $expires;
|
|
$this->accountId = $accountId;
|
|
}
|
|
public static function __set_state(array $state)
|
|
{
|
|
return new self($state['key'], $state['secret'], $state['token'], $state['expires'], $state['accountId']);
|
|
}
|
|
public function getAccessKeyId()
|
|
{
|
|
return $this->key;
|
|
}
|
|
public function getSecretKey()
|
|
{
|
|
return $this->secret;
|
|
}
|
|
public function getSecurityToken()
|
|
{
|
|
return $this->token;
|
|
}
|
|
public function getExpiration()
|
|
{
|
|
return $this->expires;
|
|
}
|
|
public function isExpired()
|
|
{
|
|
return $this->expires !== null && \time() >= $this->expires;
|
|
}
|
|
public function getAccountId()
|
|
{
|
|
return $this->accountId;
|
|
}
|
|
public function toArray()
|
|
{
|
|
return ['key' => $this->key, 'secret' => $this->secret, 'token' => $this->token, 'expires' => $this->expires, 'accountId' => $this->accountId];
|
|
}
|
|
public function serialize()
|
|
{
|
|
return \json_encode($this->__serialize());
|
|
}
|
|
public function unserialize($serialized)
|
|
{
|
|
$data = \json_decode($serialized, \true);
|
|
$this->__unserialize($data);
|
|
}
|
|
public function __serialize()
|
|
{
|
|
return $this->toArray();
|
|
}
|
|
public function __unserialize($data)
|
|
{
|
|
$this->key = $data['key'];
|
|
$this->secret = $data['secret'];
|
|
$this->token = $data['token'];
|
|
$this->expires = $data['expires'];
|
|
$this->accountId = $data['accountId'];
|
|
}
|
|
/**
|
|
* Internal-only. Used when IMDS is unreachable
|
|
* or returns expires credentials.
|
|
*
|
|
* @internal
|
|
*/
|
|
public function extendExpiration()
|
|
{
|
|
$extension = \mt_rand(5, 10);
|
|
$this->expires = \time() + $extension * 60;
|
|
$message = <<<EOT
|
|
Attempting credential expiration extension due to a credential service
|
|
availability issue. A refresh of these credentials will be attempted again
|
|
after {$extension} minutes.
|
|
|
|
EOT;
|
|
\trigger_error($message, \E_USER_WARNING);
|
|
}
|
|
}
|