-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Add option to modify how a query is printed #54
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes introduced in this pull request involve enhancements to the handling of query strings in the Changes
Possibly related PRs
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (2)
Files skipped from review as they are similar to previous changes (1)
Additional context usedPath-based instructions (1)
Ruff
Additional comments not posted (8)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 7
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- snakemake_interface_storage_plugins/storage_object.py (5 hunks)
- snakemake_interface_storage_plugins/storage_provider.py (1 hunks)
Additional context used
Path-based instructions (2)
snakemake_interface_storage_plugins/storage_provider.py (1)
Pattern
**/*.py
: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of theself
argument of methods.
Do not suggest type annotation of thecls
argument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturn
statement.snakemake_interface_storage_plugins/storage_object.py (1)
Pattern
**/*.py
: Do not try to improve formatting.
Do not suggest type annotations for functions that are defined inside of functions or methods.
Do not suggest type annotation of theself
argument of methods.
Do not suggest type annotation of thecls
argument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturn
statement.
Ruff
snakemake_interface_storage_plugins/storage_object.py
147-147: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
154-154: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
161-161: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
193-193: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
200-200: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
223-223: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
Additional comments not posted (2)
snakemake_interface_storage_plugins/storage_provider.py (1)
144-150
: Excellent addition for enhancing security!The new
safe_print
method provides a valuable mechanism for storage providers to remove potentially sensitive information from queries before printing them. This is particularly useful for URL-like queries that may contain authentication tokens, usernames, or passwords.By default, the method simply returns the original query, allowing storage providers to opt-in to this feature and implement their own custom logic for removing sensitive data. This approach maintains backward compatibility while encouraging better security practices.
This addition aligns well with the PR objective of enhancing the handling of query outputs to improve security and privacy.
snakemake_interface_storage_plugins/storage_object.py (1)
71-71
: LGTM!The addition of the
print_query
attribute aligns with the PR objective of allowing storage providers to customize how a query is printed. It is assigned the value returned byself.provider.safe_print(self.query)
, which is expected to return a sanitized version of the query, potentially removing sensitive information.
@@ -173,7 +174,7 @@ async def managed_retrieve(self): | |||
else: | |||
os.remove(local_path) | |||
raise WorkflowError( | |||
f"Failed to retrieve storage object from {self.query}", e | |||
f"Failed to retrieve storage object from {self.print_query}", e |
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.
Use raise ... from e
for consistency with the previous instances.
The change from self.query
to self.print_query
in the error message is consistent with the PR objective of using the safe representation of the query in exception handling scenarios.
For consistency with the previous instances, use raise ... from e
to distinguish the exception from errors in exception handling:
- f"Failed to retrieve storage object from {self.print_query}", e
+ f"Failed to retrieve storage object from {self.print_query}") from e
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
f"Failed to retrieve storage object from {self.print_query}", e | |
f"Failed to retrieve storage object from {self.print_query}") from e |
@@ -143,21 +144,21 @@ | |||
async with self._rate_limiter(Operation.SIZE): | |||
return self.size() | |||
except Exception as e: | |||
raise WorkflowError(f"Failed to get size of {self.query}", e) | |||
raise WorkflowError(f"Failed to get size of {self.print_query}", e) |
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.
Use raise ... from e
to distinguish the exception from errors in exception handling.
The change from self.query
to self.print_query
in the error message is consistent with the PR objective of using the safe representation of the query in exception handling scenarios.
To improve the clarity of the exception, use raise ... from e
as suggested by the static analysis hint:
- raise WorkflowError(f"Failed to get size of {self.print_query}", e)
+ raise WorkflowError(f"Failed to get size of {self.print_query}") from e
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
raise WorkflowError(f"Failed to get size of {self.print_query}", e) | |
raise WorkflowError(f"Failed to get size of {self.print_query}") from e |
Tools
Ruff
147-147: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
@@ -219,4 +220,4 @@ | |||
async with self._rate_limiter(Operation.TOUCH): | |||
self.touch() | |||
except Exception as e: | |||
raise WorkflowError(f"Failed to touch storage object {self.query}", e) | |||
raise WorkflowError(f"Failed to touch storage object {self.print_query}", e) |
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.
Use raise ... from e
to distinguish the exception from errors in exception handling.
The change from self.query
to self.print_query
in the error message is consistent with the PR objective of using the safe representation of the query in exception handling scenarios.
To improve the clarity of the exception, use raise ... from e
as suggested by the static analysis hint:
- raise WorkflowError(f"Failed to touch storage object {self.print_query}", e)
+ raise WorkflowError(f"Failed to touch storage object {self.print_query}") from e
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
raise WorkflowError(f"Failed to touch storage object {self.print_query}", e) | |
raise WorkflowError(f"Failed to touch storage object {self.print_query}") from e |
Tools
Ruff
223-223: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
@@ -189,14 +190,14 @@ | |||
async with self._rate_limiter(Operation.REMOVE): | |||
self.remove() | |||
except Exception as e: | |||
raise WorkflowError(f"Failed to remove storage object {self.query}", e) | |||
raise WorkflowError(f"Failed to remove storage object {self.print_query}", e) |
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.
Use raise ... from e
to distinguish the exception from errors in exception handling.
The change from self.query
to self.print_query
in the error message is consistent with the PR objective of using the safe representation of the query in exception handling scenarios.
To improve the clarity of the exception, use raise ... from e
as suggested by the static analysis hint:
- raise WorkflowError(f"Failed to remove storage object {self.print_query}", e)
+ raise WorkflowError(f"Failed to remove storage object {self.print_query}") from e
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
raise WorkflowError(f"Failed to remove storage object {self.print_query}", e) | |
raise WorkflowError(f"Failed to remove storage object {self.print_query}") from e |
Tools
Ruff
193-193: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
|
||
async def managed_store(self): | ||
try: | ||
async with self._rate_limiter(Operation.STORE): | ||
self.store_object() | ||
except Exception as e: | ||
raise WorkflowError(f"Failed to store output in storage {self.query}", e) | ||
raise WorkflowError(f"Failed to store output in storage {self.print_query}", e) |
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.
Use raise ... from e
to distinguish the exception from errors in exception handling.
The change from self.query
to self.print_query
in the error message is consistent with the PR objective of using the safe representation of the query in exception handling scenarios.
To improve the clarity of the exception, use raise ... from e
as suggested by the static analysis hint:
- raise WorkflowError(f"Failed to store output in storage {self.print_query}", e)
+ raise WorkflowError(f"Failed to store output in storage {self.print_query}") from e
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
raise WorkflowError(f"Failed to store output in storage {self.print_query}", e) | |
raise WorkflowError(f"Failed to store output in storage {self.print_query}") from e |
Tools
Ruff
200-200: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
|
||
async def managed_exists(self) -> bool: | ||
try: | ||
async with self._rate_limiter(Operation.EXISTS): | ||
return self.exists() | ||
except Exception as e: | ||
raise WorkflowError(f"Failed to check existence of {self.query}", e) | ||
raise WorkflowError(f"Failed to check existence of {self.print_query}", e) |
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.
Use raise ... from e
to distinguish the exception from errors in exception handling.
The change from self.query
to self.print_query
in the error message is consistent with the PR objective of using the safe representation of the query in exception handling scenarios.
To improve the clarity of the exception, use raise ... from e
as suggested by the static analysis hint:
- raise WorkflowError(f"Failed to check existence of {self.print_query}", e)
+ raise WorkflowError(f"Failed to check existence of {self.print_query}") from e
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
raise WorkflowError(f"Failed to check existence of {self.print_query}", e) | |
raise WorkflowError(f"Failed to check existence of {self.print_query}") from e |
Tools
Ruff
161-161: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
|
||
async def managed_mtime(self) -> float: | ||
try: | ||
async with self._rate_limiter(Operation.MTIME): | ||
return self.mtime() | ||
except Exception as e: | ||
raise WorkflowError(f"Failed to get mtime of {self.query}", e) | ||
raise WorkflowError(f"Failed to get mtime of {self.print_query}", e) |
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.
Use raise ... from e
to distinguish the exception from errors in exception handling.
The change from self.query
to self.print_query
in the error message is consistent with the PR objective of using the safe representation of the query in exception handling scenarios.
To improve the clarity of the exception, use raise ... from e
as suggested by the static analysis hint:
- raise WorkflowError(f"Failed to get mtime of {self.print_query}", e)
+ raise WorkflowError(f"Failed to get mtime of {self.print_query}") from e
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
raise WorkflowError(f"Failed to get mtime of {self.print_query}", e) | |
raise WorkflowError(f"Failed to get mtime of {self.print_query}") from e |
Tools
Ruff
154-154: Within an
except
clause, raise exceptions withraise ... from err
orraise ... from None
to distinguish them from errors in exception handling(B904)
This adds an attribute to
storage_object
calledprint_query
which allows a storage provider to change how a query is printed (e.g. removing senstitive information) through a new methodsafe_print()
which by default just returns the query.Related to issue snakemake/snakemake#3087 and required for PR snakemake/snakemake#3089.
Summary by CodeRabbit
safe_print
method to enhance security by processing query strings to remove sensitive information.