Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@arxdsilva
Copy link
Member

@arxdsilva arxdsilva commented Feb 17, 2025

Summary by CodeRabbit

  • Refactor
    • Streamlined database security configuration by replacing legacy SSL options with PostgreSQL-specific settings for improved consistency and clarity.
  • Bug Fixes
    • Updated test cases to reflect changes in database configuration fields, ensuring accurate assertions for PostgreSQL settings.
  • Chores
    • Removed unnecessary blank lines in the configuration file without affecting its structure or functionality.
  • New Features
    • Enhanced test output with verbose mode during test execution for better visibility into test results.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 17, 2025

Warning

Rate limit exceeded

@arxdsilva has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 59 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 e61647c and 4d6e294.

📒 Files selected for processing (2)
  • config/config.go (5 hunks)
  • config/config_test.go (5 hunks)

Walkthrough

The pull request modifies the SSL configuration handling by removing legacy SSL fields from the Prest struct and introducing PostgreSQL-specific fields. The Load function is updated to set a default SSL mode, and the parsing logic is restructured to utilize the new PGSSL fields. The deprecated parseSSLData and parseSSLV1Data functions are eliminated. Test cases are adjusted to reflect the new PGSSL field names, ensuring consistency in configuration parsing. Additionally, minor adjustments are made to the GitHub Actions workflow to enable verbose test output.

Changes

File Change Summary
config/config.go Removed fields: Version, SSLMode, SSLCert, SSLKey, SSLRootCert from Prest struct; Added fields: PGSSLMode, PGSSLKey, PGSSLCert, PGSSLRootCert; Updated Load function for default SSL mode; Removed parseSSLData functions; Added Restrict field to AccessConf.
config/config_test.go Updated test assertions to switch from require to assert across multiple test functions, including checks for PGSSLMode, HTTPPort, and Restrict; Added unsetEnv helper function for environment cleanup.
testdata/prest.toml Removed multiple blank lines; no functional changes made.
.github/workflows/test.yml Modified test command to include -v flag for verbose output during test execution.

Sequence Diagram(s)

sequenceDiagram
    participant Loader as Config Loader
    participant Parser as Parse Function
    participant DBParser as parseDatabaseURL Function

    Loader->>Parser: Read configuration file
    Parser->>Parser: Remove legacy SSL fields
    Parser->>Parser: Add PGSSL fields & update logic
    Parser->>DBParser: Pass database URL for parsing
    DBParser->>DBParser: Extract PGSSLMode from URL
    DBParser-->>Parser: Return updated configuration
    Parser-->>Loader: Updated configuration with PGSSL settings
Loading

Poem

Hop, hop, hop, I'm a clever rabbit,
Leaping over old fields to a new habitat.
PGSSL signs the dawn, bright and clear,
Old SSLs vanish, no longer here.
Code blossoms anew—let's give a cheer! 🐇✨


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.

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

🧹 Nitpick comments (1)
config/config.go (1)

371-371: Consider validating the user-provided sslmode.
Here, you accept any value for sslmode from the query parameters. Add a quick check to ensure it’s one of the known PostgreSQL SSL modes (e.g., "disable", "require", etc.).

Example snippet:

 if u.Query().Get("sslmode") != "" {
+   validModes := map[string]bool{"disable": true, "require": true, "verify-ca": true, "verify-full": true}
+   userMode := u.Query().Get("sslmode")
+   if !validModes[userMode] {
+       log.Warningf("Invalid sslmode: %s, defaulting to 'disable'", userMode)
+       cfg.PGSSLMode = "disable"
+   } else {
        cfg.PGSSLMode = userMode
+   }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 478ddea and 8e0390b.

📒 Files selected for processing (2)
  • config/config.go (2 hunks)
  • config/config_test.go (4 hunks)
🔇 Additional comments (5)
config/config.go (1)

237-237: Question the fallback from the default "require" to "disable".
Line 179 sets a default of "require", but here, when no config file is found, you're overriding it to "disable". This may be intentional; if not, consider aligning both defaults or clarifying the intended behavior.

Do you want me to scan the codebase to see if there's a dependency on default "require"?

config/config_test.go (4)

39-39: Test behavior is consistent with the fallback SSL mode.
This test verifies the code’s fallback to "disable" when no config file is found, matching the logic at line 237 in config.go.


185-185: Great test coverage for PREST_PG_URL override.
This confirms that "sslmode=disable" is correctly interpreted from the environment variable.


196-196: Correctly testing DATABASE_URL-based sslmode.
This ensures "sslmode=disable" is parsed as expected from the DATABASE_URL.


235-235: Accurate test of parseDatabaseURL with "require" sslmode.
Verifies that "sslmode=require" is properly recognized and stored in cfg.PGSSLMode.

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

🧹 Nitpick comments (1)
config/config.go (1)

63-115: Consider updating documentation for SSL configuration changes.

The Prest struct has undergone significant SSL configuration changes. Consider adding documentation comments to explain:

  1. The available SSL modes and their security implications
  2. The recommended SSL mode for production environments
  3. Examples of secure SSL configuration

Add documentation comments above the struct:

 // Prest basic config
+// SSL Configuration:
+// PGSSLMode: PostgreSQL SSL mode (disable, allow, prefer, require, verify-ca, verify-full)
+// PGSSLCert: Path to client certificate file
+// PGSSLKey: Path to client private key file
+// PGSSLRootCert: Path to root certificate file
 type Prest struct {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8e0390b and 6fd9d4e.

📒 Files selected for processing (3)
  • config/config.go (3 hunks)
  • config/config_test.go (5 hunks)
  • testdata/prest.toml (0 hunks)
💤 Files with no reviewable changes (1)
  • testdata/prest.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/config_test.go
🔇 Additional comments (2)
config/config.go (2)

258-261: LGTM! Well-structured PostgreSQL SSL configuration.

The new PostgreSQL-specific SSL configuration fields are correctly implemented and follow PostgreSQL's naming convention.


370-370: LGTM! Correct parsing of SSL mode from database URL.

The SSL mode is correctly parsed from the database URL and assigned to the new PostgreSQL-specific field.

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

♻️ Duplicate comments (1)
config/config.go (1)

179-181: ⚠️ Potential issue

Security concern: Default SSL mode set to "disable".

Setting pg.ssl.mode to "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.

Apply this diff to improve security:

-	viper.SetDefault("pg.ssl.mode", "disable")
+	viper.SetDefault("pg.ssl.mode", "prefer")

Note: The TODO comment suggests that this is a temporary setting until the migration to pgx is complete. However, it's crucial to maintain secure defaults even during the transition period.

🧹 Nitpick comments (1)
config/config.go (1)

230-230: Consider splitting the Parse function.

The TODO comment on line 230 correctly identifies that the Parse function should be split into smaller, more focused methods. This would improve maintainability and testability.

Consider breaking down the Parse function into these methods:

  1. parseAuthConfig
  2. parseHTTPConfig
  3. parseDBConfig
  4. parseJWTConfig
  5. parseCORSConfig
  6. parseExposeConfig
  7. parseCacheConfig
  8. parseAccessConfig
  9. parsePluginConfig

Example refactor:

func (p *Prest) parseDBConfig() {
    p.PGURL = viper.GetString("pg.url")
    p.PGHost = viper.GetString("pg.host")
    p.PGPort = viper.GetInt("pg.port")
    p.PGUser = viper.GetString("pg.user")
    p.PGPass = viper.GetString("pg.pass")
    p.PGDatabase = viper.GetString("pg.database")
    p.PGSSLMode = viper.GetString("pg.ssl.mode")
    p.PGSSLKey = viper.GetString("pg.ssl.key")
    p.PGSSLCert = viper.GetString("pg.ssl.cert")
    p.PGSSLRootCert = viper.GetString("pg.ssl.rootcert")
    // ... other DB-related config
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 54eac9a and 5e86f56.

📒 Files selected for processing (3)
  • config/config.go (3 hunks)
  • config/config_test.go (4 hunks)
  • testdata/prest.toml (0 hunks)
💤 Files with no reviewable changes (1)
  • testdata/prest.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • config/config_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
config/config.go (3)

82-85: LGTM! PostgreSQL-specific SSL fields are properly defined.

The SSL-related fields in the Prest struct have been correctly renamed to use the PG prefix, making it clear that these are PostgreSQL-specific configurations.


238-238: Excellent! Secure default for SSL mode when config file is not found.

The code sets a secure default of "prefer" for SSL mode when the configuration file is not found, which aligns with PostgreSQL's security recommendations.


371-373: LGTM! Proper handling of SSL mode from database URL.

The code correctly extracts and sets the SSL mode from the database URL's query parameters.

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

♻️ Duplicate comments (1)
config/config.go (1)

179-181: ⚠️ Potential issue

Security concern: Default SSL mode set to "disable".

Setting pg.ssl.mode to "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.

Apply this diff to improve security:

-	viper.SetDefault("pg.ssl.mode", "disable")
+	viper.SetDefault("pg.ssl.mode", "prefer")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e86f56 and cc22c3c.

📒 Files selected for processing (3)
  • config/config.go (3 hunks)
  • config/config_test.go (14 hunks)
  • testdata/prest.toml (0 hunks)
💤 Files with no reviewable changes (1)
  • testdata/prest.toml
🧰 Additional context used
🪛 golangci-lint (1.62.2)
config/config_test.go

108-108: Error return value of w.Write is not checked

(errcheck)

🪛 GitHub Actions: test code
config/config_test.go

[error] 41-41: TestParse/no_envs failed: expected: false, actual: true


[error] 235-235: Test_parseDatabaseURL failed: expected: 'assert', actual: 'require'

🔇 Additional comments (1)
config/config.go (1)

238-238: LGTM! Good security practice.

Setting the fallback SSL mode to "prefer" is a good security practice as it maintains secure defaults when the config file is not found.

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

🧹 Nitpick comments (1)
config/config.go (1)

230-231: Remove outdated TODO comment.

The TODO comment about splitting the config can be removed as it has been addressed by the recent refactoring that split the configuration parsing into separate functions.

-// todo: split config onto methods to simplify this
 func Parse(cfg *Prest) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cc22c3c and f22cb28.

📒 Files selected for processing (1)
  • config/config.go (5 hunks)
🔇 Additional comments (2)
config/config.go (2)

179-181: Security concern: Default SSL mode set to "disable".

Setting pg.ssl.mode to "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.


243-247: LGTM! Well-structured configuration parsing.

The refactoring of configuration parsing into separate functions (parseAuthConfig, parseHTTPConfig, parseDBConfig, loadCacheConfig) improves code organization and maintainability by following the Single Responsibility Principle.

Also applies to: 425-480

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

♻️ Duplicate comments (1)
config/config_test.go (1)

43-44: ⚠️ Potential issue

Fix failing test: TestParse/no_envs.

The test is failing because the assertion doesn't match the default value set in viperCfg(). The test expects cfg.Debug to be false, but it's getting true.

Apply this diff to fix the test:

-		assert.Equal(t, false, cf.Debug)
+		assert.Equal(t, viper.GetBool("debug"), cf.Debug)
🧰 Tools
🪛 GitHub Actions: test code

[error] 44-44: TestParse failed: Not equal: expected: false, actual: true

🧹 Nitpick comments (1)
config/config_test.go (1)

338-343: Use the helper function to clean up environment variables.

The unsetEnv helper function is well-structured but currently unused. Consider using it in test cases that modify environment variables to ensure proper cleanup.

For example, in the TestParse function:

 func TestParse(t *testing.T) {
+	unsetEnv(t)
 	t.Run("no envs", func(t *testing.T) {
 		t.Setenv("PREST_CONF", "../notfound.toml")
 		cf := &Prest{}
🧰 Tools
🪛 golangci-lint (1.62.2)

338-338: func unsetEnv is unused

(unused)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f22cb28 and 0d08f00.

📒 Files selected for processing (2)
  • config/config.go (6 hunks)
  • config/config_test.go (11 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
config/config_test.go

111-111: Error return value of w.Write is not checked

(errcheck)


338-338: func unsetEnv is unused

(unused)

🪛 GitHub Actions: test code
config/config_test.go

[error] 44-44: TestParse failed: Not equal: expected: false, actual: true

🔇 Additional comments (5)
config/config.go (5)

157-158: LGTM!

Setting the default value for access.restrict to false is a sensible default.


181-183: Security concern: Default SSL mode set to "disable".

Setting pg.ssl.mode to "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.

Apply this diff to improve security:

-	viper.SetDefault("pg.ssl.mode", "disable")
+	viper.SetDefault("pg.ssl.mode", "prefer")

240-240: Security concern: SSL mode fallback set to "disable".

When the config file is not found, falling back to "disable" for SSL mode is a security risk. The fallback should maintain secure defaults.

Apply this diff to improve security:

-			cfg.PGSSLMode = "disable"
+			cfg.PGSSLMode = "prefer"

428-451: LGTM!

The parseDBConfig function is well-structured and correctly handles all database configuration fields, including the new PostgreSQL-specific SSL fields.


453-466: LGTM!

The loadCacheConfig function is well-structured and correctly handles all cache configuration fields.

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

♻️ Duplicate comments (2)
config/config.go (2)

179-181: ⚠️ Potential issue

Security concern: Default SSL mode set to "disable".

Setting pg.ssl.mode to "disable" by default is a security risk. PostgreSQL recommends using at least "prefer" as the default SSL mode to ensure secure communication when possible.

While the TODO comment indicates a plan to replace this with "prefer" after switching to pgx, this should be prioritized as it affects the security of database connections.


238-238: ⚠️ Potential issue

Security concern: SSL mode fallback set to "disable".

When the config file is not found, falling back to "disable" for SSL mode is a security risk. The fallback should maintain secure defaults.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d08f00 and e61647c.

📒 Files selected for processing (3)
  • .github/workflows/test.yml (1 hunks)
  • config/config.go (5 hunks)
  • config/config_test.go (7 hunks)
🧰 Additional context used
🪛 golangci-lint (1.62.2)
config/config_test.go

108-108: Error return value of w.Write is not checked

(errcheck)

🔇 Additional comments (8)
config/config.go (5)

243-246: LGTM! Good refactoring of configuration parsing.

Breaking down the configuration parsing into smaller, focused functions improves code organization and maintainability.


425-448: LGTM! Well-structured database configuration parsing.

The function properly handles all PostgreSQL-related configurations, including the new SSL fields. The cloud factor support for DATABASE_URL is a good addition.


450-463: LGTM! Clean cache configuration handling.

The function effectively manages cache settings and endpoint configurations.


465-474: LGTM! Clear authentication configuration parsing.

The function cleanly handles all authentication-related settings.


476-480: LGTM! Concise HTTP configuration parsing.

The function effectively handles HTTP-related settings.

config/config_test.go (2)

29-41: LGTM! Updated test assertions for new configuration structure.

The test cases properly verify the default values for the new PostgreSQL SSL fields.


204-205: LGTM! Proper test environment cleanup.

Good practice to unset environment variables before each test to ensure a clean state.

Also applies to: 213-214, 224-225

.github/workflows/test.yml (1)

84-84: LGTM! Added verbose test output.

Adding the -v flag improves test debugging by providing detailed output for each test case.

@arxdsilva arxdsilva merged commit 03937fb into main Feb 18, 2025
11 checks passed
@arxdsilva arxdsilva deleted the deprecate-ssl-v1 branch February 18, 2025 02:18
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