Skip to content

Commit 56f6aea

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

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@
414414
'OCP\\Files\\Notify\\IChange' => $baseDir . '/lib/public/Files/Notify/IChange.php',
415415
'OCP\\Files\\Notify\\INotifyHandler' => $baseDir . '/lib/public/Files/Notify/INotifyHandler.php',
416416
'OCP\\Files\\Notify\\IRenameChange' => $baseDir . '/lib/public/Files/Notify/IRenameChange.php',
417+
'OCP\\Files\\ObjectStore\\Events\\BucketCreatedEvent' => $baseDir . '/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php',
417418
'OCP\\Files\\ObjectStore\\IObjectStore' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStore.php',
418419
'OCP\\Files\\ObjectStore\\IObjectStoreMultiPartUpload' => $baseDir . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php',
419420
'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
@@ -447,6 +447,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
447447
'OCP\\Files\\Notify\\IChange' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/IChange.php',
448448
'OCP\\Files\\Notify\\INotifyHandler' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/INotifyHandler.php',
449449
'OCP\\Files\\Notify\\IRenameChange' => __DIR__ . '/../../..' . '/lib/public/Files/Notify/IRenameChange.php',
450+
'OCP\\Files\\ObjectStore\\Events\\BucketCreatedEvent' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/Events/BucketCreatedEvent.php',
450451
'OCP\\Files\\ObjectStore\\IObjectStore' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStore.php',
451452
'OCP\\Files\\ObjectStore\\IObjectStoreMultiPartUpload' => __DIR__ . '/../../..' . '/lib/public/Files/ObjectStore/IObjectStoreMultiPartUpload.php',
452453
'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
@@ -14,6 +14,8 @@
1414
use Aws\S3\S3Client;
1515
use GuzzleHttp\Promise\Create;
1616
use GuzzleHttp\Promise\RejectedPromise;
17+
use OCP\EventDispatcher\IEventDispatcher;
18+
use OCP\Files\ObjectStore\Events\BucketCreatedEvent;
1719
use OCP\Files\StorageNotAvailableException;
1820
use OCP\ICertificateManager;
1921
use OCP\Server;
@@ -141,6 +143,13 @@ public function getConnection() {
141143
throw new StorageNotAvailableException('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket);
142144
}
143145
$this->connection->createBucket(['Bucket' => $this->bucket]);
146+
Server::get(IEventDispatcher::class)
147+
->dispatchTyped(new BucketCreatedEvent(
148+
$this->bucket,
149+
$options['endpoint'],
150+
$options['region'],
151+
$options['version']
152+
));
144153
$this->testTimeout();
145154
} catch (S3Exception $e) {
146155
$logger->debug('Invalid remote storage.', [
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
/**
14+
* @since 29.0.16
15+
*/
16+
class BucketCreatedEvent extends Event {
17+
18+
19+
/**
20+
* @param string $bucket
21+
* @param string $endpoint
22+
* @param string $region
23+
* @param string $version
24+
*
25+
* @since 29.0.16
26+
*/
27+
public function __construct(
28+
private readonly string $bucket,
29+
private readonly string $endpoint,
30+
private readonly string $region,
31+
private readonly string $version = 'latest',
32+
) {
33+
parent::__construct();
34+
}
35+
36+
/**
37+
* @since 29.0.16
38+
*/
39+
public function getBucket(): string {
40+
return $this->bucket;
41+
}
42+
43+
/**
44+
* @since 29.0.16
45+
*/
46+
public function getEndpoint(): string {
47+
return $this->endpoint;
48+
}
49+
50+
/**
51+
* @since 29.0.16
52+
*/
53+
public function getRegion(): string {
54+
return $this->region;
55+
}
56+
57+
/**
58+
* @since 29.0.16
59+
*/
60+
public function getVersion(): string {
61+
return $this->version;
62+
}
63+
}

0 commit comments

Comments
 (0)