Skip to content

refactor: add elasticache client and clean up code formatting#82

Open
RoseSecurity wants to merge 2 commits intomainfrom
add-elasticache-helpers
Open

refactor: add elasticache client and clean up code formatting#82
RoseSecurity wants to merge 2 commits intomainfrom
add-elasticache-helpers

Conversation

@RoseSecurity
Copy link
Copy Markdown
Member

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:

  • Added a new utility for creating AWS ElastiCache clients, including both error-returning and error-checking versions in pkg/aws/elasticache.go.

Code cleanup and consistency:

  • Standardized import ordering and grouping in multiple files, such as 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, and pkg/aws/waf.go. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]
  • Removed unnecessary blank lines and trailing newlines in various functions and files for improved code clarity, including pkg/aws/eks.go, pkg/aws/efs.go, pkg/aws/waf.go, and others. [1] [2] [3] [4] [5]
  • Refactored variable declarations in AssertPotgresqlSchemaExistsE and AssertPotgresqlGrantsExistsE functions in pkg/aws/rds.go to use a more concise form. [1] [2]

Minor fixes:

  • Fixed misplaced or missing package declarations and removed unnecessary blank lines in pkg/aws/rds.go. [1] [2]

These changes improve maintainability and readability of the codebase while adding ElastiCache support.

- 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
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 10, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 6daab904-3e6e-4f8e-aa26-2bd6cb6bcbea

📥 Commits

Reviewing files that changed from the base of the PR and between 9a85e85 and d6d8276.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (1)
  • go.mod

Walkthrough

Codebase-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

Cohort / File(s) Summary
Formatting & Import Cleanups
pkg/aws/amplify.go, pkg/aws/backup.go, pkg/aws/documentdb.go, pkg/aws/ec2.go, pkg/aws/efs.go, pkg/aws/eks.go, pkg/aws/eks_test.go, pkg/aws/elb.go, pkg/aws/msk.go, pkg/aws/route53.go, pkg/aws/ses.go, pkg/aws/waf.go
Whitespace and blank-line removals, minor import reorderings, and missing newline fixes. No logic, control-flow, or API changes.
Elasticache Client Helpers
pkg/aws/elasticache.go
Added NewElasticacheClient(t *testing.T, region string) *elasticache.Client and NewElasticacheClientE(t *testing.T, region string) (*elasticache.Client, error) to create authenticated Elasticache clients.
RDS Variable Declarations
pkg/aws/rds.go
Replaced multi-line var (...) blocks with single-line var declarations in PostgreSQL assertion helpers; no behavioral change.
Dependency Updates
go.mod
Bumped github.com/aws/aws-sdk-go-v2 and related internals; added direct requirement for service/elasticache (v1.52.0).

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Test as rgba(135,206,235,0.5) Test / Caller
participant Auth as rgba(144,238,144,0.5) AWS Auth Session
participant Elasti as rgba(255,182,193,0.5) Elasticache Client
Test->>Auth: aws.NewAuthenticatedSession(region)
Auth-->>Test: session or error
alt session created
Test->>Elasti: elasticache.NewFromConfig(*sess)
Elasti-->>Test: *elasticache.Client
else error
Auth-->>Test: error returned
end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • Gowiem

Poem

🐇 I nibble through imports at dawn,

Trimming fluff until it's gone.
Elasticache springs up in a hop,
Dependencies bumped — then stop.
Happy code, I twirl and yawn.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes both main objectives: adding ElastiCache client support and performing code cleanup/formatting improvements across the codebase.
Description check ✅ Passed The description is well-related to the changeset, providing specific details about new ElastiCache functionality, code cleanup across multiple files, and refactoring efforts.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-elasticache-helpers

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
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.

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 | 🔴 Critical

Critical: 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 dbUsername parameter 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 | 🔴 Critical

Critical: 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 schemaName doesn'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

📥 Commits

Reviewing files that changed from the base of the PR and between e679bb8 and 9a85e85.

📒 Files selected for processing (14)
  • pkg/aws/amplify.go
  • pkg/aws/backup.go
  • pkg/aws/documentdb.go
  • pkg/aws/ec2.go
  • pkg/aws/efs.go
  • pkg/aws/eks.go
  • pkg/aws/eks_test.go
  • pkg/aws/elasticache.go
  • pkg/aws/elb.go
  • pkg/aws/msk.go
  • pkg/aws/rds.go
  • pkg/aws/route53.go
  • pkg/aws/ses.go
  • pkg/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

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.

1 participant