Skip to content

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

Merged
jayqi merged 6 commits intomasterfrom
update-file-dir-check
Sep 17, 2021
Merged

Update _s3_file_query to check if an object exists explicitly. #168
jayqi merged 6 commits intomasterfrom
update-file-dir-check

Conversation

@pjbull
Copy link
Copy Markdown
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
Copy Markdown
Contributor

github-actions Bot commented Sep 17, 2021

@codecov
Copy link
Copy Markdown

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%) ⬆️

Comment thread tests/mock_clients/mock_s3.py Outdated
Comment thread tests/test_s3_specific.py Outdated
Comment thread tests/test_s3_specific.py Outdated
Comment thread tests/test_s3_specific.py Outdated
Comment thread tests/test_s3_specific.py Outdated
Comment thread tests/test_s3_specific.py Outdated
@pjbull
Copy link
Copy Markdown
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