FoalTS / foal

Full-featured Node.js framework, with no complexity. πŸš€ Simple and easy to use, TypeScript-based and well-documented.
https://foalts.org/
MIT License
1.88k stars 137 forks source link

Support ServerSideEncryption #1013

Closed khaliqgant closed 2 years ago

khaliqgant commented 2 years ago

At the moment it looks like the upload function is used but does't accept an option to pass in the ServerSideEncryption header. The upload function takes the same params as the the putObject function:

s3.putObject({
        Bucket: bucketName,
        Key: key,
        Body: fileStream,
        ServerSideEncryption: 'AES256',
        Metadata: { 'docId': 'DOCID', 'docKey': 'XYZZY', 'index': 'pdf' }
})

Reference for the above

It would be great if the disk.write updated usage could look like this:

 await this.disk.write(path, file.buffer, {
      name,
      ServerSideEncryption: 'AES256'
 });

FoalTS is fantastic btw, awesome work!

khaliqgant commented 2 years ago

Hi @LoicPoullain have you had any chance to take a look at this?

Thanks!

LoicPoullain commented 2 years ago

FoalTS is fantastic btw, awesome work!

Thank you!

Hi @LoicPoullain have you had any chance to take a look at this?

I'm thinking of adding a fourth parameter (not the third) to the write function to pass custom options to the putObject method. This would be specific to the S3Disk service (and not Disk).

I still need to think about this to check that it won't introduce backward incompatibility, especially on the typing.

LoicPoullain commented 2 years ago

@khaliqgant is the ServerSideEncryption option is specific to the entire bucket or is it used only for specific files in the bucket?

khaliqgant commented 2 years ago

@khaliqgant is the ServerSideEncryption option is specific to the entire bucket or is it used only for specific files in the bucket?

Thanks for your attention to this! It’s a bucket wide policy

LoicPoullain commented 2 years ago

Ok thanks. πŸ‘

Yes, so I think the best place to specify the option will be in the configuration then. It will allow us to keep using the generic Disk and @ValidateMultipartBody hook in this case. In this way, we will still be able to write a unique code that uses the local file system in development (for testing) and the S3 bucket in production.

LoicPoullain commented 2 years ago

Feature added in v2.8. Will be released this week or week-end.

khaliqgant commented 2 years ago

Awesome, thanks! Thanks again for your impressive work