Support relative blob paths in AzureBlobStorageIO#1478
Open
biefan wants to merge 1 commit intoAzure:mainfrom
Open
Support relative blob paths in AzureBlobStorageIO#1478biefan wants to merge 1 commit intoAzure:mainfrom
biefan wants to merge 1 commit intoAzure:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates AzureBlobStorageIO so callers can pass either a full Azure Blob URL or a relative blob path (within the configured container) consistently across blob operations.
Changes:
- Added a
_resolve_blob_name()helper to accept either full blob URLs or relative blob paths. - Updated
read_file(),write_file(),path_exists(), andis_file()to use the helper instead of requiring URL parsing. - Added regression tests for relative-path handling in
read_file()andpath_exists().
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
pyrit/models/storage_io.py |
Adds blob-name resolution helper and applies it across Azure blob operations to support relative paths. |
tests/unit/models/test_storage_io.py |
Adds unit tests validating relative-path behavior for read_file() and path_exists(). |
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+268
to
+272
| parsed_url = urlparse(path_str) | ||
| if parsed_url.scheme and parsed_url.netloc: | ||
| _, blob_name = self.parse_blob_url(path_str) | ||
| return blob_name | ||
| return path_str |
| if not self._client_async: | ||
| await self._create_container_client_async() | ||
| _, blob_name = self.parse_blob_url(str(path)) | ||
| blob_name = self._resolve_blob_name(path) |
| if not self._client_async: | ||
| await self._create_container_client_async() | ||
| _, blob_name = self.parse_blob_url(str(path)) | ||
| blob_name = self._resolve_blob_name(path) |
| await self._create_container_client_async() | ||
| try: | ||
| _, blob_name = self.parse_blob_url(str(path)) | ||
| blob_name = self._resolve_blob_name(path) |
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.
Summary
This updates
AzureBlobStorageIOso that relative blob paths are handled consistently across blob operations.Problem
Several
AzureBlobStorageIOmethods document or imply support for either:In particular,
read_file()explicitly documents relative-path support. However, the implementation always routed the input throughparse_blob_url(), which only accepts full URLs and raisesValueErrorfor relative paths.That means calls such as:
fail immediately with
ValueError("Invalid blob URL")even though the method contract says the relative path should be used as-is.The same issue also affects
path_exists()andis_file(), and it unnecessarily constrainswrite_file()to URL-only inputs as well.Fix
read_file(),write_file(),path_exists(), andis_file()This keeps the existing full-URL behavior intact while making the relative-path behavior match the documented API.
Tests
Added regression coverage for relative-path handling in:
read_file()path_exists()Validation command:
Validation result: