-
Notifications
You must be signed in to change notification settings - Fork 3
Refactoring: More OO, less module-level code #16
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
Conversation
|
""" WalkthroughThis change removes the Changes
Sequence Diagram(s)sequenceDiagram
participant Main
participant DocumentationIndex
participant Settings
Main->>DocumentationIndex: fetch_cratedb_docs(url)
DocumentationIndex->>DocumentationIndex: url_permitted(url)
alt URL permitted
DocumentationIndex->>DocumentationIndex: client.get(url)
else URL not permitted
DocumentationIndex-->>Main: Raise error or deny
end
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. 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 (
|
b84425a to
02b21a2
Compare
|
LGTM as a 1:1 refactor, but I'm not into the context so will let others approve. |
Introduce `DocumentationIndex` and `Settings` classes.
02b21a2 to
1190f6a
Compare
DocumentationIndexThere 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: 0
🧹 Nitpick comments (1)
cratedb_mcp/util/sql.py (1)
13-14: Instance creation for static methodsCreating an instance of
Settingsis unnecessary since you're only using static methods. Consider using the class directly.-settings = Settings() -Then update line 27 to use:
- is_dql = SqlStatementClassifier(expression=expression, permit_all=settings.permit_all_statements()).is_dql + is_dql = SqlStatementClassifier(expression=expression, permit_all=Settings.permit_all_statements()).is_dql
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
cratedb_mcp/__main__.py(2 hunks)cratedb_mcp/knowledge.py(2 hunks)cratedb_mcp/settings.py(1 hunks)cratedb_mcp/util/sql.py(2 hunks)tests/test_util.py(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
cratedb_mcp/util/sql.py (1)
cratedb_mcp/settings.py (2)
Settings(12-48)permit_all_statements(18-34)
tests/test_util.py (1)
cratedb_mcp/util/sql.py (1)
sql_is_permitted(16-32)
🔇 Additional comments (13)
cratedb_mcp/settings.py (1)
12-48: Looks good: Encapsulating settings into class methodsThe refactoring to a
Settingsclass with static methods is a good OO approach. This provides a centralized location for configuration and handles environment variable parsing and validation in a cleaner way.A couple minor points:
- Consider addressing the TODOs for tests (lines 31 and 45) now rather than deferring them
- The error message in line 31's comment about integers is misleading since you're converting to boolean
cratedb_mcp/__main__.py (2)
4-5: Clean import refactoringGood job simplifying the imports by removing
hisheland related constants.
35-37: Proper encapsulation of URL permission and HTTP clientThe refactoring correctly moves URL permission checks and HTTP client usage into the
DocumentationIndexclass, which aligns with the OO approach.cratedb_mcp/util/sql.py (2)
8-8: Good update of import to use Settings classThe import was correctly updated to use the new
Settingsclass rather than a module-level constant.
27-27: Updated to use Settings method appropriatelyThe code correctly uses the new
permit_all_statements()method from theSettingsclass.tests/test_util.py (3)
1-4: Added necessary imports for environment variable testingGood addition of the required imports for the updated tests.
20-26: Good test for environment variable success caseThis test properly verifies that:
- Setting the environment variable to "true" enables all SQL statements
- A warning is emitted when all statements are permitted
This aligns with the refactoring to environment variable-based configuration.
28-34: Good test for invalid environment variableThis test properly verifies that:
- Setting an invalid value for the environment variable causes the permission to be denied
- An appropriate warning is emitted about the invalid environment variable value
This ensures proper error handling in the refactored code.
cratedb_mcp/knowledge.py (5)
2-3: Good modularization with improved imports.The addition of typing and structured imports from the new Settings module aligns well with the objective of making the code more object-oriented.
Also applies to: 5-5, 8-9
116-124: Well-structured class attributes for configuration.Moving the settings and permitted URLs into class-level attributes implements good encapsulation. The list of permitted URLs is clearly defined with appropriate documentation, making the security boundaries explicit.
125-132: Good constructor implementation with improved HTTP client configuration.The initialization of the Hishel HTTP client with caching is well-structured, using the settings object to retrieve the cache TTL. This approach properly integrates the caching logic into the class and makes the dependency on the settings explicit.
136-140: Appropriate cache configuration with dynamic TTL.Using the settings object to configure the TTL for the cache is a good practice. Setting the TTL to slightly less than the docs cache TTL is a thoughtful detail to prevent edge cases where the cache might expire while being used.
143-159: Good encapsulation of URL permission logic.Moving the URL permission logic from a standalone function to an instance method increases cohesion and aligns with object-oriented principles. The method is well-documented with clear purpose, parameters, and return values.
1190f6a to
90aac8b
Compare
About
Just a bit of refactoring before the first release, adding classes
DocumentationIndexandSettings, to bundle relevant topic matters.