spiral/framework

[spiral/storage] Simplified AWS Bucket Configuration

Closed this issue · 1 comments

Currently, when configuring AWS S3 buckets, there is a duplication of server configuration details when defining different buckets that use the same server. This results in redundancy and maintenance challenges, as the same server and credentials need to be repeated for each bucket. This feature request proposes a streamlined approach to configure AWS buckets within the Spiral Framework's storage configuration, enhancing simplicity, ease of maintenance, and reducing redundancy.

Here is a simple example

/** @see \Spiral\Storage\Config\StorageConfig */
return [
    'default' => env('STORAGE_SERVER', 'uploads'),

    'servers' => [
        'uploads' => [
            'adapter' => 's3',
            'endpoint' => env('AWS_ENDPOINT_URL'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => 'uploads',
            'key' => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
        ],
        'pdf' =>[
            'adapter' => 's3',
            'endpoint' => env('AWS_ENDPOINT_URL'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => 'pdf',
            'key' => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
        ],
    ],

    'buckets' => [
        'uploads' => [
            'server' => 'uploads',
        ],
        'pdf' => [
            'server' => 'pdf',
        ],
    ],
];

Requested Feature:

Introduce the ability to define bucket-specific options within the bucket configuration itself. This enhancement would allow developers to specify bucket-specific options directly, while still utilizing the shared server configuration.

return [
  //...

  'html' => [
      'server' => 'html',
      'options' => [
          // Bucket-specific options here
          'bucket' => 'files', // Specify the bucket name directly
          'acl' => 'public-read',
          'cache_control' => 'max-age=3600',
      ],
  ],
];

Benefits:

With the proposed enhancement, developers can define bucket-specific options within the bucket configuration itself, reducing the need to duplicate server and credential information.

@butschster Hi, in the storage.php configuration file, you can specify a bucket, region, visibility, prefix. for a server. The config might look like this:

/** @see \Spiral\Storage\Config\StorageConfig */
return [
    'default' => env('STORAGE_SERVER', 'uploads'),

    'servers' => [
        's3' => [
            'adapter' => 's3',
            'endpoint' => env('AWS_ENDPOINT_URL'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_DEFAULT_BUCKET'),
            'key' => env('AWS_KEY'),
            'secret' => env('AWS_SECRET'),
        ],
    ],

    'buckets' => [
        'uploads' => [
            'server' => 's3',
            'bucket' => 'uploads'  // <-------
        ],
        'pdf' => [
            'server' => 's3',
            'bucket' => 'pdf'  // <-------
        ],
    ],
];

Read more about the Storage component:
https://spiral.dev/docs/advanced-storage/current