refactor: add elasticache client and clean up code formatting#82
refactor: add elasticache client and clean up code formatting#82RoseSecurity wants to merge 2 commits intomainfrom
Conversation
- Add new ElastiCache client helper functions - Fix import ordering to follow Go conventions - Remove unnecessary blank lines throughout codebase - Fix trailing whitespace and missing newlines - Simplify variable declarations in RDS helpers
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
WalkthroughCodebase-wide formatting and import cleanup across AWS helpers, plus addition of Elasticache client helper functions and dependency updates in go.mod. No exported API signatures were changed. Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
pkg/aws/rds.go (2)
77-77:⚠️ Potential issue | 🔴 CriticalCritical: SQL parameter placeholder is quoted as a string literal.
The WHERE clause uses
'$1'(a literal string) instead of$1(a parameter placeholder). This means:
- The query will search for a grantee literally named "$1" instead of using the
dbUsernameparameter passed at line 79- The function will never match the intended user
🔧 Proposed fix
- WHERE grantee = '$1' + WHERE grantee = $1🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/aws/rds.go` at line 77, The SQL is incorrectly using a quoted parameter placeholder "'$1'" in the WHERE clause, causing the query to search for the literal string "$1" instead of binding the dbUsername variable; update the query in rds.go to use an unquoted placeholder ($1) so the dbUsername parameter passed to the function (referenced as dbUsername at the call site) is bound properly (check the query string where "WHERE grantee = '$1'" appears and replace the quoted placeholder with $1).
71-80:⚠️ Potential issue | 🔴 CriticalCritical: Column count mismatch between SELECT and Scan.
The SQL query selects 3 columns (
user,table,grants), but line 80 scans into only 1 variable (&schemaName). This will cause a runtime error:sql: expected 3 destination arguments in Scan, not 1.Additionally, the variable name
schemaNamedoesn't match the data being retrieved (grant information).🔧 Proposed fix
- var schemaName string + var grantee, table, grants string sqlStatement := `SELECT grantee AS user, CONCAT(table_schema, '.', table_name) AS table, CASE WHEN COUNT(privilege_type) = 7 THEN 'ALL' ELSE ARRAY_TO_STRING(ARRAY_AGG(privilege_type), ', ') END AS grants FROM information_schema.role_table_grants - WHERE grantee = '$1' + WHERE grantee = $1 GROUP BY table_name, table_schema, grantee;` row := db.QueryRow(sqlStatement, dbUsername) - scanErr := row.Scan(&schemaName) + scanErr := row.Scan(&grantee, &table, &grants) if scanErr != nil { return false, scanErr }Note: This fix assumes the function should verify that grants exist (returning true if any row is found). If different logic is intended, further adjustments may be needed.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/aws/rds.go` around lines 71 - 80, The SQL selects three columns but the code only scans into one variable and uses an unrelated name; change the logic in pkg/aws/rds.go so the SELECT and Scan match: either (A) if you only need to check existence, replace the SELECT with a single column (e.g., SELECT 1) and Scan into a single boolean/int variable (and return true if a row is found), or (B) if you need the grant details, scan into three appropriately named variables (e.g., grantee, tableName, grants) and use them; update the variable names (avoid schemaName) and the surrounding logic accordingly to reflect which approach (existence vs. details) the function intends to perform.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@pkg/aws/rds.go`:
- Line 77: The SQL is incorrectly using a quoted parameter placeholder "'$1'" in
the WHERE clause, causing the query to search for the literal string "$1"
instead of binding the dbUsername variable; update the query in rds.go to use an
unquoted placeholder ($1) so the dbUsername parameter passed to the function
(referenced as dbUsername at the call site) is bound properly (check the query
string where "WHERE grantee = '$1'" appears and replace the quoted placeholder
with $1).
- Around line 71-80: The SQL selects three columns but the code only scans into
one variable and uses an unrelated name; change the logic in pkg/aws/rds.go so
the SELECT and Scan match: either (A) if you only need to check existence,
replace the SELECT with a single column (e.g., SELECT 1) and Scan into a single
boolean/int variable (and return true if a row is found), or (B) if you need the
grant details, scan into three appropriately named variables (e.g., grantee,
tableName, grants) and use them; update the variable names (avoid schemaName)
and the surrounding logic accordingly to reflect which approach (existence vs.
details) the function intends to perform.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 241a3294-b222-410a-93a0-09cd0f38f585
📒 Files selected for processing (14)
pkg/aws/amplify.gopkg/aws/backup.gopkg/aws/documentdb.gopkg/aws/ec2.gopkg/aws/efs.gopkg/aws/eks.gopkg/aws/eks_test.gopkg/aws/elasticache.gopkg/aws/elb.gopkg/aws/msk.gopkg/aws/rds.gopkg/aws/route53.gopkg/aws/ses.gopkg/aws/waf.go
💤 Files with no reviewable changes (5)
- pkg/aws/ses.go
- pkg/aws/amplify.go
- pkg/aws/elb.go
- pkg/aws/waf.go
- pkg/aws/efs.go
what and why
This primarily focuses on code cleanup and consistency improvements across several AWS-related modules. The changes include import reordering for better readability, removal of unnecessary blank lines, minor refactoring for variable declarations, and the addition of a new client utility for ElastiCache.
New functionality:
pkg/aws/elasticache.go.Code cleanup and consistency:
pkg/aws/backup.go,pkg/aws/documentdb.go,pkg/aws/efs.go,pkg/aws/eks.go,pkg/aws/eks_test.go,pkg/aws/msk.go,pkg/aws/elb.go,pkg/aws/route53.go,pkg/aws/ses.go, andpkg/aws/waf.go. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]pkg/aws/eks.go,pkg/aws/efs.go,pkg/aws/waf.go, and others. [1] [2] [3] [4] [5]AssertPotgresqlSchemaExistsEandAssertPotgresqlGrantsExistsEfunctions inpkg/aws/rds.goto use a more concise form. [1] [2]Minor fixes:
pkg/aws/rds.go. [1] [2]These changes improve maintainability and readability of the codebase while adding ElastiCache support.