-
Notifications
You must be signed in to change notification settings - Fork 11
RDISCROWD-8392 upgrade to boto3 #1069
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
base: main
Are you sure you want to change the base?
Conversation
704a157 to
b2082cb
Compare
Pull Request Test Coverage Report for Build 19114618549Details
💛 - Coveralls |
dchhabda
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pybossa/cloud_store_api/base_conn.py
Outdated
| def get_path(self, path='/', **kwargs): | ||
| """ | ||
| Get the full path by prepending host_suffix if it exists. | ||
| This method provides compatibility with the legacy boto2-style interface. | ||
| """ | ||
| host_suffix = getattr(self, 'host_suffix', '') | ||
| if host_suffix: | ||
| if not host_suffix.startswith('/'): | ||
| host_suffix = '/' + host_suffix | ||
| if not host_suffix.endswith('/') and path.startswith('/'): | ||
| return host_suffix + path | ||
| elif host_suffix.endswith('/') and path.startswith('/'): | ||
| return host_suffix + path[1:] | ||
| else: | ||
| return host_suffix + path | ||
| return path | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be removed as it seems this method is not used anywhere except under tests.
| def get_object(self, bucket: str, key: str, **kwargs): | ||
| return self.client.get_object(Bucket=bucket, Key=key, **kwargs) | ||
|
|
||
| def put_object(self, bucket: str, key: str, body, **kwargs): | ||
| return self.client.put_object(Bucket=bucket, Key=key, Body=body, **kwargs) | ||
|
|
||
| def list_objects(self, bucket: str, prefix: str = "", **kwargs): | ||
| return self.client.list_objects_v2(Bucket=bucket, Prefix=prefix, **kwargs) | ||
|
|
||
| def upload_file(self, filename: str, bucket: str, key: str, **kwargs): | ||
| # Uses s3transfer under the hood (built-in retries/backoff) | ||
| return self.client.upload_file(filename, bucket, key, ExtraArgs=kwargs or {}) | ||
|
|
||
| def raw(self): | ||
| """Access the underlying boto3 client if you need operations not wrapped here.""" | ||
| return self.client | ||
|
|
||
| def get_bucket(self, bucket_name, validate=False, **kwargs): | ||
| """Return a bucket adapter for boto2-style interface compatibility.""" | ||
| return ProxiedBucketAdapter(self, bucket_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar function definitions exists at multiple places. Please have them defined in base class. Any customization can be done in derived classes. This will make codebase easier to evolve and reduce inconsistencies over time. Thanks
| def test_proxy_s3_error(self, create_connection): | ||
| admin, owner = UserFactory.create_batch(2) | ||
| project = ProjectFactory.create(owner=owner) | ||
| url = '/fileproxy/encrypted/s3/test/%s/file.pdf' % project.id | ||
| task = TaskFactory.create(project=project, info={ | ||
| 'url': url | ||
| }) | ||
|
|
||
| signature = signer.dumps({'task_id': task.id}) | ||
| req_url = '%s?api_key=%s&task-signature=%s' % (url, admin.api_key, signature) | ||
|
|
||
| key = self.get_key(create_connection) | ||
| key.get_contents_as_string.side_effect = S3ResponseError(403, 'Forbidden') | ||
|
|
||
| res = self.app.get(req_url, follow_redirects=True) | ||
| assert res.status_code == 500, f"Expected 500 Internal Server Error, got {res.status_code}" | ||
|
|
||
| @with_context | ||
| @patch('pybossa.cloud_store_api.s3.create_connection') | ||
| def test_proxy_key_not_found(self, create_connection): | ||
| admin, owner = UserFactory.create_batch(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the new approach to test these cases?
8b5557e to
b3a446e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a big PR with auto formatting at multiple places that is unrelated to the changes specific to this PR. Please remove the auto formatting so that PR only contains necessary changes. Also, fix coverage and failing tests to make all checks green. Thanks.
I’ll fix the test, but I’ll keep the auto-formatting changes. While they aren’t directly related to the main changes, they improve code readability and consistency. |
RDISCROWD-8392