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

Utility function for parsing uri into container, path #48

Open
erinwild opened this issue Jul 29, 2019 · 1 comment
Open

Utility function for parsing uri into container, path #48

erinwild opened this issue Jul 29, 2019 · 1 comment

Comments

@erinwild
Copy link

I'm looking to gauge whether adding a utility function would be a useful or welcome addition to this library. In order to use cloudstorage in some of our projects we've added a helper function to parse s3 and wasb urls, for example, into container, path for use in bits of code like:

container = storage.get_container(parsed_container)
container.upload_blob(f, blob_name=parsed_path)

If there's any interest, I'd be happy to help with implementing and expanding a helper function like below:

def parse_blob_path(blob_path: str) -> Tuple[str, str, str]:
    """Splits a blob URL into a `(protocol, container, path)` tuple."""
    if not blob_path:
        raise CloudStorageError('blob_path cannot be empty')
    scheme, netloc, path, _, _ = urlsplit(blob_path)
    path_without_leading_slash = path[1:]
    if scheme in ('s3', 's3a', 's3n', 'gs'):
        container = netloc
    elif scheme in ('wasb', 'wasbs'):
        container, storage_account = netloc.split('@')
    else:
        raise CloudStorageError(f'Unknown scheme {scheme}; which cloud provider is this?')
    return scheme, container, path_without_leading_slash

Thoughts?

@scottwernervt
Copy link
Owner

Go ahead and implement it since it sounds like it would definitely benefit other users.

@erinwild erinwild removed their assignment Sep 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants