From 96672e1c4dafc740a375ece7d35f95234e2344bf 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 | 44 +++++++++++++++++++ 4 files changed, 55 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 4b903289049a0..0269912e86427 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -490,6 +490,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\\IObjectStoreMetaData' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStoreMetaData.php', 'OCP\\Files\\ObjectStore\\IObjectStoreMultiPartUpload' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 855d7b05a7f07..9a6bd60c29305 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.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', diff --git a/lib/private/Files/ObjectStore/S3ConnectionTrait.php b/lib/private/Files/ObjectStore/S3ConnectionTrait.php index e32fe64f278e6..b879489f34ecc 100644 --- a/lib/private/Files/ObjectStore/S3ConnectionTrait.php +++ b/lib/private/Files/ObjectStore/S3ConnectionTrait.php @@ -14,6 +14,8 @@ 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\ICache; use OCP\ICacheFactory; @@ -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..bd6afcd82094a --- /dev/null +++ b/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php @@ -0,0 +1,44 @@ +bucket; + } + + public function getEndpoint(): string { + return $this->endpoint; + } + + public function getRegion(): string { + return $this->region; + } + + public function getVersion(): string { + return $this->version; + } +}