Skip to content

update ExecuterService Contracts and decrypt env connection string i…#4024

Closed
sudarshan0212 wants to merge 8 commits into
Releases/Official-Releasefrom
update_environment_CLI
Closed

update ExecuterService Contracts and decrypt env connection string i…#4024
sudarshan0212 wants to merge 8 commits into
Releases/Official-Releasefrom
update_environment_CLI

Conversation

@sudarshan0212

@sudarshan0212 sudarshan0212 commented Dec 6, 2024

Copy link
Copy Markdown
Contributor

…f encrypted.

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a method to securely decrypt database connection strings, enhancing security.
  • Updates

    • Updated the Ginger.ExecuterService.Contracts package across multiple projects from version 24.3.1 to 24.5.4, potentially improving functionality and fixing bugs.
  • Cleanup

    • Removed obsolete files and resources from various projects to streamline the structure and improve efficiency.

@coderabbitai

coderabbitai Bot commented Dec 6, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

The changes in this pull request involve updates to multiple project files within the Ginger framework. Key modifications include the removal of various file references and the upgrade of the Ginger.ExecuterService.Contracts package from version 24.3.1 to 24.5.4 across several project files. Additionally, a new method for decrypting connection strings has been introduced in the DatabaseConfigHelper class, enhancing security. Overall, these changes focus on cleaning up unused files and ensuring that dependencies are current.

Changes

File Path Change Summary
Ginger/Ginger/Ginger.csproj Removed multiple file references; updated PackageReference for Ginger.ExecuterService.Contracts from 24.3.1 to 24.5.4.
Ginger/GingerCoreNET/GingerCoreNET.csproj Removed various file references; updated PackageReference for Ginger.ExecuterService.Contracts from 24.3.1 to 24.5.4.
Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs Added method DecryptConnectionString; modified existing methods to utilize this new method for handling connection strings.
Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj Removed multiple file references; updated PackageReference for Ginger.ExecuterService.Contracts from 24.3.1 to 24.5.4.
Ginger/GingerRuntime/GingerRuntime.csproj Updated PackageReference for Ginger.ExecuterService.Contracts from 24.3.1 to 24.5.4.

Possibly related PRs

Suggested reviewers

  • Maheshkale447

🐇 In the meadow, changes bloom,
Files removed, making room.
Packages updated, oh what a sight,
Decrypting strings, securing the night.
Clean and tidy, the code we adore,
Hopping forward, we achieve much more! 🌼✨


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. (Experiment)
  • @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 or @coderabbitai title 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (1)
Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (1)

Line range hint 81-88: Verify consistent error handling

The methods CreateDatabaseFromConfig and UpdateDatabaseFromConfig now use DecryptConnectionString, but they should handle potential exceptions from the decryption process.

Add try-catch blocks to handle decryption errors:

 public static Database CreateDatabaseFromConfig(DatabaseConfig databaseConfig)
 {
     ValidateDatabaseConfig(databaseConfig);            
+    try
+    {
         return new()
         {
             ConnectionString = DecryptConnectionString(databaseConfig),
             Name = databaseConfig.Name,
             KeepConnectionOpen = databaseConfig.KeepConnectionOpen ?? false,
             DBType = ConvertDBConfigTypeToDBType(databaseConfig.DBType)
         };
+    }
+    catch (Exception ex)
+    {
+        throw new InvalidOperationException($"Failed to create database configuration: {ex.Message}", ex);
+    }
 }

 public static void UpdateDatabaseFromConfig(DatabaseConfig db, ref Database dbFromGinger)
 {
     ValidateDatabaseConfig(db);
+    try
+    {            
         dbFromGinger.Name = db.Name;
         dbFromGinger.ConnectionString = DecryptConnectionString(db);
         dbFromGinger.KeepConnectionOpen = db.KeepConnectionOpen ?? false;
         dbFromGinger.DBType = ConvertDBConfigTypeToDBType(db.DBType);
+    }
+    catch (Exception ex)
+    {
+        throw new InvalidOperationException($"Failed to update database configuration: {ex.Message}", ex);
+    }
 }

Also applies to: 93-97

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 43c27b5 and 375fe49.

📒 Files selected for processing (5)
  • Ginger/Ginger/Ginger.csproj (1 hunks)
  • Ginger/GingerCoreNET/GingerCoreNET.csproj (1 hunks)
  • Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (3 hunks)
  • Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj (1 hunks)
  • Ginger/GingerRuntime/GingerRuntime.csproj (1 hunks)
👮 Files not reviewed due to content moderation or server errors (2)
  • Ginger/GingerCoreNET/GingerCoreNET.csproj
  • Ginger/Ginger/Ginger.csproj
🔇 Additional comments (2)
Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (1)

19-22: LGTM: Required imports added

The new imports support the encryption functionality.

Ginger/GingerCoreNETUnitTest/GingerCoreNETUnitTest.csproj (1)

91-91: Verify test coverage for new functionality

While the package version update is consistent, we should ensure that unit tests cover the new decryption functionality in DatabaseConfigHelper.


<ItemGroup>
<PackageReference Include="Ginger.ExecuterService.Contracts" Version="24.3.1" />
<PackageReference Include="Ginger.ExecuterService.Contracts" Version="24.5.4" />

@coderabbitai coderabbitai Bot Dec 6, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Package version 24.5.4 is not the latest available

The package Ginger.ExecuterService.Contracts has a newer stable version 24.6.1 available. Consider updating to the latest version for potential improvements and bug fixes. No security vulnerabilities were found for this package.

🔗 Analysis chain

Verify package version compatibility

The package version update from 24.3.1 to 24.5.4 is consistent across project files. However, we should verify this version.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the latest stable version of Ginger.ExecuterService.Contracts

# Check NuGet for latest versions
curl -s https://api.nuget.org/v3-flatcontainer/ginger.executerservice.contracts/index.json | jq -r '.versions[]' | sort -V | tail -n 5

# Check for any security advisories
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: NUGET, package: "Ginger.ExecuterService.Contracts") {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 539

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

24.6.1 version is unlisted.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@sudarshan0212, understood. Thank you for informing me that version 24.6.1 is unlisted. Continuing with version 24.5.4 is the right choice.

(_/)
(..)
(")
(")


✏️ Learnings added
Learnt from: sudarshan0212
PR: Ginger-Automation/Ginger#4024
File: Ginger/GingerRuntime/GingerRuntime.csproj:43-43
Timestamp: 2024-12-09T12:36:36.691Z
Learning: Version 24.6.1 of Ginger.ExecuterService.Contracts is unlisted and should not be suggested for updates.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Comment on lines +100 to +112
public static string DecryptConnectionString(DatabaseConfig db)
{
string DbConnectionString = string.Empty;
if (db.IsConnectionStringEncrypted == true)
{
DbConnectionString = EncryptionHandler.DecryptwithKey(db.ConnectionString, WorkSpace.Instance.Solution.EncryptionKey);
}
else
{
DbConnectionString = db.ConnectionString;
}
return DbConnectionString;
}

@coderabbitai coderabbitai Bot Dec 6, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Review encryption key handling

The method correctly handles both encrypted and unencrypted connection strings. However, there are a few considerations:

  1. The method assumes WorkSpace.Instance.Solution is not null
  2. No null check for the connection string itself

Consider adding null checks:

 public static string DecryptConnectionString(DatabaseConfig db)
 {
+    if (db?.ConnectionString == null)
+    {
+        throw new ArgumentNullException(nameof(db), "Database config or connection string cannot be null");
+    }
+    
+    if (WorkSpace.Instance?.Solution?.EncryptionKey == null)
+    {
+        throw new InvalidOperationException("Workspace solution encryption key not available");
+    }
+
     string DbConnectionString = string.Empty;
     if (db.IsConnectionStringEncrypted == true)
     {
         DbConnectionString = EncryptionHandler.DecryptwithKey(db.ConnectionString, WorkSpace.Instance.Solution.EncryptionKey);
     }
     else
     {
         DbConnectionString = db.ConnectionString;
     }
     return DbConnectionString;
 }
📝 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
public static string DecryptConnectionString(DatabaseConfig db)
{
string DbConnectionString = string.Empty;
if (db.IsConnectionStringEncrypted == true)
{
DbConnectionString = EncryptionHandler.DecryptwithKey(db.ConnectionString, WorkSpace.Instance.Solution.EncryptionKey);
}
else
{
DbConnectionString = db.ConnectionString;
}
return DbConnectionString;
}
public static string DecryptConnectionString(DatabaseConfig db)
{
if (db?.ConnectionString == null)
{
throw new ArgumentNullException(nameof(db), "Database config or connection string cannot be null");
}
if (WorkSpace.Instance?.Solution?.EncryptionKey == null)
{
throw new InvalidOperationException("Workspace solution encryption key not available");
}
string DbConnectionString = string.Empty;
if (db.IsConnectionStringEncrypted == true)
{
DbConnectionString = EncryptionHandler.DecryptwithKey(db.ConnectionString, WorkSpace.Instance.Solution.EncryptionKey);
}
else
{
DbConnectionString = db.ConnectionString;
}
return DbConnectionString;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Resolved as per coderabbit comments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@sudarshan0212, glad to hear that the issue has been resolved! (^・^)/


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

@MeniKadosh1 MeniKadosh1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

see Rabbit comments for code improvments

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (1)

112-112: Simplify boolean condition

Instead of comparing db.IsConnectionStringEncrypted == true, you can simplify the condition to if (db.IsConnectionStringEncrypted) for readability.

Apply this diff to simplify the condition:

-                if (db.IsConnectionStringEncrypted == true)
+                if (db.IsConnectionStringEncrypted)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 375fe49 and 927cd07.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (3 hunks)
🔇 Additional comments (3)
Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (3)

19-22: Usings added are appropriate

The added using statements are necessary for the new functionality and ensure that all required namespaces are available.


84-84: ConnectionString assignment updated appropriately

The assignment of ConnectionString now correctly uses DecryptConnectionString(databaseConfig), ensuring that the connection string is decrypted before use.


95-95: ConnectionString assignment updated appropriately

The dbFromGinger.ConnectionString is now set using DecryptConnectionString(db), which ensures the connection string is decrypted correctly.

Comment on lines +107 to +110
if (WorkSpace.Instance?.Solution?.EncryptionKey == null)
{
throw new InvalidOperationException("Workspace solution encryption key not available");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize encryption key check for encrypted connection strings

Currently, the method checks for WorkSpace.Instance?.Solution?.EncryptionKey == null regardless of whether the connection string is encrypted. Move this check inside the if (db.IsConnectionStringEncrypted == true) block to prevent unnecessary exceptions and improve efficiency.

Apply this diff to adjust the method:

 public static string DecryptConnectionString(DatabaseConfig db)
 {
     if (db?.ConnectionString == null)
     {
         throw new ArgumentNullException(nameof(db), "Database config or connection string cannot be null");
     }

-    if (WorkSpace.Instance?.Solution?.EncryptionKey == null)
-    {
-        throw new InvalidOperationException("Workspace solution encryption key not available");
-    }

     string DbConnectionString = string.Empty;
     if (db.IsConnectionStringEncrypted == true)
     {
+        if (WorkSpace.Instance?.Solution?.EncryptionKey == null)
+        {
+            throw new InvalidOperationException("Workspace solution encryption key not available");
+        }

         DbConnectionString = EncryptionHandler.DecryptwithKey(db.ConnectionString, WorkSpace.Instance.Solution.EncryptionKey);
     }
     else
     {
         DbConnectionString = db.ConnectionString;
     }
     return DbConnectionString;
 }
📝 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
if (WorkSpace.Instance?.Solution?.EncryptionKey == null)
{
throw new InvalidOperationException("Workspace solution encryption key not available");
}
public static string DecryptConnectionString(DatabaseConfig db)
{
if (db?.ConnectionString == null)
{
throw new ArgumentNullException(nameof(db), "Database config or connection string cannot be null");
}
string DbConnectionString = string.Empty;
if (db.IsConnectionStringEncrypted == true)
{
if (WorkSpace.Instance?.Solution?.EncryptionKey == null)
{
throw new InvalidOperationException("Workspace solution encryption key not available");
}
DbConnectionString = EncryptionHandler.DecryptwithKey(db.ConnectionString, WorkSpace.Instance.Solution.EncryptionKey);
}
else
{
DbConnectionString = db.ConnectionString;
}
return DbConnectionString;
}

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (1)

111-111: Follow C# naming conventions

The local variable DbConnectionString should follow camelCase naming convention.

-            string DbConnectionString = string.Empty;
+            string dbConnectionString = string.Empty;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 927cd07 and 0459db9.

📒 Files selected for processing (1)
  • Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (3 hunks)
🔇 Additional comments (4)
Ginger/GingerCoreNET/RunLib/DynamicExecutionLib/DatabaseConfigHelper.cs (4)

19-22: LGTM: Import changes align with PR objectives

The added imports for ExecuterService.Contracts are necessary for the updated functionality.


84-84: LGTM: Improved security with connection string decryption

The change properly integrates the new decryption functionality into database creation.


95-95: LGTM: Consistent implementation of connection string decryption

The change maintains consistency with CreateDatabaseFromConfig method.


107-110: 🛠️ Refactor suggestion

Optimize encryption key check placement

Move the encryption key check inside the encrypted connection string block to prevent unnecessary exceptions.

throw new InvalidOperationException("Workspace solution encryption key not available");
}
string DbConnectionString = string.Empty;
if ((bool)db.IsConnectionStringEncrypted)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix potential InvalidCastException in boolean casting

The explicit casting of db.IsConnectionStringEncrypted to bool could throw an InvalidCastException. Use a null-safe approach instead.

-            if ((bool)db.IsConnectionStringEncrypted)
+            if (db.IsConnectionStringEncrypted == true)
📝 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
if ((bool)db.IsConnectionStringEncrypted)
if (db.IsConnectionStringEncrypted == true)

@Maheshkale447

Copy link
Copy Markdown
Contributor

Handled via different PR

@Maheshkale447
Maheshkale447 deleted the update_environment_CLI branch October 28, 2025 14:33
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.

3 participants