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 Uploadcare::File.remote_copy raising response errors #171

Merged
merged 3 commits into from
May 28, 2024

Conversation

vipulnsward
Copy link
Collaborator

@vipulnsward vipulnsward commented May 28, 2024

Description

  • Fix Uploadcare::File.remote_copy raising response errors

Checklist

Summary by CodeRabbit

  • Bug Fixes

    • Resolved an issue in the Uploadcare::File.remote_copy method to prevent errors related to input parameter type.
  • Enhancements

    • Improved variable naming in REST API examples for better clarity.
    • Updated the remote_copy method to return a string instead of a File entity instance.
  • Security

    • Introduced filtering for sensitive data (<uploadcare_public_key> and <uploadcare_secret_key>) in test configurations.
  • Testing

    • Added new test cases for remote file copying and error handling for invalid storage in the project.
    • Included VCR cassette for HTTP interactions with the Uploadcare API.

Copy link
Contributor

coderabbitai bot commented May 28, 2024

Walkthrough

The recent updates focus on improving the Uploadcare::File.remote_copy method by fixing an input parameter type error and altering its return type to a string. Additionally, variable names in the REST API example script were clarified, and HTTP interactions for remote file copying were captured. Other changes include modifying the form_data_for method in the multipart upload client and enhancing VCR configuration to filter sensitive data.

Changes

File Path Change Summary
CHANGELOG.md Documented the fix for Uploadcare::File.remote_copy method and other changes.
api_examples/rest_api/post_files_remote_copy.rb Renamed variables for clarity in the remote file copy operation.
lib/uploadcare/entity/file.rb Modified remote_copy method to return a string directly.
lib/uploadcare/client/multipart_upload_client.rb Removed file parameter in form_data_for method's super call.
spec/fixtures/vcr_cassettes/rest_file_remote_copy.yml Added new VCR cassette capturing HTTP interactions for remote file copying.
spec/support/vcr.rb Introduced sensitive data filtering for public and secret keys in VCR configuration.
spec/uploadcare/entity/file_spec.rb Updated tests to reflect changes in copying files to remote storage and added a test for storage errors.

Poem

In the land of code, a change was made,
To fix the paths where errors played.
Remote copies now return with grace,
Variables renamed, a clearer space.
Sensitive keys hidden from view,
Uploadcare's flow, refreshed and new.
🐇✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 full the 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
Contributor

@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: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e0e6772 and dd2fded.
Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • api_examples/rest_api/post_files_remote_copy.rb (1 hunks)
  • lib/uploadcare/entity/file.rb (1 hunks)
  • spec/fixtures/vcr_cassettes/rest_file_remote_copy.yml (1 hunks)
  • spec/support/vcr.rb (1 hunks)
  • spec/uploadcare/entity/file_spec.rb (1 hunks)
Files skipped from review due to trivial changes (3)
  • api_examples/rest_api/post_files_remote_copy.rb
  • lib/uploadcare/entity/file.rb
  • spec/fixtures/vcr_cassettes/rest_file_remote_copy.yml
Additional Context Used
LanguageTool (7)
CHANGELOG.md (7)

Near line 5: Possible typo: you repeated a word
Context: # Changelog ## Unreleased ### Fixed * Fixed that Uploadcare::File.remote_copy met...
Rule ID: ENGLISH_WORD_REPEAT_RULE


Near line 12: Possible typo: you repeated a word
Context: ...tConverter. ## 4.4.1 — 2024-04-27 ### Added * Added AWS Rekognition Moderation` Add-On. * ...
Rule ID: ENGLISH_WORD_REPEAT_RULE


Near line 123: In American English, abbreviations like “etc.” require a period.
Context: ...s mime-type, image (dimensions, format, etc), video information (duration, format, ...
Rule ID: ETC_PERIOD


Near line 123: In American English, abbreviations like “etc.” require a period.
Context: ...information (duration, format, bitrate, etc), audio information, etc - Field `met...
Rule ID: ETC_PERIOD


Near line 123: In American English, abbreviations like “etc.” require a period.
Context: ...rmat, bitrate, etc), audio information, etc - Field metadata that includes arbi...
Rule ID: ETC_PERIOD


Near line 129: This phrase is redundant (‘I’ stands for ‘interface’). Use simply “API”.
Context: ...plications ### Added - Add Uploadcare API interface: - Uploadcare::FileMetadata -...
Rule ID: ACRONYM_TAUTOLOGY


Near line 155: Possible typo: you repeated a word
Context: ...tureVerifier ## 3.1.1 — 2021-10-13 - FixedUploadcare::File#store- FixedUploadcare::File#delete` ## 3.1.0 — 2...
Rule ID: ENGLISH_WORD_REPEAT_RULE

Markdownlint (73)
CHANGELOG.md (73)

82: Expected: asterisk; Actual: dash
Unordered list style


83: Expected: asterisk; Actual: dash
Unordered list style


91: Expected: asterisk; Actual: dash
Unordered list style


92: Expected: asterisk; Actual: dash
Unordered list style


96: Expected: asterisk; Actual: dash
Unordered list style


109: Expected: asterisk; Actual: dash
Unordered list style


110: Expected: asterisk; Actual: dash
Unordered list style


111: Expected: asterisk; Actual: dash
Unordered list style


112: Expected: asterisk; Actual: dash
Unordered list style


113: Expected: asterisk; Actual: dash
Unordered list style


114: Expected: asterisk; Actual: dash
Unordered list style


115: Expected: asterisk; Actual: dash
Unordered list style


116: Expected: asterisk; Actual: dash
Unordered list style


117: Expected: asterisk; Actual: dash
Unordered list style


118: Expected: asterisk; Actual: dash
Unordered list style


122: Expected: asterisk; Actual: dash
Unordered list style


123: Expected: asterisk; Actual: dash
Unordered list style


124: Expected: asterisk; Actual: dash
Unordered list style


125: Expected: asterisk; Actual: dash
Unordered list style


129: Expected: asterisk; Actual: dash
Unordered list style


130: Expected: asterisk; Actual: dash
Unordered list style


131: Expected: asterisk; Actual: dash
Unordered list style


132: Expected: asterisk; Actual: dash
Unordered list style


133: Expected: asterisk; Actual: dash
Unordered list style


137: Expected: asterisk; Actual: dash
Unordered list style


141: Expected: asterisk; Actual: dash
Unordered list style


142: Expected: asterisk; Actual: dash
Unordered list style


146: Expected: asterisk; Actual: dash
Unordered list style


150: Expected: asterisk; Actual: dash
Unordered list style


151: Expected: asterisk; Actual: dash
Unordered list style


155: Expected: asterisk; Actual: dash
Unordered list style


156: Expected: asterisk; Actual: dash
Unordered list style


160: Expected: asterisk; Actual: dash
Unordered list style


161: Expected: asterisk; Actual: dash
Unordered list style


162: Expected: asterisk; Actual: dash
Unordered list style


166: Expected: asterisk; Actual: dash
Unordered list style


167: Expected: asterisk; Actual: dash
Unordered list style


171: Expected: asterisk; Actual: dash
Unordered list style


172: Expected: asterisk; Actual: dash
Unordered list style


173: Expected: asterisk; Actual: dash
Unordered list style


177: Expected: asterisk; Actual: dash
Unordered list style


181: Expected: asterisk; Actual: dash
Unordered list style


182: Expected: asterisk; Actual: dash
Unordered list style


186: Expected: asterisk; Actual: dash
Unordered list style


187: Expected: asterisk; Actual: dash
Unordered list style


188: Expected: asterisk; Actual: dash
Unordered list style


189: Expected: asterisk; Actual: dash
Unordered list style


190: Expected: asterisk; Actual: dash
Unordered list style


196: Expected: asterisk; Actual: dash
Unordered list style


200: Expected: asterisk; Actual: dash
Unordered list style


201: Expected: asterisk; Actual: dash
Unordered list style


202: Expected: asterisk; Actual: dash
Unordered list style


203: Expected: asterisk; Actual: dash
Unordered list style


204: Expected: asterisk; Actual: dash
Unordered list style


130: Expected: 2; Actual: 4
Unordered list indentation


131: Expected: 2; Actual: 4
Unordered list indentation


7: Expected: 0 or 2; Actual: 1
Trailing spaces


41: Expected: 1; Actual: 2
Multiple consecutive blank lines


54: Expected: 1; Actual: 2
Multiple consecutive blank lines


61: Expected: 1; Actual: 2
Multiple consecutive blank lines


5: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


8: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


10: Expected: 1; Actual: 0; Above
Headings should be surrounded by blank lines


12: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


16: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


38: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


6: null
Lists should be surrounded by blank lines


9: null
Lists should be surrounded by blank lines


9: null
Lists should be surrounded by blank lines


13: null
Lists should be surrounded by blank lines


17: null
Lists should be surrounded by blank lines


39: null
Lists should be surrounded by blank lines


101: null
Lists should be surrounded by blank lines

Additional comments not posted (4)
spec/support/vcr.rb (1)

9-10: Sensitive data filtering added for security enhancement.

This is a crucial update for maintaining security by ensuring that sensitive keys are not exposed in VCR cassettes. Good job on implementing dynamic key retrieval.

spec/uploadcare/entity/file_spec.rb (2)

47-55: Updated tests reflect new behavior of remote_copy.

The tests are well-updated to check the new behavior of the remote_copy method returning a URL string. It's good to see thorough testing, including error handling when the specified storage is unavailable.


56-56: Error handling test for unavailable storage.

This test ensures robust error handling by checking for a specific error message when the storage is unavailable. It's crucial for maintaining reliability in production environments.

CHANGELOG.md (1)

5-7: Changelog updated to reflect recent fixes.

The changelog entry correctly documents the fix made to the remote_copy method. It's important to keep this document up-to-date for users and developers.

CHANGELOG.md Outdated Show resolved Hide resolved
vipulnsward and others added 2 commits May 29, 2024 00:41
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@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

Outside diff range and nitpick comments (1)
lib/uploadcare/client/multipart_upload_client.rb (1)

[!TIP]
Codebase Verification

The form_data_for method in lib/uploadcare/client/upload_client.rb expects a file parameter, which conflicts with the refactored method in lib/uploadcare/client/multipart_upload_client.rb that no longer provides this parameter. This discrepancy needs to be addressed to ensure compatibility.

  • lib/uploadcare/client/upload_client.rb: form_data_for(file)
Analysis chain

Line range hint 50-56: The refactoring of form_data_for simplifies parameter handling and enhances clarity by utilizing inheritance.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the superclass method `form_data_for` is compatible with the changes.

# Test: Search for the superclass method implementation. Expect: It should handle the absence of the `file` parameter gracefully.
ast-grep --lang ruby --pattern $'def form_data_for($_) { $$$ }' lib/uploadcare/client/upload_client.rb

Length of output: 448



Script:

#!/bin/bash
# Description: Search for the superclass method `form_data_for` in the entire codebase to verify its implementation.

# Test: Search for the method definition in the entire codebase.
ast-grep --lang ruby --pattern 'def form_data_for($_) { $$$ }'

Length of output: 409



Script:

#!/bin/bash
# Description: Search for the superclass method `form_data_for` in the entire codebase to verify its implementation.

# Test: Search for the method definition in the entire codebase.
rg 'def form_data_for'

Length of output: 172



Script:

#!/bin/bash
# Description: Extract and review the `form_data_for` method in `lib/uploadcare/client/upload_client.rb` to verify its implementation.

# Test: Extract the method definition and its body.
rg -A 10 'def form_data_for' lib/uploadcare/client/upload_client.rb

Length of output: 502

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between dd2fded and dc000d6.
Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • lib/uploadcare/client/multipart_upload_client.rb (1 hunks)
Additional Context Used
LanguageTool (10)
CHANGELOG.md (10)

Near line 5: Possible typo: you repeated a word
Context: # Changelog ## Unreleased ### Fixed * Fixed the Uploadcare::File.remote_copy meth...
Rule ID: ENGLISH_WORD_REPEAT_RULE


Near line 6: Possible missing comma found.
Context: ...ixed the Uploadcare::File.remote_copy method which raised an `ApiStruct::EntityError...
Rule ID: AI_HYDRA_LEO_MISSING_COMMA


Near line 6: Possible missing comma found.
Context: ...ruct::EntityError: {url} must be Hash. Now returns a string instead of a File` en...
Rule ID: AI_HYDRA_LEO_MISSING_COMMA


Near line 11: Possible typo: you repeated a word
Context: ...tConverter. ## 4.4.1 — 2024-04-27 ### Added * Added AWS Rekognition Moderation` Add-On. * ...
Rule ID: ENGLISH_WORD_REPEAT_RULE


Near line 82: Possible missing preposition found.
Context: ...Changed - Update the gem description - Allow ENV keys to be configured after the gem...
Rule ID: AI_HYDRA_LEO_MISSING_TO


Near line 122: In American English, abbreviations like “etc.” require a period.
Context: ...s mime-type, image (dimensions, format, etc), video information (duration, format, ...
Rule ID: ETC_PERIOD


Near line 122: In American English, abbreviations like “etc.” require a period.
Context: ...information (duration, format, bitrate, etc), audio information, etc - Field `met...
Rule ID: ETC_PERIOD


Near line 122: In American English, abbreviations like “etc.” require a period.
Context: ...rmat, bitrate, etc), audio information, etc - Field metadata that includes arbi...
Rule ID: ETC_PERIOD


Near line 128: This phrase is redundant (‘I’ stands for ‘interface’). Use simply “API”.
Context: ...plications ### Added - Add Uploadcare API interface: - Uploadcare::FileMetadata -...
Rule ID: ACRONYM_TAUTOLOGY


Near line 154: Possible typo: you repeated a word
Context: ...tureVerifier ## 3.1.1 — 2021-10-13 - FixedUploadcare::File#store- FixedUploadcare::File#delete` ## 3.1.0 — 2...
Rule ID: ENGLISH_WORD_REPEAT_RULE

Markdownlint (74)
CHANGELOG.md (74)

81: Expected: asterisk; Actual: dash
Unordered list style


82: Expected: asterisk; Actual: dash
Unordered list style


90: Expected: asterisk; Actual: dash
Unordered list style


91: Expected: asterisk; Actual: dash
Unordered list style


95: Expected: asterisk; Actual: dash
Unordered list style


108: Expected: asterisk; Actual: dash
Unordered list style


109: Expected: asterisk; Actual: dash
Unordered list style


110: Expected: asterisk; Actual: dash
Unordered list style


111: Expected: asterisk; Actual: dash
Unordered list style


112: Expected: asterisk; Actual: dash
Unordered list style


113: Expected: asterisk; Actual: dash
Unordered list style


114: Expected: asterisk; Actual: dash
Unordered list style


115: Expected: asterisk; Actual: dash
Unordered list style


116: Expected: asterisk; Actual: dash
Unordered list style


117: Expected: asterisk; Actual: dash
Unordered list style


121: Expected: asterisk; Actual: dash
Unordered list style


122: Expected: asterisk; Actual: dash
Unordered list style


123: Expected: asterisk; Actual: dash
Unordered list style


124: Expected: asterisk; Actual: dash
Unordered list style


128: Expected: asterisk; Actual: dash
Unordered list style


129: Expected: asterisk; Actual: dash
Unordered list style


130: Expected: asterisk; Actual: dash
Unordered list style


131: Expected: asterisk; Actual: dash
Unordered list style


132: Expected: asterisk; Actual: dash
Unordered list style


136: Expected: asterisk; Actual: dash
Unordered list style


140: Expected: asterisk; Actual: dash
Unordered list style


141: Expected: asterisk; Actual: dash
Unordered list style


145: Expected: asterisk; Actual: dash
Unordered list style


149: Expected: asterisk; Actual: dash
Unordered list style


150: Expected: asterisk; Actual: dash
Unordered list style


154: Expected: asterisk; Actual: dash
Unordered list style


155: Expected: asterisk; Actual: dash
Unordered list style


159: Expected: asterisk; Actual: dash
Unordered list style


160: Expected: asterisk; Actual: dash
Unordered list style


161: Expected: asterisk; Actual: dash
Unordered list style


165: Expected: asterisk; Actual: dash
Unordered list style


166: Expected: asterisk; Actual: dash
Unordered list style


170: Expected: asterisk; Actual: dash
Unordered list style


171: Expected: asterisk; Actual: dash
Unordered list style


172: Expected: asterisk; Actual: dash
Unordered list style


176: Expected: asterisk; Actual: dash
Unordered list style


180: Expected: asterisk; Actual: dash
Unordered list style


181: Expected: asterisk; Actual: dash
Unordered list style


185: Expected: asterisk; Actual: dash
Unordered list style


186: Expected: asterisk; Actual: dash
Unordered list style


187: Expected: asterisk; Actual: dash
Unordered list style


188: Expected: asterisk; Actual: dash
Unordered list style


189: Expected: asterisk; Actual: dash
Unordered list style


195: Expected: asterisk; Actual: dash
Unordered list style


199: Expected: asterisk; Actual: dash
Unordered list style


200: Expected: asterisk; Actual: dash
Unordered list style


201: Expected: asterisk; Actual: dash
Unordered list style


202: Expected: asterisk; Actual: dash
Unordered list style


203: Expected: asterisk; Actual: dash
Unordered list style


129: Expected: 2; Actual: 4
Unordered list indentation


130: Expected: 2; Actual: 4
Unordered list indentation


40: Expected: 1; Actual: 2
Multiple consecutive blank lines


53: Expected: 1; Actual: 2
Multiple consecutive blank lines


60: Expected: 1; Actual: 2
Multiple consecutive blank lines


5: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


7: Expected: 1; Actual: 0; Above
Headings should be surrounded by blank lines


7: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


9: Expected: 1; Actual: 0; Above
Headings should be surrounded by blank lines


11: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


15: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


37: Expected: 1; Actual: 0; Below
Headings should be surrounded by blank lines


6: null
Lists should be surrounded by blank lines


6: null
Lists should be surrounded by blank lines


8: null
Lists should be surrounded by blank lines


8: null
Lists should be surrounded by blank lines


12: null
Lists should be surrounded by blank lines


16: null
Lists should be surrounded by blank lines


38: null
Lists should be surrounded by blank lines


100: null
Lists should be surrounded by blank lines

Additional comments not posted (5)
lib/uploadcare/client/multipart_upload_client.rb (4)

Line range hint 12-18: The upload method implementation looks solid and well-structured.


Line range hint 24-32: The upload_start method is correctly implemented to initiate multipart uploads.


Line range hint 34-42: The upload_complete method effectively finalizes the multipart upload process.


Line range hint 58-62: The post method correctly handles API requests with throttling, ensuring robustness in network interactions.

CHANGELOG.md (1)

6-6: The changelog entry clearly documents the fix to Uploadcare::File.remote_copy. Consider incorporating the previous review's suggestion for enhanced clarity.

- * Fixed the `Uploadcare::File.remote_copy` method which raised an `ApiStruct::EntityError: {url} must be Hash`. Now returns a string instead of a `File` entity instance.
+ * Fixed the `Uploadcare::File.remote_copy` method which raised an `ApiStruct::EntityError: {url} must be Hash`. Now returns a string instead of a `File` entity instance.

@vipulnsward vipulnsward merged commit 61f3ce3 into main May 28, 2024
10 checks passed
@vipulnsward vipulnsward deleted the fix-remote-copy branch May 28, 2024 19:19
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