Skip to content

Commit c172165

Browse files
committed
feat: emit an event when an S3 bucket is created
Signed-off-by: Kent Delante <[email protected]>
1 parent 1374e07 commit c172165

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@
460460
'OCP\\Files\\Notify\\IChange' => $baseDir . '/lib/public/Files/Notify/IChange.php',
461461
'OCP\\Files\\Notify\\INotifyHandler' => $baseDir . '/lib/public/Files/Notify/INotifyHandler.php',
462462
'OCP\\Files\\Notify\\IRenameChange' => $baseDir . '/lib/public/Files/Notify/IRenameChange.php',
463+
'OCP\\Files\\ObjectStore\\Events\\BucketCreatedEvent' => $baseDir . '/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php',
463464
'OCP\\Files\\ObjectStore\\IObjectStore' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStore.php',
464465
'OCP\\Files\\ObjectStore\\IObjectStoreMultiPartUpload' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php',
465466
'OCP\\Files\\ReservedWordException' => $baseDir . '/lib/public/Files/ReservedWordException.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
509509
'OCP\\Files\\Notify\\IChange' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/IChange.php',
510510
'OCP\\Files\\Notify\\INotifyHandler' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/INotifyHandler.php',
511511
'OCP\\Files\\Notify\\IRenameChange' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/IRenameChange.php',
512+
'OCP\\Files\\ObjectStore\\Events\\BucketCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php',
512513
'OCP\\Files\\ObjectStore\\IObjectStore' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStore.php',
513514
'OCP\\Files\\ObjectStore\\IObjectStoreMultiPartUpload' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php',
514515
'OCP\\Files\\ReservedWordException' => __DIR__ . '/../../..' . '/lib/public/Files/ReservedWordException.php',

lib/private/Files/ObjectStore/S3ConnectionTrait.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Aws\S3\S3Client;
1414
use GuzzleHttp\Promise\Create;
1515
use GuzzleHttp\Promise\RejectedPromise;
16+
use OCP\EventDispatcher\IEventDispatcher;
17+
use OCP\Files\ObjectStore\Events\BucketCreatedEvent;
1618
use OCP\Files\StorageNotAvailableException;
1719
use OCP\ICertificateManager;
1820
use OCP\Server;
@@ -140,6 +142,13 @@ public function getConnection() {
140142
throw new StorageNotAvailableException('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket);
141143
}
142144
$this->connection->createBucket(['Bucket' => $this->bucket]);
145+
Server::get(IEventDispatcher::class)
146+
->dispatchTyped(new BucketCreatedEvent(
147+
$this->bucket,
148+
$options['endpoint'],
149+
$options['region'],
150+
$options['version']
151+
));
143152
$this->testTimeout();
144153
} catch (S3Exception $e) {
145154
$logger->debug('Invalid remote storage.', [
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-only
8+
*/
9+
namespace OCP\Files\ObjectStore\Events;
10+
11+
use OCP\EventDispatcher\Event;
12+
13+
class BucketCreatedEvent extends Event {
14+
15+
public function __construct(
16+
private readonly string $bucket,
17+
private readonly string $endpoint,
18+
private readonly string $region,
19+
private readonly string $version = 'latest',
20+
) {
21+
parent::__construct();
22+
}
23+
24+
public function getBucket(): string {
25+
return $this->bucket;
26+
}
27+
28+
public function getEndpoint(): string {
29+
return $this->endpoint;
30+
}
31+
32+
public function getRegion(): string {
33+
return $this->region;
34+
}
35+
36+
public function getVersion(): string {
37+
return $this->version;
38+
}
39+
}

0 commit comments

Comments
 (0)