feat: Add option to modify how a query is printed#54
feat: Add option to modify how a query is printed#54johanneskoester merged 3 commits intosnakemake:mainfrom
Conversation
📝 WalkthroughWalkthroughThe changes introduced in this pull request involve modifications to error handling in several asynchronous methods of the Changes
Possibly related PRs
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used📓 Path-based instructions (1)`**/*.py`: Do not try to improve formatting. Do not suggest ...
🪛 Ruff (0.8.2)snakemake_interface_storage_plugins/storage_object.py195-197: Within an (B904) 🔇 Additional comments (3)
✨ Finishing Touches
🪧 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.
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 theselfargument of methods.
Do not suggest type annotation of theclsargument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturnstatement.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 theselfargument of methods.
Do not suggest type annotation of theclsargument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturnstatement.
Ruff
snakemake_interface_storage_plugins/storage_object.py
147-147: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
154-154: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
161-161: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
193-193: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
200-200: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto distinguish them from errors in exception handling(B904)
223-223: Within an
exceptclause, raise exceptions withraise ... from errorraise ... from Noneto 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_printmethod 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_queryattribute 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.
7afeb7a to
026cb90
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
snakemake_interface_storage_plugins/storage_object.py(5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.py`: Do not try to improve formatting. Do not suggest ...
**/*.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 theselfargument of methods.
Do not suggest type annotation of theclsargument of classmethods.
Do not suggest return type annotation if a function or method does not contain areturnstatement.
snakemake_interface_storage_plugins/storage_object.py
🪛 GitHub Actions: CI
snakemake_interface_storage_plugins/storage_object.py
[error] 178-178: E999 SyntaxError: unmatched ')'
🔇 Additional comments (7)
snakemake_interface_storage_plugins/storage_object.py (7)
71-71: Proper implementation of safe_print feature.This new line adds the
print_queryattribute that utilizes the provider'ssafe_printmethod as described in the PR objectives. This will allow storage providers to customize how the query is printed, which is particularly useful for hiding sensitive information.
147-147: Good error handling implementation.The change from
self.querytoself.print_queryin the error message aligns with the PR objective to use the safe representation of the query in exception handling. Thefrom esyntax for chaining exceptions is correctly used.
154-154: Good error handling implementation.The change from
self.querytoself.print_queryin the error message aligns with the PR objective to use the safe representation of the query in exception handling. Thefrom esyntax for chaining exceptions is correctly used.
161-161: Good error handling implementation.The change from
self.querytoself.print_queryin the error message aligns with the PR objective to use the safe representation of the query in exception handling. Thefrom esyntax for chaining exceptions is correctly used.
193-195: Useraise ... from eto distinguish the exception from errors in exception handling.The change from
self.querytoself.print_queryin 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:raise WorkflowError( - f"Failed to remove storage object {self.print_query}", e + f"Failed to remove storage object {self.print_query}") from e )
202-204: Useraise ... from eto distinguish the exception from errors in exception handling.The change from
self.querytoself.print_queryin 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:raise WorkflowError( - f"Failed to store output in storage {self.print_query}", e + f"Failed to store output in storage {self.print_query}") from e )
227-227: Good error handling implementation.The change from
self.querytoself.print_queryin the error message aligns with the PR objective to use the safe representation of the query in exception handling. Thefrom esyntax for chaining exceptions is correctly used.
There was a problem hiding this comment.
Very good catch! We also have to use print_query in the main snakemake whenever storage_object.query is accessed for logging or exception handling there. Can you create a follow-up PR once this is merged and released?
Further, can you update the example skeleton in the readme in this PR and after the release the poetry-plugin-snakemake repo to contain the method in the skeleton?
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
Thanks @johanneskoester! I've updated the README and would be happy to open a PR for the poetry plugin. This PR snakemake/snakemake#3089 starts to replace things with |
|
Thanks a lot! |
Adds the methods `postprocess_query` and `safe_print` to the storage plugin scaffolding. Depends on snakemake/snakemake-interface-storage-plugins#54. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced customizable query processing to support query normalization. - Added secure logging for handling queries safely without exposing sensitive details. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Adds the new safe_print method (snakemake/snakemake-interface-storage-plugins#54) to censor information in the XRootD URL. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced secure URL printing functionality that ensures sensitive information is protected when URLs are displayed. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This adds an attribute to
storage_objectcalledprint_querywhich 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