Skip to content

Conversation

@VeskeR
Copy link
Contributor

@VeskeR VeskeR commented Feb 14, 2025

This implements RSA9f and TK2b, where a capability JSON text can be provided for a Auth#createTokenRequest function and when passing TokenParams object

Resolves #579

Summary by CodeRabbit

  • New Features

    • Token requests and capability settings now accept both structured data and JSON string inputs for greater flexibility.
    • Added a test for constructing Capability objects from JSON strings, enhancing test coverage.
  • Refactor

    • Simplified the initialization process for capability configurations to reduce complexity.

@VeskeR VeskeR requested review from sacOO7 and ttypic February 14, 2025 15:05
@coderabbitai
Copy link

coderabbitai bot commented Feb 14, 2025

Warning

Rate limit exceeded

@VeskeR has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 37 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between e14e447 and 9213854.

📒 Files selected for processing (4)
  • ably/rest/auth.py (1 hunks)
  • ably/types/capability.py (2 hunks)
  • ably/types/tokendetails.py (1 hunks)
  • test/ably/rest/restcapability_test.py (1 hunks)

Walkthrough

The changes update method signatures and capability parsing. In the Auth class, the create_token_request method now accepts an Optional[dict | str] for token parameters. The Capability class constructor has been modified to use a capability parameter of type Optional[dict | str] with JSON parsing logic for string inputs. The TokenDetails class simplifies its initialization of the __capability attribute by directly instantiating a Capability object without extra error handling. Additionally, a new test checks that Capability objects can be correctly created from JSON strings.

Changes

File(s) Change Summary
ably/rest/auth.py, ably/types/capability.py Updated method signatures to accept `Optional[dict
ably/types/tokendetails.py Simplified __capability initialization by directly using Capability(capability or {}), removing previous JSON parsing error handling.
test/ably/rest/restcapability_test.py Added test_capability_from_string to verify that Capability objects are constructed correctly from both double-quoted and single-quoted JSON strings.

Poem

I'm a rabbit with a joyful hop,
Leaping through code that doesn't stop.
Dicts and strings now twirl in the light,
Crafting capabilities just right.
With each change, I dance and cheer—
Hoppy updates make my springtime clear!
🐇✨


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@github-actions github-actions bot temporarily deployed to staging/pull/586/features February 14, 2025 15:05 Inactive
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: 0

🧹 Nitpick comments (2)
ably/types/capability.py (1)

21-21: Fix whitespace in blank line.

Remove the whitespace characters from the blank line to resolve the linting warning.

-            
+
🧰 Tools
🪛 GitHub Actions: Linting check

[warning] 21-21: blank line contains whitespace

test/ably/rest/restcapability_test.py (1)

244-254: LGTM! Comprehensive test coverage for string capabilities.

The test verifies both double and single-quoted JSON string inputs, ensuring compatibility with dictionary-based capabilities.

Follow Python naming conventions by using snake_case for variable names:

-        capabilityFromStr = Capability('{"cansubscribe":["subscribe"]}')
-        capabilityFromStrSingleQuote = Capability('{\'cansubscribe\':[\'subscribe\']}')
-        capabilityFromDict = Capability({
+        capability_from_str = Capability('{"cansubscribe":["subscribe"]}')
+        capability_from_str_single_quote = Capability('{\'cansubscribe\':[\'subscribe\']}')
+        capability_from_dict = Capability({
🧰 Tools
🪛 GitHub Actions: Linting check

[warning] 246-246: variable in function should be lowercase


[warning] 247-247: variable in function should be lowercase


[warning] 249-249: variable in function should be lowercase

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8672cef and 00278d7.

📒 Files selected for processing (4)
  • ably/rest/auth.py (1 hunks)
  • ably/types/capability.py (2 hunks)
  • ably/types/tokendetails.py (1 hunks)
  • test/ably/rest/restcapability_test.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Linting check
test/ably/rest/restcapability_test.py

[warning] 246-246: variable in function should be lowercase


[warning] 247-247: variable in function should be lowercase


[warning] 249-249: variable in function should be lowercase

ably/types/capability.py

[warning] 21-21: blank line contains whitespace

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: check (3.13)
  • GitHub Check: check (3.12)
  • GitHub Check: check (3.11)
  • GitHub Check: check (3.10)
🔇 Additional comments (3)
ably/types/tokendetails.py (1)

23-23: LGTM! Code simplification improves maintainability.

The simplified initialization of __capability leverages the enhanced Capability constructor, reducing code complexity while maintaining functionality.

ably/types/capability.py (1)

11-18: LGTM! Robust implementation of string capability parsing.

The implementation correctly handles both double and single-quoted JSON strings, with proper error handling and type hints.

ably/rest/auth.py (1)

232-232: LGTM! Method signature updated to support string input.

The type annotation correctly reflects the RSA9f specification requirement to accept JSON text for token parameters while maintaining backward compatibility.

@VeskeR VeskeR force-pushed the 579/fix-capabilities-string branch from 00278d7 to a6faf1d Compare February 14, 2025 15:32
Copy link
Contributor

@ttypic ttypic left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot temporarily deployed to staging/pull/586/features February 14, 2025 15:33 Inactive
@VeskeR VeskeR force-pushed the 579/fix-capabilities-string branch from a6faf1d to c8af383 Compare February 14, 2025 15:37
@github-actions github-actions bot temporarily deployed to staging/pull/586/features February 14, 2025 15:38 Inactive
@VeskeR VeskeR force-pushed the 579/fix-capabilities-string branch from c8af383 to 2d004f3 Compare February 14, 2025 15:44
@github-actions github-actions bot temporarily deployed to staging/pull/586/features February 14, 2025 15:45 Inactive
@VeskeR VeskeR force-pushed the 579/fix-capabilities-string branch from 2d004f3 to e14e447 Compare February 14, 2025 16:08
@github-actions github-actions bot temporarily deployed to staging/pull/586/features February 14, 2025 16:09 Inactive
This implements RSA9f [1] and TK2b [2], where a capability JSON text can
be provided for a `Auth#createTokenRequest` function and when passing
`TokenParams` object

Resolves #579

[1] https://sdk.ably.com/builds/ably/specification/main/features/#RSA9f
[2] https://sdk.ably.com/builds/ably/specification/main/features/#TK2b
@VeskeR VeskeR force-pushed the 579/fix-capabilities-string branch from e14e447 to 9213854 Compare February 14, 2025 16:20
Base automatically changed from fix-invalid-credential-error-code to main February 14, 2025 16:21
@VeskeR VeskeR merged commit 696883e into main Feb 14, 2025
4 of 10 checks passed
@VeskeR VeskeR deleted the 579/fix-capabilities-string branch February 14, 2025 16:50
@coderabbitai coderabbitai bot mentioned this pull request Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ably_rest.auth.request_token capabilities call - unnecessary json.dumps() ?

3 participants