liormizr / s3path

s3path is a pathlib extension for AWS S3 Service
Apache License 2.0
206 stars 39 forks source link

Add presigned url methods to PureS3Path #125

Closed gabrieldemarmiesse closed 1 year ago

gabrieldemarmiesse commented 1 year ago

I see that PureS3Path has attributes specific to S3 and not present in pathlib.Path. https://github.com/liormizr/s3path/blob/master/docs/interface.rst#pure-paths

For our use case we use a lot of presigned urls. I was wondering if we could add a method like

from typing import Union, Literal

class PureS3Path:
    def presigned_url(self, mode: Literal["r", "w"] = "r", expiration: Union[timedelta, int] = 3600) -> str:
        """generate and return a presigned url"""
         ....

Would you be open to such a pull request?

liormizr commented 1 year ago

Hi @gabrieldemarmiesse

Nice idea I'm OK with a pull request like that Just one question, if you need to do a query to AWS S3 for this I think that it better to implement it in the S3Path class and note PureS3Path

gabrieldemarmiesse commented 1 year ago

To my knowledge, the presigned url is generated entirely on the client side and never actually call S3. For instance, you can create a presigned url for a minio server that doesn't exist since it's not calling anything. So we would call boto3, but I don't believe it does any network call

Source: https://stackoverflow.com/questions/55231229/does-generating-a-pre-signed-url-to-an-s3-object-using-the-aws-sdk-cost-anything

Generating a pre-signed URL is a purely client-side operation. There are no AWS costs associated with this and there is no network activity. The SDK you're using takes your current credentials, the bucket and key for your object, your method of choice (e.g. GET), an expiration time, optional HTTP headers, and calculates and signs a URL, all done locally.

With this information, do you think we should add the method to S3Path or PureS3Path?

liormizr commented 1 year ago

I think that like your implementation the S3Path class is more suitable It already have the ability to talk with boto3 something that is by design missing from PureS3Path

liormizr commented 1 year ago

Merged We will close this issue when we will release the next version

liormizr commented 1 year ago

Deployed in version 0.5.0