silverstripe / silverstripe-s3

Silverstripe module to store assets in S3 rather than on the local filesystem (SS4/SS5 only)
BSD 3-Clause "New" or "Revised" License
20 stars 25 forks source link

Allow empty prefix for {Public,Protected}Adapter #36

Closed omoustaouda closed 4 years ago

omoustaouda commented 4 years ago

The prefix is not always used in the adapters.

This PR allows to make it optional.

an example where no prefix is used is (last line):

---
Name: custom-silverstripe-s3
After:
  - '#silverstripes3-flysystem'
---
SilverStripe\Core\Injector\Injector:
  Aws\S3\S3Client:
    constructor:
      configuration:
        region: eu-central-1
        version: latest
        credentials:
          key: '`AWS_ACCESS_KEY_ID`'
          secret: '`AWS_SECRET_ACCESS_KEY`'
  SilverStripe\S3\Adapter\PublicAdapter:
    constructor:
      s3Client: '%$Aws\S3\S3Client'
      bucket: '`AWS_BUCKET_NAME`'
      prefix: '' # <---- HERE no prefix is being used
obj63mc commented 4 years ago

With SS and the way they secure your file assets (published/unpublished) you have to have some sort of prefix so that protected assets and public assets live in different directories, allowing you to be able to configure the buckets security policy properly.

Simply setting the prefix to nothing and having everything upload to the root would cause possible issues if you have say an unpublished file with the same name as a published file. They could potentially overwrite themselves. Also if all the assets are in the same directory, technically protected (unpublished assets) could be accessed by anyone if they new the file name.