Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MattMonk
Copy link

@MattMonk MattMonk commented Sep 18, 2024

This adds an attribute to storage_object called print_query which allows a storage provider to change how a query is printed (e.g. removing senstitive information) through a new method safe_print() which by default just returns the query.

Related to issue snakemake/snakemake#3087 and required for PR snakemake/snakemake#3089.

Summary by CodeRabbit

  • New Features
    • Introduced safe_print method to enhance security by processing query strings to remove sensitive information.
  • Bug Fixes
    • Improved error reporting with safer and more informative representations of queries in various methods, enhancing clarity during exception handling.

Copy link

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes introduced in this pull request involve enhancements to the handling of query strings in the snakemake_interface_storage_plugins module. A new instance variable print_query is added to the StorageObjectBase class to improve error reporting by providing a safer representation of the query attribute. Additionally, a new method safe_print is introduced in the storage_provider.py file to process query strings and remove sensitive information, thereby enhancing security practices.

Changes

File Path Change Summary
snakemake_interface_storage_plugins/storage_object.py Added self.print_query to StorageObjectBase for safer error reporting in various methods.
snakemake_interface_storage_plugins/storage_provider.py Introduced def safe_print(self, query: str) -> str to handle sensitive information in query strings.

Possibly related PRs


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7afeb7a and 026cb90.

Files selected for processing (2)
  • snakemake_interface_storage_plugins/storage_object.py (5 hunks)
  • snakemake_interface_storage_plugins/storage_provider.py (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • snakemake_interface_storage_plugins/storage_provider.py
Additional context used
Path-based instructions (1)
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 the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

Ruff
snakemake_interface_storage_plugins/storage_object.py

147-147: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


154-154: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


161-161: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


193-195: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


202-204: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


227-227: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

Additional comments not posted (8)
snakemake_interface_storage_plugins/storage_object.py (8)

71-71: LGTM!

The introduction of print_query using the safe_print method of the provider aligns with the PR objective and allows for customization by storage providers.


147-147: The past review comment suggesting the use of raise ... from e is still valid and applicable to the current code segment.

Tools
Ruff

147-147: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


154-154: The past review comment suggesting the use of raise ... from e is still valid and applicable to the current code segment.

Tools
Ruff

154-154: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


161-161: The past review comment suggesting the use of raise ... from e is still valid and applicable to the current code segment.

Tools
Ruff

161-161: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


177-177: The past review comment suggesting the use of raise ... from e is still valid and applicable to the current code segment.


193-195: The past review comment suggesting the use of raise ... from e is still valid and applicable to the current code segment.

Tools
Ruff

193-195: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


202-204: The past review comment suggesting the use of raise ... from e is still valid and applicable to the current code segment.

Tools
Ruff

202-204: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


227-227: The past review comment suggesting the use of raise ... from e is still valid and applicable to the current code segment.

Tools
Ruff

227-227: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    -- I pushed a fix in commit <commit_id>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    -- @coderabbitai generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    -- @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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

Commits

Files that changed from the base of the PR and between 19a5f80 and ed2e41e.

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 the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return 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 the self argument of methods.
Do not suggest type annotation of the cls argument of classmethods.
Do not suggest return type annotation if a function or method does not contain a return statement.

Ruff
snakemake_interface_storage_plugins/storage_object.py

147-147: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


154-154: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


161-161: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


193-193: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


200-200: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


223-223: Within an except clause, raise exceptions with raise ... from err or raise ... 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 by self.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
Copy link

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.

Suggested change
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)
Copy link

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.

Suggested change
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 with raise ... from err or raise ... 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)
Copy link

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.

Suggested change
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 with raise ... from err or raise ... 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)
Copy link

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.

Suggested change
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 with raise ... from err or raise ... 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)
Copy link

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.

Suggested change
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 with raise ... from err or raise ... 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)
Copy link

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.

Suggested change
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 with raise ... from err or raise ... 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)
Copy link

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.

Suggested change
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 with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

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.

2 participants