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

[SVCS-826] S3 Compatablilty #351

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

NyanHelsing
Copy link
Contributor

@NyanHelsing NyanHelsing commented Jun 13, 2018

Purpose

This PR enables users to connect any s3 compatible storage provider to their OSF account using the s3 addon.

Changes

Rewrites all s3 provider operations to use boto3 (boto2 has issues signing urls that will work properly with minio)

QA Notes

Ensure that users can connect s3-compatible providers

#Documentation

Side Effects

Users modifying an account will necessarily modify that account for any other user that also has connected this account. (This is already a behaviour experienced using the 'connect or reauthorize dialog)

Ticket

https://openscience.atlassian.net/browse/SVCS-826

Copy link
Contributor

@cslzchen cslzchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this PR? Looks related to your S3-like provider update?

I see some of the API calls are replaced with client library code, which is a major change. What's the primary reason? How does this impact our async requests?

@NyanHelsing
Copy link
Contributor Author

Yep that's true, its related to s3-compat.

Replacing the calls with client library is because the signature stuff in boto2 is delusional. the signature stuff in boto3 works as intended.

It is going to be synchronous as written now, but there's two options -
1. Just wrap it in a await loop.run_in_executor()
2. There's an asyncio wrapper around boto3

@NyanHelsing NyanHelsing changed the title Allow arbitrary host/port/encryption [SVCS-826] Allow arbitrary host/port/encryption Jun 28, 2018
@NyanHelsing NyanHelsing changed the title [SVCS-826] Allow arbitrary host/port/encryption [SVCS-826] S3 Compatablilty Jun 29, 2018
boto2 causes lots of problems, and trying to use both is trying. Use
boto3 for all s3 operations.
Upgrades boto2 to boto3.
This required some implementations of operations to change because of
some inflexibility inside of boto - It likes to do it the boto way, but
using some of the internals, to generate signed urls for example, is
difficult to call in isolation. In the interest of getting it
implemented sooner than later, we use the boto way of doing some things
rather than making our own requests manually.
Removes some code that was written during trying to get the provider
working. This code was exploratory and does not work.
Finishes updates to the sign_url functions to allow use with boto3's
`generate_presigned_url`

async def revisions(self, path, **kwargs):
"""Get past versions of the requested key

:param str path: The path to a key
:rtype list:
"""
await self._check_region()

query_params = {'prefix': path.path, 'delimiter': '/', 'versions': ''}
url = functools.partial(self.bucket.generate_url, settings.TEMP_URL_SECS, 'GET', query_parameters=query_params)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be fixed

@@ -1,6 +1,7 @@
agent==0.1.2
aiohttp==0.18.2
git+https://github.com/felliott/boto.git@feature/gen-url-query-params-6#egg=boto
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove old boto

@@ -187,12 +188,16 @@ def size(self):
def at_eof(self):
return self.inner.at_eof()

def tell(self):
return self.offset

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not strictly necessary, but was needed for a transient implementation. Still technically correct and simply makes our streams more stream-y.

@@ -105,15 +105,17 @@ def _async_retry(func):
))


def normalize_datetime(date_string):
if date_string is None:
def normalize_datetime(date):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not always a string, so saying date_str here is a little misleading.


import xmltodict

import xml.sax.saxutils

#import aioboto3
from boto import config as boto_config
from boto.compat import BytesIO # type: ignore
from boto.utils import compute_md5
from boto.auth import get_auth_handler
from boto.s3.connection import S3Connection
from boto.s3.connection import OrdinaryCallingFormat
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove old boto

:param HttpMethod: The http method to use on the generated url. By
default, the http method is whatever is used in the method's model.
:returns: The presigned url
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another comment here explaining the patch better

# to supply the client with a string of the region name. First we
# make a temporary client in order to get that string. We put the
# client creation inside a lmabda so its easier to call twice.
# This must be a lambda an *not* a partial, because we want the
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really relevant here.

# if kwargs.get('displayName'):
# get_kwargs['ResponseContentDisposition'] = 'attachment; filename*=UTF-8\'\'{}'.format(parse.quote(kwargs['displayName']))
# else:
# get_kwargs['ResponseContentDisposition'] = 'attachment'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if dead

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

Successfully merging this pull request may close these issues.

2 participants