From 1ff14bd2c6679b7c3c9eb6be8696366035d01301 Mon Sep 17 00:00:00 2001 From: Kent Delante Date: Thu, 20 Nov 2025 14:05:01 +0800 Subject: [PATCH] feat: emit an event when an S3 bucket is created Signed-off-by: Kent Delante --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + .../Files/ObjectStore/S3ConnectionTrait.php | 9 +++ .../ObjectStore/Events/BucketCreatedEvent.php | 75 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 1ef4f8817f94a..cdf4a3e6f0150 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -396,6 +396,7 @@ '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\\IObjectStoreMultiPartUpload' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php', 'OCP\\Files\\ReservedWordException' => $baseDir . '/lib/public/Files/ReservedWordException.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index ebce96ca01827..9ab4980e24510 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -429,6 +429,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\\IObjectStoreMultiPartUpload' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php', 'OCP\\Files\\ReservedWordException' => __DIR__ . '/../../..' . '/lib/public/Files/ReservedWordException.php', diff --git a/lib/private/Files/ObjectStore/S3ConnectionTrait.php b/lib/private/Files/ObjectStore/S3ConnectionTrait.php index 9961388eddf4f..f2a434190d64c 100644 --- a/lib/private/Files/ObjectStore/S3ConnectionTrait.php +++ b/lib/private/Files/ObjectStore/S3ConnectionTrait.php @@ -40,6 +40,8 @@ use Aws\S3\S3Client; use GuzzleHttp\Promise; use GuzzleHttp\Promise\RejectedPromise; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\ObjectStore\Events\BucketCreatedEvent; use OCP\Files\StorageNotAvailableException; use OCP\ICertificateManager; use OCP\Server; @@ -164,6 +166,13 @@ public function getConnection() { 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.', [ diff --git a/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php b/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php new file mode 100644 index 0000000000000..51c291bac69ce --- /dev/null +++ b/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php @@ -0,0 +1,75 @@ +bucket = $bucket; + $this->endpoint = $endpoint; + $this->region = $region; + $this->version = $version; + } + + /** + * @return string + * @since 29.0.16 + */ + public function getBucket(): string { + return $this->bucket; + } + + /** + * @return string + * @since 29.0.16 + */ + public function getEndpoint(): string { + return $this->endpoint; + } + + /** + * @return string + * @since 29.0.16 + */ + public function getRegion(): string { + return $this->region; + } + + /** + * @return string + * @since 29.0.16 + */ + public function getVersion(): string { + return $this->version; + } +}