add check for blob access#133
Open
ryanraaschCDC wants to merge 6 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds explicit Blob Storage access verification to BlobEndpoint so common Blob operations fail early with clearer, contextualized errors, and updates typing stubs plus introduces a new test module for the access-check behavior.
Changes:
- Add
BlobEndpoint.check_blob_access()/BlobEndpoint.verify_blob_access()and call verification beforewrite_blob,read_blobs,read_csv, andget_versions. - Update generated and template
.pyistubs to include the new methods. - Add pytest coverage for access-check behavior and for access-check gating on several BlobEndpoint methods.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
cfa/dataops/catalog.py |
Implements access check/verification and gates key blob operations behind verify_blob_access(). |
tests/test_blob_access_check.py |
Adds tests for the new access-check APIs and for method-level access gating (but currently mocks the wrong call path). |
typings/cfa/dataops/catalog.pyi |
Adds the new methods to the published typing stubs. |
cfa/dataops/stub_templates/catalog.pyi.mako |
Adds the new methods to the stub generation template to keep stubs in sync. |
Comments suppressed due to low confidence (5)
tests/test_blob_access_check.py:43
- check_blob_access() branches on HttpResponseError (status_code==401) raised from get_container_properties(); patching walk_blobs_in_container and raising a generic Exception with status_code won’t be caught by the intended handler. Mock BlobServiceClient.get_container_properties to raise an HttpResponseError (or subclass) with status_code=401.
def test_check_blob_access_401_unauthorized(self, blob_endpoint):
class Err401(Exception):
status_code = 401
with patch(
tests/test_blob_access_check.py:57
- Same as the 401 case: the implementation catches HttpResponseError and checks status_code==403. This test currently patches the wrong function and raises an exception type that won’t be handled as expected.
def test_check_blob_access_403_forbidden(self, blob_endpoint):
class Err403(Exception):
status_code = 403
with patch(
tests/test_blob_access_check.py:71
- check_blob_access() handles missing containers via ResourceNotFoundError from get_container_properties(); patching walk_blobs_in_container and raising a custom Exception won’t hit that branch.
def test_check_blob_access_resource_not_found(self, blob_endpoint):
class Err404(Exception):
status_code = 404
with patch(
tests/test_blob_access_check.py:87
- The 'Authentication failed' branch is only reached when ClientAuthenticationError is raised by get_container_properties(). Raising a generic Exception will hit the fallback 'Failed to verify access…' branch instead, making this assertion fail.
def test_check_blob_access_authentication_error(self, blob_endpoint):
with patch(
"cfa.dataops.catalog.walk_blobs_in_container",
side_effect=Exception("credential unavailable"),
):
has_access, message = blob_endpoint.check_blob_access()
tests/test_blob_access_check.py:97
- check_blob_access() does not call walk_blobs_in_container, so this test will currently attempt a real get_container_properties() call. Mock BlobServiceClient.get_container_properties to raise the generic exception so the fallback branch is exercised without network access.
def test_check_blob_access_generic_exception(self, blob_endpoint):
with patch(
"cfa.dataops.catalog.walk_blobs_in_container",
side_effect=Exception("Something went wrong"),
):
has_access, message = blob_endpoint.check_blob_access()
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…-no-access-warning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.