Skip to content

Commit e615f08

Browse files
committed
configure disks
1 parent 38be038 commit e615f08

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

src/Illuminate/Foundation/Cloud.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static function bootstrapperBootstrapped(Application $app, string $bootst
2525
{
2626
(match ($bootstrapper) {
2727
LoadConfiguration::class => function () use ($app) {
28+
static::configureDisks($app);
2829
static::configureUnpooledPostgresConnection($app);
2930
static::ensureMigrationsUseUnpooledConnection($app);
3031
},
@@ -36,7 +37,38 @@ public static function bootstrapperBootstrapped(Application $app, string $bootst
3637
}
3738

3839
/**
39-
* Adjust the database configuration for pooled Laravel Postgres.
40+
* Configure the Laravel Cloud disks if applicable.
41+
*/
42+
public static function configureDisks(Application $app): void
43+
{
44+
if (! isset($_SERVER['LARAVEL_CLOUD_DISK_CONFIG'])) {
45+
return;
46+
}
47+
48+
$disks = json_decode($_SERVER['LARAVEL_CLOUD_DISK_CONFIG'], true);
49+
50+
foreach ($disks as $disk) {
51+
$app['config']->set('filesystems.disks.'.$disk['disk'], [
52+
'driver' => 's3',
53+
'key' => $disk['access_key_id'],
54+
'secret' => $disk['access_key_secret'],
55+
'bucket' => $disk['bucket'],
56+
'url' => $disk['url'],
57+
'endpoint' => $disk['endpoint'],
58+
'region' => 'auto',
59+
'use_path_style_endpoint' => false,
60+
'throw' => false,
61+
'report' => false,
62+
]);
63+
64+
if ($disk['is_default'] ?? false) {
65+
$app['config']->set('filesystems.default', $disk['disk']);
66+
}
67+
}
68+
}
69+
70+
/**
71+
* Configure the unpooled Laravel Postgres connection if applicable.
4072
*/
4173
public static function configureUnpooledPostgresConnection(Application $app): void
4274
{

tests/Integration/Foundation/CloudTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,37 @@ public function test_it_can_resolve_core_container_aliases()
2323
'password' => 'test-password',
2424
], $this->app['config']->get('database.connections.pgsql-unpooled'));
2525
}
26+
27+
public function test_it_can_configure_disks()
28+
{
29+
$_SERVER['LARAVEL_CLOUD_DISK_CONFIG'] = json_encode(
30+
[
31+
[
32+
'disk' => 'test-disk',
33+
'access_key_id' => 'test-access-key-id',
34+
'access_key_secret' => 'test-access-key-secret',
35+
'bucket' => 'test-bucket',
36+
'url' => 'test-url',
37+
'endpoint' => 'test-endpoint',
38+
'is_default' => false,
39+
],
40+
[
41+
'disk' => 'test-disk-2',
42+
'access_key_id' => 'test-access-key-id-2',
43+
'access_key_secret' => 'test-access-key-secret-2',
44+
'bucket' => 'test-bucket-2',
45+
'url' => 'test-url-2',
46+
'endpoint' => 'test-endpoint-2',
47+
'is_default' => true,
48+
],
49+
]
50+
);
51+
52+
Cloud::configureDisks($this->app);
53+
54+
$this->assertEquals('test-disk-2', $this->app['config']->get('filesystems.default'));
55+
$this->assertEquals('test-access-key-id', $this->app['config']->get('filesystems.disks.test-disk.key'));
56+
57+
unset($_SERVER['LARAVEL_CLOUD_DISK_CONFIG']);
58+
}
2659
}

0 commit comments

Comments
 (0)