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: trim db urls and remove special characters during backup restore #36201

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

pratapaprasanna
Copy link
Contributor

@pratapaprasanna pratapaprasanna commented Sep 9, 2024

fixes: #36176

Warning

Tests have not run on the HEAD dd01ffd yet


Fri, 13 Sep 2024 10:38:44 UTC

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of database URLs by removing leading and trailing whitespace, enhancing robustness and preventing potential issues.

@pratapaprasanna pratapaprasanna added the DevOps Pod Issues related to devops label Sep 9, 2024
@pratapaprasanna pratapaprasanna self-assigned this Sep 9, 2024
Copy link
Contributor

coderabbitai bot commented Sep 9, 2024

Walkthrough

The changes in this pull request focus on improving the handling of database URLs in the getDburl function within utils.js. The modifications ensure that any leading or trailing whitespace is removed from the database URL values extracted from the environment configuration. This enhancement addresses issues related to improperly formatted database URLs, which can lead to failures in operations such as backups.

Changes

File Change Summary
deploy/docker/fs/opt/appsmith/utils/bin/utils.js Added trim() method to clean whitespace from database URL values in getDburl function.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant DB

    User->>App: Request Backup
    App->>App: Get DB URL
    App->>App: Trim whitespace
    App->>DB: Connect with clean DB URL
    DB-->>App: Backup data
    App-->>User: Return backup status
Loading

Assessment against linked issues

Objective Addressed Explanation
Ensure database URL is properly trimmed to avoid parsing errors (#[36176])

Suggested labels

Bug

Poem

In the code where URLs roam,
Whitespace trimmed, they find a home.
Backups now run without a fuss,
Clean and neat, they’re a must!
Cheers to fixes, let’s raise a cheer,
For smoother operations, year after year! 🎉


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>.
    • 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 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 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.

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 added Bug Something isn't working High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage Production labels Sep 9, 2024
@pratapaprasanna
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Sep 9, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10774092346.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36201.
recreate: .

Copy link

github-actions bot commented Sep 9, 2024

Deploy-Preview-URL: https://ce-36201.dp.appsmith.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: 2

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aac30b6 and 346f567.

Files selected for processing (1)
  • deploy/docker/fs/opt/appsmith/utils/bin/utils.js (2 hunks)

@@ -38,7 +38,7 @@ function getDburl() {
let env_array = fs.readFileSync(Constants.ENV_PATH, 'utf8').toString().split("\n");
for (let i in env_array) {
if (env_array[i].startsWith("APPSMITH_MONGODB_URI") || env_array[i].startsWith("APPSMITH_DB_URL")) {
dbUrl = env_array[i].toString().split("=")[1];
dbUrl = env_array[i].toString().split("=")[1].trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure consistent handling of undefined or null values.

The line dbUrl = env_array[i].toString().split("=")[1].trim(); assumes that the split operation results in at least two elements. If the environment variable is malformed and does not contain an "=", this will result in an undefined value, which will cause an error when trim() is called.

To prevent runtime errors, consider checking if the split operation results in the expected number of elements before calling trim():

- dbUrl = env_array[i].toString().split("=")[1].trim();
+ const parts = env_array[i].toString().split("=");
+ dbUrl = parts.length > 1 ? parts[1].trim() : '';
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dbUrl = env_array[i].toString().split("=")[1].trim();
const parts = env_array[i].toString().split("=");
dbUrl = parts.length > 1 ? parts[1].trim() : '';

@@ -48,7 +48,7 @@
let dbEnvUrl = process.env.APPSMITH_DB_URL || process.env.APPSMITH_MONGO_DB_URI;
// Make sure dbEnvUrl takes precedence over dbUrl
if (dbEnvUrl && dbEnvUrl !== "undefined") {
dbUrl = dbEnvUrl;
dbUrl = dbEnvUrl.trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

Good use of trim() to ensure clean database URLs.

The addition of trim() on the line dbUrl = dbEnvUrl.trim(); is a good practice to ensure that any leading or trailing whitespace is removed from the database URL. This change directly addresses the issue outlined in the PR summary and should help prevent errors related to improperly formatted URIs in backup operations.

However, as mentioned in the PR summary, there's a need to remove special characters as well. Consider extending this functionality to also filter out any unwanted characters that might cause parsing issues:

- dbUrl = dbEnvUrl.trim();
+ dbUrl = dbEnvUrl.trim().replace(/[^a-zA-Z0-9:/.@]+/g, '');

This regex will remove any characters that are not alphanumeric, colon, slash, period, or at symbol, which are typically safe for URIs.

Committable suggestion was skipped due to low confidence.

@pratapaprasanna
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10847567082.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36201.
recreate: .

@pratapaprasanna
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10847694151.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36201.
recreate: .

@pratapaprasanna
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10847946636.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36201.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-36201.dp.appsmith.com

@pratapaprasanna pratapaprasanna merged commit 9398cf4 into release Sep 13, 2024
18 checks passed
@pratapaprasanna pratapaprasanna deleted the fix/trim/dburl branch September 13, 2024 11:26
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
…appsmithorg#36201)

fixes: appsmithorg#36176 

<!-- This is an auto-generated comment: Cypress test results  -->
> [!WARNING]
> Tests have not run on the HEAD
dd01ffd yet
> <hr>Fri, 13 Sep 2024 10:38:44 UTC
<!-- end of auto-generated comment: Cypress test results  -->


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **Bug Fixes**
- Improved handling of database URLs by removing leading and trailing
whitespace, enhancing robustness and preventing potential issues.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working DevOps Pod Issues related to devops High This issue blocks a user from building or impacts a lot of users Needs Triaging Needs attention from maintainers to triage Production
Projects
None yet
1 participant