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

fix: auth schemes #1226

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

fix: auth schemes #1226

wants to merge 4 commits into from

Conversation

Devanshusisodiya
Copy link
Contributor

@Devanshusisodiya Devanshusisodiya commented Jan 26, 2025

fixes ENG-2491


Important

Fixes and enhances handling of authentication schemes in Composio SDK, ensuring proper validation and error handling for missing or invalid auth modes.

  • Behavior:
    • Fix handling of auth_mode in add_integration() in add.py to ensure it is not None before processing.
    • Update get() in collections.py to set auth_mode from mode if available.
    • Raise ComposioSDKError in get_expected_params_for_user() and fetch_expected_integration_params() in toolset.py if auth_mode is None.
  • Models:
    • Add t.Optional to scheme_name, name, auth_mode, and mode in AppAuthScheme in collections.py.
  • Tests:
    • Add test_get_apps() in test_toolset.py to verify auth_mode is in AUTH_SCHEMES.
    • Add checks for auth_mode in test_toolset.py to ensure proper handling of auth schemes.

This description was created by Ellipsis for ec3e8a4. It will automatically update as commits are pushed.

Copy link

vercel bot commented Jan 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 28, 2025 1:49pm

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 7b1061b in 21 seconds

More details
  • Looked at 132 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 drafted comments based on config settings.
1. python/composio/cli/add.py:246
  • Draft comment:
    Ensure auth_mode is checked for None before calling lower() to avoid potential AttributeError. This is already done in the PR, but ensure consistency across the codebase.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR introduces a change where auth_mode is checked for None before calling lower(). This is a good practice to avoid potential AttributeError if auth_mode is None. However, the same check should be applied consistently across the codebase where auth_mode is used.
2. python/composio/client/collections.py:373
  • Draft comment:
    Ensure auth_scheme.mode is a valid AuthSchemeType before casting to avoid potential runtime errors.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR changes the AppAuthScheme class to use Optional for several fields, which is a good practice for fields that may not always have a value. However, the mode field is being cast to AuthSchemeType without checking if it is a valid value. This could lead to runtime errors if mode is not a valid AuthSchemeType.
3. python/composio/tools/toolset.py:1062
  • Draft comment:
    Ensure auth_scheme is checked for None before calling upper() to avoid potential AttributeError. This is already done in the PR, but ensure consistency across the codebase.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The PR introduces a change where auth_mode is checked for None before calling upper(). This is a good practice to avoid potential AttributeError if auth_mode is None. However, the same check should be applied consistently across the codebase where auth_mode is used.

Workflow ID: wflow_P1g94F501tQcPIzY


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Comment on lines 368 to 374
apps: t.Union[AppModel, t.List[AppModel]] = super().get(queries=queries)
for app in apps:
if app.auth_schemes is not None: # type: ignore
for auth_scheme in app.auth_schemes: # type: ignore
if auth_scheme.mode is not None:
auth_scheme.auth_mode = t.cast(AuthSchemeType, auth_scheme.mode)
return apps

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type casting apps to AppModel before iteration can raise TypeError since apps could be a single AppModel. Should check type and handle single model case.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
apps: t.Union[AppModel, t.List[AppModel]] = super().get(queries=queries)
for app in apps:
if app.auth_schemes is not None: # type: ignore
for auth_scheme in app.auth_schemes: # type: ignore
if auth_scheme.mode is not None:
auth_scheme.auth_mode = t.cast(AuthSchemeType, auth_scheme.mode)
return apps
apps: t.Union[AppModel, t.List[AppModel]] = super().get(queries=queries)
if isinstance(apps, AppModel):
if apps.auth_schemes is not None:
for auth_scheme in apps.auth_schemes:
if auth_scheme.mode is not None:
auth_scheme.auth_mode = t.cast(AuthSchemeType, auth_scheme.mode)
else:
for app in apps:
if app.auth_schemes is not None:
for auth_scheme in app.auth_schemes:
if auth_scheme.mode is not None:
auth_scheme.auth_mode = t.cast(AuthSchemeType, auth_scheme.mode)
return apps

Comment on lines 1094 to 1096
if scheme.auth_mode is not None:
if auth_scheme != scheme.auth_mode.upper():
continue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential NoneType error when accessing auth_mode - need to check if scheme itself is not None before accessing auth_mode

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if scheme.auth_mode is not None:
if auth_scheme != scheme.auth_mode.upper():
continue
if scheme is not None and scheme.auth_mode is not None:
if auth_scheme != scheme.auth_mode.upper():
continue

@@ -293,8 +293,10 @@ class AuthSchemeField(BaseModel):
class AppAuthScheme(BaseModel):
"""App authenticatio scheme."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the docstring: authenticatio should be authentication

@@ -1051,8 +1058,9 @@ def get_expected_params_for_user(
# without user inputs to create an integratuib, if yes then create
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the comment: integratuib should be integration

scheme_name: t.Optional[str] = None
name: t.Optional[str] = None
auth_mode: t.Optional[AuthSchemeType] = None
mode: t.Optional[str] = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a docstring to explain the purpose of the mode field and its relationship with auth_mode. This would help clarify why both fields exist and when each should be used.

) -> t.List[AppModel]:
apps = self.client.apps.get()
# added type ignore since method overload was not being referenced
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type ignore comment should explain why the method overload is not being referenced and what's the proper way to fix it. This would help future maintainers understand if this is a temporary workaround or a permanent solution.

@shreysingla11
Copy link
Collaborator

Code Review Summary

The changes look good overall, with improvements to authentication scheme handling and type safety. Here's a breakdown:

Positives:

  • ✅ Improved type safety with proper null checks and type casting
  • ✅ Made authentication scheme fields optional, providing more flexibility
  • ✅ Added support for local app inclusion and additional fields in queries
  • ✅ Better error handling for auth scheme validation

Areas for Improvement:

  • 📝 Fixed typos in comments and docstrings
  • 📝 Need better documentation for the relationship between mode and auth_mode fields
  • 📝 Type ignore comments should include more context about the underlying issue

The code changes are well-structured and improve the robustness of the authentication handling. The suggestions are mostly about documentation and clarity rather than functional issues.

Rating: 8/10 - Solid improvements with minor documentation needs.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested. Incremental review on 277eae9 in 36 seconds

More details
  • Looked at 30 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_Bt62BKfJgA36Xx0H


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@@ -67,6 +68,17 @@ def test_uninitialize_app() -> None:
ComposioToolSet().get_action_schemas(actions=[Action.ATTIO_UPDATE_A_LIST])


def test_get_apps() -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle the case where no app with no_auth set to False is found to avoid potential UnboundLocalError.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on 8524a9e in 10 seconds

More details
  • Looked at 12 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. python/tests/test_tools/test_toolset.py:81
  • Draft comment:
    Unnecessary blank line. Consider removing it to maintain code consistency.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The PR adds an unnecessary blank line which does not contribute to code readability or functionality.

Workflow ID: wflow_yOegUl0xHqvJDmk3


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Incremental review on ec3e8a4 in 35 seconds

More details
  • Looked at 92 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. python/composio/tools/toolset.py:870
  • Draft comment:
    The include_local parameter is removed from the method signature but is still used in the method logic. Consider either removing its usage from the method or re-adding it to the method signature.
  • Reason this comment was not posted:
    Comment looked like it was already resolved.

Workflow ID: wflow_cNrm9lqTYT4Xz3LD


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

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