Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Region cannot be set using url parameters #83

Open
sdorgancs opened this issue Jan 17, 2021 · 0 comments
Open

Region cannot be set using url parameters #83

sdorgancs opened this issue Jan 17, 2021 · 0 comments

Comments

@sdorgancs
Copy link

Hello,
I would like to be able to set the region using url parameters, like in the example below:

fs = open_fs('s3://testbucket?endpoint_url=localhost:9000&region=us-east-1')

But S3FSOpener in opener.py doest not get it

class S3FSOpener(Opener):
    protocols = ["s3"]

    def open_fs(self, fs_url, parse_result, writeable, create, cwd):
        bucket_name, _, dir_path = parse_result.resource.partition("/")
        if not bucket_name:
            raise OpenerError("invalid bucket name in '{}'".format(fs_url))
        strict = (
            parse_result.params["strict"] == "1"
            if "strict" in parse_result.params
            else True
        )
        s3fs = S3FS(
            bucket_name,
            dir_path=dir_path or "/",
            aws_access_key_id=parse_result.username or None,
            aws_secret_access_key=parse_result.password or None,
            endpoint_url=parse_result.params.get("endpoint_url", None),
            acl=parse_result.params.get("acl", None),
            cache_control=parse_result.params.get("cache_control", None),
            strict=strict,
        )
        return s3fs

The change to make it working is very simple

class S3FSOpener(Opener):
    protocols = ["s3"]

    def open_fs(self, fs_url, parse_result, writeable, create, cwd):
        bucket_name, _, dir_path = parse_result.resource.partition("/")
        if not bucket_name:
            raise OpenerError("invalid bucket name in '{}'".format(fs_url))
        strict = (
            parse_result.params["strict"] == "1"
            if "strict" in parse_result.params
            else True
        )
        s3fs = S3FS(
            bucket_name,
            dir_path=dir_path or "/",
            aws_access_key_id=parse_result.username or None,
            aws_secret_access_key=parse_result.password or None,
            endpoint_url=parse_result.params.get("endpoint_url", None),
            # line to add
            region=parse_result.params.get("region", None),
            acl=parse_result.params.get("acl", None),
            cache_control=parse_result.params.get("cache_control", None),
            strict=strict,
        )
        return s3fs

Could you manage this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant