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

Update _s3_file_query to check if an object exists explicitly. #168

Merged
merged 6 commits into from
Sep 17, 2021

Conversation

pjbull
Copy link
Member

@pjbull pjbull commented Sep 17, 2021

In our current setup, the _is_file_or_dir check relies on _s3_file_query, which requires list permissions. When we pass no_sign_request, we want to be able to download public files without credentials. However, we're not able to use this functionality because we do not have list permissions to the bucket.

This change introduces a first check to see if an object exists using load (which just calls head_object so should have very little overhead and does not require list permissions). If that does not work, we do our normal call to see if it is a dir.

Downside:
1 extra network call in the case of a directory.

Bonuses:

  • Update no_sign_request test to include scenario that failed before this fix.
  • We used get which downloads the file where we should have used load. Fixed this instance.
  • Some other tests were failing because our test bucket had not been cleaned up. I changed these tests to properly use the rig.test_dir folder so state on the bucket shouldn't exist. Also removed cleanup performed by _download_with_threads in the test since it should be handled by the rig now.

Closes #169

@github-actions
Copy link
Contributor

github-actions bot commented Sep 17, 2021

@codecov
Copy link

codecov bot commented Sep 17, 2021

Codecov Report

Merging #168 (40b098d) into master (ea3053f) will increase coverage by 0.0%.
The diff coverage is 100.0%.

@@          Coverage Diff           @@
##           master    #168   +/-   ##
======================================
  Coverage    94.1%   94.1%           
======================================
  Files          21      21           
  Lines        1183    1189    +6     
======================================
+ Hits         1114    1120    +6     
  Misses         69      69           
Impacted Files Coverage Δ
cloudpathlib/s3/s3client.py 93.8% <100.0%> (+0.3%) ⬆️

tests/mock_clients/mock_s3.py Outdated Show resolved Hide resolved
tests/test_s3_specific.py Outdated Show resolved Hide resolved
tests/test_s3_specific.py Outdated Show resolved Hide resolved
tests/test_s3_specific.py Outdated Show resolved Hide resolved
tests/test_s3_specific.py Outdated Show resolved Hide resolved
tests/test_s3_specific.py Outdated Show resolved Hide resolved
@pjbull
Copy link
Member Author

pjbull commented Sep 17, 2021

Thanks @jayqi should be good now!

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

Successfully merging this pull request may close these issues.

Downloading public files with no_sign_request throws error
2 participants