mirror of
https://github.com/nextcloud/server.git
synced 2026-03-04 18:28:08 +01:00
Merge pull request #56617 from nextcloud/backport/56565/stable32
[stable32] feat: emit an event when an S3 bucket is created
This commit is contained in:
@@ -490,6 +490,7 @@ return array(
|
||||
'OCP\\Files\\Notify\\IChange' => $baseDir . '/lib/public/Files/Notify/IChange.php',
|
||||
'OCP\\Files\\Notify\\INotifyHandler' => $baseDir . '/lib/public/Files/Notify/INotifyHandler.php',
|
||||
'OCP\\Files\\Notify\\IRenameChange' => $baseDir . '/lib/public/Files/Notify/IRenameChange.php',
|
||||
'OCP\\Files\\ObjectStore\\Events\\BucketCreatedEvent' => $baseDir . '/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php',
|
||||
'OCP\\Files\\ObjectStore\\IObjectStore' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStore.php',
|
||||
'OCP\\Files\\ObjectStore\\IObjectStoreMetaData' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStoreMetaData.php',
|
||||
'OCP\\Files\\ObjectStore\\IObjectStoreMultiPartUpload' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php',
|
||||
|
||||
@@ -531,6 +531,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
||||
'OCP\\Files\\Notify\\IChange' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/IChange.php',
|
||||
'OCP\\Files\\Notify\\INotifyHandler' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/INotifyHandler.php',
|
||||
'OCP\\Files\\Notify\\IRenameChange' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/IRenameChange.php',
|
||||
'OCP\\Files\\ObjectStore\\Events\\BucketCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php',
|
||||
'OCP\\Files\\ObjectStore\\IObjectStore' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStore.php',
|
||||
'OCP\\Files\\ObjectStore\\IObjectStoreMetaData' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStoreMetaData.php',
|
||||
'OCP\\Files\\ObjectStore\\IObjectStoreMultiPartUpload' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php',
|
||||
|
||||
@@ -14,6 +14,8 @@ use Aws\S3\Exception\S3Exception;
|
||||
use Aws\S3\S3Client;
|
||||
use GuzzleHttp\Promise\Create;
|
||||
use GuzzleHttp\Promise\RejectedPromise;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\ObjectStore\Events\BucketCreatedEvent;
|
||||
use OCP\Files\StorageNotAvailableException;
|
||||
use OCP\ICertificateManager;
|
||||
use OCP\Server;
|
||||
@@ -149,6 +151,13 @@ trait S3ConnectionTrait {
|
||||
throw new StorageNotAvailableException('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket);
|
||||
}
|
||||
$this->connection->createBucket(['Bucket' => $this->bucket]);
|
||||
Server::get(IEventDispatcher::class)
|
||||
->dispatchTyped(new BucketCreatedEvent(
|
||||
$this->bucket,
|
||||
$options['endpoint'],
|
||||
$options['region'],
|
||||
$options['version']
|
||||
));
|
||||
$this->testTimeout();
|
||||
} catch (S3Exception $e) {
|
||||
$logger->debug('Invalid remote storage.', [
|
||||
|
||||
44
lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php
Normal file
44
lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
namespace OCP\Files\ObjectStore\Events;
|
||||
|
||||
use OCP\AppFramework\Attribute\Consumable;
|
||||
use OCP\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* @since 29.0.16
|
||||
*/
|
||||
#[Consumable(since: '29.0.16')]
|
||||
class BucketCreatedEvent extends Event {
|
||||
|
||||
public function __construct(
|
||||
private readonly string $bucket,
|
||||
private readonly string $endpoint,
|
||||
private readonly string $region,
|
||||
private readonly string $version = 'latest',
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getBucket(): string {
|
||||
return $this->bucket;
|
||||
}
|
||||
|
||||
public function getEndpoint(): string {
|
||||
return $this->endpoint;
|
||||
}
|
||||
|
||||
public function getRegion(): string {
|
||||
return $this->region;
|
||||
}
|
||||
|
||||
public function getVersion(): string {
|
||||
return $this->version;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user