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

Add AWS Rekognition moderation Add-On methods #140

Merged
merged 1 commit into from
May 9, 2024

Conversation

vipulnsward
Copy link
Collaborator

@vipulnsward vipulnsward commented May 4, 2024

Description

Checklist

Summary by CodeRabbit

  • New Features
    • Introduced AWS Rekognition Moderation Add-On for detecting moderation labels in images.
  • Documentation
    • Updated README to reflect new AWS Rekognition Moderation capabilities.
  • Tests
    • Added various test cases and fixtures for new and existing functionalities, including AWS Rekognition and virus scanning.
  • Refactor
    • Implemented sensitive data filtering within VCR configurations for enhanced security.
  • Chores
    • Adjusted HTTP request details in VCR cassettes to align with current API specifications and security practices.

Copy link

coderabbitai bot commented May 4, 2024

Walkthrough

The recent changes focus on expanding the Uploadcare library with new capabilities, particularly around the AWS Rekognition Moderation Add-On. These updates introduce methods for detecting moderation labels in images and checking Add-On status, enhancing image processing and moderation features within the library.

Changes

File Path Change Summary
lib/uploadcare/rails/api/rest/addons_api.rb Expanded functionality for AWS Rekognition Moderation Add-On.
README.md, CHANGELOG.md Added features for AWS Rekognition Moderation, detailing new capabilities.
spec/fixtures/vcr_cassettes/... Updated VCR cassettes for testing AWS Rekognition and other add-ons.
spec/.../addons_api_spec.rb, ..._api_spec.rb Updated specs with tests for Addons API and other APIs, including AWS Rekognition.
spec/support/... Introduced stub keys and sensitive data filtering configurations.

🐇✨
In the realm of code, where lines dance and play,
A rabbit weaves updates, in its mischievous way.
With a leap and a bound, new features take flight,
Enhancing the library, in the soft glow of night.
Celebrate the changes, for the rabbit's touch is keen,
Uploadcare shines brighter, under its magical sheen! 🌟🐾


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

@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

before do
allow(Uploadcare.config).to receive_message_chain(:public_key).and_return('demopublickey')
allow(Uploadcare.config).to receive_message_chain(:secret_key).and_return('demosecretkey')
end
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This has been added due to changes from uploadcare/uploadcare-ruby#161

@vipulnsward vipulnsward merged commit 0659cc0 into main May 9, 2024
34 checks passed
@vipulnsward vipulnsward deleted the aws-rekognition-add-on branch May 9, 2024 20:20
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: 4

Out of diff range and nitpick comments (14)
CHANGELOG.md (5)

Line range hint 51-51: Consider using "Updated" instead of "Fixed" for consistency in describing non-bug changes.

- * Fixed an issue with the configuration
+ * Updated the configuration

Line range hint 98-98: Add periods after abbreviations like "etc." for grammatical correctness.

- * Field `content_info` that includes mime-type, image (dimensions, format, etc), video information (duration, format, bitrate, etc), audio information, etc
+ * Field `content_info` that includes mime-type, image (dimensions, format, etc.), video information (duration, format, bitrate, etc.), audio information, etc.

Line range hint 104-104: Remove redundancy in "API interface".

- - Add Uploadcare API interface:
+ - Add Uploadcare API:

Line range hint 186-186: Fix unpaired markdown link syntax.

- - Tests against Ruby 2.0 and 2.1 that [had reached their EOL](https://www.ruby-lang.org/en/downloads/branches/
+ - Tests against Ruby 2.0 and 2.1 that [had reached their EOL](https://www.ruby-lang.org/en/downloads/branches/)

Line range hint 84-160: Standardize list item markers to use asterisks for consistency.

- - For `Uploadcare::FileApi#get_file`
+ * For `Uploadcare::FileApi#get_file`
- - Field `content_info` that includes mime-type, image (dimensions, format, etc), video information (duration, format, bitrate, etc), audio information, etc
+ * Field `content_info` that includes mime-type, image (dimensions, format, etc.), video information (duration, format, bitrate, etc.), audio information, etc.
- - Field `metadata` that includes arbitrary metadata associated with a file
+ * Field `metadata` that includes arbitrary metadata associated with a file
README.md (9)

Line range hint 11-11: Consider removing the space before the exclamation mark in "Note:" for consistency with common English punctuation practices.


Line range hint 31-31: Replace "API interfaces" with "APIs" to avoid redundancy, as "I" in "API" already stands for "interface".

- * [Uploadcare API interfaces](#uploadcare-api-interfaces)
+ * [Uploadcare APIs](#uploadcare-api-interfaces)

Line range hint 91-91: Consider replacing "very important" with "crucial" to enhance the tone and avoid the overused phrase.

- :warning: `require: "dotenv/rails-now"` is very important!
+ :warning: `require: "dotenv/rails-now"` is crucial!

Line range hint 136-136: Add "the" before "Full list" to correct the grammatical structure of the sentence.

- Full list of available options is listed in the file itself.
+ The full list of available options is listed in the file itself.

Line range hint 212-212: Insert a comma after "For example" to improve the readability of the sentence.

- For example you have a database table like this and model `Post`:
+ For example, you have a database table like this and model `Post`:

Line range hint 289-289: Insert a comma after "caching" to correctly separate the clauses in the sentence.

- If you are facing issue, with multiple input elements being rendered due to turbolinks caching you can append this fix in the `app/javascript/application.js` to overcome this:
+ If you are facing issue, with multiple input elements being rendered due to turbolinks caching, you can append this fix in the `app/javascript/application.js` to overcome this:

Line range hint 309-309: Insert a comma after "Similarly" to correctly separate the introductory phrase from the main clause.

- Similarly if you are using [Hotwire](https://hotwired.dev/) then use can you use below code:
+ Similarly, if you are using [Hotwire](https://hotwired.dev/) then use can you use below code:

Line range hint 333-333: Replace "a" with "an" before "Uploadcare" as the following word starts with a vowel sound.

- this attribute is getting wrapped with a Uploadcare object.
+ this attribute is getting wrapped with an Uploadcare object.

Line range hint 507-507: Replace "an URL" with "a URL" as the pronunciation of "URL" starts with a consonant sound.

- file uploading and uploading files from an URL (depending on the type of first argument - can be either String (i.e. URL) or File).
+ file uploading and uploading files from a URL (depending on the type of first argument - can be either String (i.e. URL) or File).
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between fdb806b and a564c59.
Files selected for processing (17)
  • CHANGELOG.md (1 hunks)
  • README.md (3 hunks)
  • lib/uploadcare/rails/api/rest/addons_api.rb (1 hunks)
  • spec/fixtures/vcr_cassettes/group_api_get_group.yml (4 hunks)
  • spec/fixtures/vcr_cassettes/remove_bg.yml (1 hunks)
  • spec/fixtures/vcr_cassettes/remove_bg_status.yml (1 hunks)
  • spec/fixtures/vcr_cassettes/uc_clamav_virus_scan.yml (1 hunks)
  • spec/fixtures/vcr_cassettes/uc_clamav_virus_scan_status.yml (1 hunks)
  • spec/fixtures/vcr_cassettes/ws_rekognition_detect_labels.yml (1 hunks)
  • spec/fixtures/vcr_cassettes/ws_rekognition_detect_labels_status.yml (1 hunks)
  • spec/fixtures/vcr_cassettes/ws_rekognition_detect_moderation_labels.yml (1 hunks)
  • spec/fixtures/vcr_cassettes/ws_rekognition_detect_moderation_labels_status.yml (1 hunks)
  • spec/spec_helper.rb (2 hunks)
  • spec/support/stub_config_keys.rb (1 hunks)
  • spec/support/vcr.rb (1 hunks)
  • spec/uploadcare/rails/api/rest/addons_api_spec.rb (1 hunks)
  • spec/uploadcare/rails/api/rest/group_api_spec.rb (1 hunks)
Files skipped from review due to trivial changes (1)
  • spec/support/stub_config_keys.rb
Files skipped from review as they are similar to previous changes (13)
  • lib/uploadcare/rails/api/rest/addons_api.rb
  • spec/fixtures/vcr_cassettes/remove_bg.yml
  • spec/fixtures/vcr_cassettes/remove_bg_status.yml
  • spec/fixtures/vcr_cassettes/uc_clamav_virus_scan.yml
  • spec/fixtures/vcr_cassettes/uc_clamav_virus_scan_status.yml
  • spec/fixtures/vcr_cassettes/ws_rekognition_detect_labels.yml
  • spec/fixtures/vcr_cassettes/ws_rekognition_detect_labels_status.yml
  • spec/fixtures/vcr_cassettes/ws_rekognition_detect_moderation_labels.yml
  • spec/fixtures/vcr_cassettes/ws_rekognition_detect_moderation_labels_status.yml
  • spec/spec_helper.rb
  • spec/support/vcr.rb
  • spec/uploadcare/rails/api/rest/addons_api_spec.rb
  • spec/uploadcare/rails/api/rest/group_api_spec.rb
Additional Context Used
LanguageTool (29)
CHANGELOG.md (8)

Near line 9: Possible typo: you repeated a word
Context: .../spec/v2.0.0.html). ## Unreleased ### Added * Added Addons api for `AWS Rekognition Moderat...


Near line 51: Consider using a different verb for a more formal wording.
Context: ... ## 3.3.2 — 2023-03-26 ### Changed * Fixed an issue with the configuration * Updat...


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


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


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


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


Near line 125: This phrase is redundant (‘I’ stands for ‘interface’). Use simply “API”.
Context: ...with 1.x.* ### Added - Add Uploadcare API interface: - Uploadcare::FileApi - Uploadcare...


Near line 186: Unpaired symbol: ‘]’ seems to be missing
Context: ...d - Tests against Ruby 2.0 and 2.1 that [had reached their EOL](https://www.ruby-...

README.md (21)

Near line 11: Loose punctuation mark.
Context: ...al purpose wrapper for Uploadcare API) ❗ *Note: the gem u...


Near line 31: This phrase is redundant (‘I’ stands for ‘interfaces’). Use simply “APIs”.
Context: ...(#image-transformation) * Uploadcare API interfaces * [Upl...


Near line 91: As an alternative to the over-used intensifier ‘very’, consider replacing this phrase.
Context: ...rning: require: "dotenv/rails-now" is very important! Run the config generator command to g...


Near line 136: Possible missing article found.
Context: ...s storing/caching, deleting files, etc. Full list of available options is listed in ...


Near line 212: After the expression ‘for example’ a comma is usually used.
Context: ...le or group to the model attribute. For example you have a database table like this and...


Near line 289: Possible missing comma found.
Context: ...ements being rendered due to turbolinks caching you can append this fix in the `app/jav...


Near line 309: A comma may be missing after the conjunctive/linking adverb ‘Similarly’.
Context: ... widget.remove(); }); }); ``` Similarly if you are using [Hotwire](https://hotw...


Near line 333: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ... this attribute is getting wrapped with a Uploadcare object. This feature adds so...


Near line 353: Possible missing article found.
Context: ...picture` is an Uploadcare::Rails::File. Following methods are supported: ```ruby # Store...


Near line 397: It seems that a comma is missing.
Context: ...ar to the File but have some differences though. ```ruby # app/models/post.rb class Po...


Near line 411: Possible missing comma found.
Context: ...8-b7a6-43ff-a35f-2ebef935dc1b~1/") ``` Now the post.attachments is an Uploadcare...


Near line 484: This phrase is redundant (‘I’ stands for ‘interfaces’). Use simply “APIs”.
Context: ...ransformations/image/). ### Uploadcare API interfaces Uploadcare provides [APIs](https://upl...


Near line 490: Unpaired symbol: ‘[’ seems to be missing
Context: ...n RailsApp. ### Upload API [Upload Api](https://uploadcare.com/api-refs/upload-...


Near line 492: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...ods to upload files in many ways. #### Upload a single file ```ruby # Load a file fi...


Near line 507: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...file uploading and uploading files from an URL (depending on the type of first arg...


Near line 763: Did you mean “managing”? Or maybe you should add a pronoun? In active voice, ‘allow’ + ‘to’ takes an object, usually a pronoun.
Context: ...`` ### Webhook API WebhookApi allows to manage Uploadcare webhooks. #### Get all webh...


Near line 785: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...ate a new webhook This method requires an URL that is triggered by an event, for ...


Near line 841: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...onvert a document This method requires an UUID of a previously uploaded to Upload...


Near line 879: Use “a” instead of ‘an’ if the following word doesn’t start with a vowel sound, e.g. ‘a sentence’, ‘a university’.
Context: ...conversion method, this method requires an UUID of a previously uploaded to Upload...


Near line 879: A comma may be missing after the conjunctive/linking adverb ‘Also’.
Context: ...previously uploaded to Uploadcare file. Also you have several options to control the...


Near line 926: Possible missing article found.
Context: ...ed file. As an example, you could store unique file identifier from your system. Metad...

Comment on lines +982 to +998
#### Execute AWS Rekognition Moderation Add-On for a given target to detect moderation labels in an image.
```
Note: Detected labels are stored in the file's appdata.
```

```ruby
Uploadcare::AddonsApi.rekognition_detect_moderation_labels('f757ea10-8b1a-4361-9a7c-56bfa5d45176')
# => {"request_id"=>"dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e"}
```

# Check the status of an AWS Rekognition Moderation Add-On execution request that had been started using the Execute Add-On operation.

```ruby
Uploadcare::AddonsApi.rekognition_detect_moderation_labels_status('dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e')
# => {"status"=>"done"}
```

Copy link

Choose a reason for hiding this comment

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

Ensure there is a blank line after the heading for better readability and markdown formatting.

#### Execute AWS Rekognition Moderation Add-On for a given target to detect moderation labels in an image.

+ 

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.

Suggested change
#### Execute AWS Rekognition Moderation Add-On for a given target to detect moderation labels in an image.
```
Note: Detected labels are stored in the file's appdata.
```
```ruby
Uploadcare::AddonsApi.rekognition_detect_moderation_labels('f757ea10-8b1a-4361-9a7c-56bfa5d45176')
# => {"request_id"=>"dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e"}
```
# Check the status of an AWS Rekognition Moderation Add-On execution request that had been started using the Execute Add-On operation.
```ruby
Uploadcare::AddonsApi.rekognition_detect_moderation_labels_status('dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e')
# => {"status"=>"done"}
```
#### Execute AWS Rekognition Moderation Add-On for a given target to detect moderation labels in an image.

Note: Detected labels are stored in the file's appdata.


```ruby
Uploadcare::AddonsApi.rekognition_detect_moderation_labels('f757ea10-8b1a-4361-9a7c-56bfa5d45176')
#   => {"request_id"=>"dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e"}

Check the status of an AWS Rekognition Moderation Add-On execution request that had been started using the Execute Add-On operation.

Uploadcare::AddonsApi.rekognition_detect_moderation_labels_status('dfeaf81c-5c0d-49d5-8ed4-ac09bac7998e')
#   => {"status"=>"done"}

</details>
<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

@@ -2,13 +2,13 @@
http_interactions:
- request:
method: get
uri: https://upload.uploadcare.com/group/info/?group_id=6053b054-b8d4-4f57-992d-94b8f1d6ba65~2&pub_key=demopublickey
uri: https://upload.uploadcare.com/group/info/?group_id=6053b054-b8d4-4f57-992d-94b8f1d6ba65~2&pub_key=<uploadcare_private_key>
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Sensitive data in the URI within the VCR cassette for the group_api_get_group endpoint is not properly masked. The placeholder <uploadcare_private_key> appears in the URI and in the user-agent string, which could potentially expose sensitive information if not handled correctly in a real environment.

  • spec/fixtures/vcr_cassettes/group_api_get_group.yml:
    • Line containing the URI with the placeholder.
    • Line containing the user-agent string with the placeholder.
Analysis chain

Ensure sensitive data is properly masked in the URI.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that sensitive data is masked in all URIs within VCR cassettes.

# Test: Search for unmasked sensitive data. Expect: No occurrences of unmasked sensitive data.
rg --type yaml --glob '*vcr_cassettes*.yml' '<uploadcare_private_key>'

Length of output: 221



Script:

#!/bin/bash
# Description: List VCR cassette files to confirm their presence and file type.

# List all files in directories containing 'vcr_cassettes' and display their file types.
find . -type f -path '*/vcr_cassettes/*' -exec file {} \;

Length of output: 1422



Script:

#!/bin/bash
# Description: List VCR cassette files to confirm their presence.

# List all files in directories containing 'vcr_cassettes' and display their paths.
find . -type f -path '*/vcr_cassettes/*'

Length of output: 2114



Script:

#!/bin/bash
# Description: Verify that sensitive data is masked in all URIs within VCR cassettes.

# Test: Search for unmasked sensitive data in the confirmed YAML files. Expect: No occurrences of unmasked sensitive data.
rg --type yaml --glob 'spec/fixtures/vcr_cassettes/*.yml' '<uploadcare_private_key>'

Length of output: 389

string: ''
headers:
User-Agent:
- UploadcareRuby/4.0.0/5d5bb5639e3f2df33674 (Ruby/3.0.0)
- UploadcareRuby/4.4.1/<uploadcare_private_key> (Ruby/3.3.0)
Copy link

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Sensitive data appears unmasked in the User-Agent headers within VCR cassettes. Immediate action is required to address this issue.

  • spec/fixtures/vcr_cassettes/group_api_get_group.yml contains unmasked sensitive data in multiple lines.
Analysis chain

Ensure sensitive data is properly masked in the User-Agent header.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that sensitive data is masked in all User-Agent headers within VCR cassettes.

# Test: Search for unmasked sensitive data. Expect: No occurrences of unmasked sensitive data.
rg --type yaml --glob '*vcr_cassettes*.yml' '<uploadcare_private_key>'

Length of output: 221



Script:

#!/bin/bash
# Description: Re-verify that sensitive data is masked in all User-Agent headers within VCR cassettes by adjusting search parameters.

# Step 1: Check if there are any YAML files in the 'vcr_cassettes' directory.
echo "Checking for YAML files in 'vcr_cassettes' directory:"
fd --type f --extension yml 'vcr_cassettes'

# Step 2: If YAML files are found, re-run the search for unmasked sensitive data without the restrictive glob pattern.
echo "Searching for unmasked sensitive data in VCR cassettes:"
rg --type yaml '<uploadcare_private_key>' $(fd --type f --extension yml 'vcr_cassettes')

Length of output: 679

@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based now on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Added
Copy link

Choose a reason for hiding this comment

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

Remove repeated word "Added" for clarity.

- * Added Addons api for `AWS Rekognition Moderation` Add-On.
+ * Addons api for `AWS Rekognition Moderation` Add-On.

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.

Suggested change
### Added
###

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.

None yet

1 participant