Skip to content

Commit

Permalink
configure disks
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 30, 2025
1 parent 38be038 commit e615f08
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/Illuminate/Foundation/Cloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static function bootstrapperBootstrapped(Application $app, string $bootst
{
(match ($bootstrapper) {
LoadConfiguration::class => function () use ($app) {
static::configureDisks($app);
static::configureUnpooledPostgresConnection($app);
static::ensureMigrationsUseUnpooledConnection($app);
},
Expand All @@ -36,7 +37,38 @@ public static function bootstrapperBootstrapped(Application $app, string $bootst
}

/**
* Adjust the database configuration for pooled Laravel Postgres.
* Configure the Laravel Cloud disks if applicable.
*/
public static function configureDisks(Application $app): void
{
if (! isset($_SERVER['LARAVEL_CLOUD_DISK_CONFIG'])) {
return;
}

$disks = json_decode($_SERVER['LARAVEL_CLOUD_DISK_CONFIG'], true);

foreach ($disks as $disk) {
$app['config']->set('filesystems.disks.'.$disk['disk'], [
'driver' => 's3',
'key' => $disk['access_key_id'],
'secret' => $disk['access_key_secret'],
'bucket' => $disk['bucket'],
'url' => $disk['url'],
'endpoint' => $disk['endpoint'],
'region' => 'auto',
'use_path_style_endpoint' => false,
'throw' => false,
'report' => false,
]);

if ($disk['is_default'] ?? false) {
$app['config']->set('filesystems.default', $disk['disk']);
}
}
}

/**
* Configure the unpooled Laravel Postgres connection if applicable.
*/
public static function configureUnpooledPostgresConnection(Application $app): void
{
Expand Down
33 changes: 33 additions & 0 deletions tests/Integration/Foundation/CloudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,37 @@ public function test_it_can_resolve_core_container_aliases()
'password' => 'test-password',
], $this->app['config']->get('database.connections.pgsql-unpooled'));
}

public function test_it_can_configure_disks()
{
$_SERVER['LARAVEL_CLOUD_DISK_CONFIG'] = json_encode(
[
[
'disk' => 'test-disk',
'access_key_id' => 'test-access-key-id',
'access_key_secret' => 'test-access-key-secret',
'bucket' => 'test-bucket',
'url' => 'test-url',
'endpoint' => 'test-endpoint',
'is_default' => false,
],
[
'disk' => 'test-disk-2',
'access_key_id' => 'test-access-key-id-2',
'access_key_secret' => 'test-access-key-secret-2',
'bucket' => 'test-bucket-2',
'url' => 'test-url-2',
'endpoint' => 'test-endpoint-2',
'is_default' => true,
],
]
);

Cloud::configureDisks($this->app);

$this->assertEquals('test-disk-2', $this->app['config']->get('filesystems.default'));
$this->assertEquals('test-access-key-id', $this->app['config']->get('filesystems.disks.test-disk.key'));

unset($_SERVER['LARAVEL_CLOUD_DISK_CONFIG']);
}
}

0 comments on commit e615f08

Please # to comment.