From 7fe57c9393876abd698c5b29e5f1c4bb140550d3 Mon Sep 17 00:00:00 2001 From: Cristian Magherusan-Stanciu Date: Thu, 16 Jul 2026 21:15:04 +0300 Subject: [PATCH] refactor(aws): reduce 4 offering-match funcs below gocyclo 10 (closes #1388) Extract resolveTag(execID string) string into each of the four AWS service packages (redshift, opensearch, elasticache, memorydb) and replace the inline `if tag == ""` branch inside findOfferingID / paginateElastiCacheOfferings. This removes one cyclomatic-complexity unit from each function, dropping all four from 11 to 10 so the pre-commit `gocyclo -over 10` hook passes on all-files runs without changing any control-flow semantics or return values. --- providers/aws/services/elasticache/client.go | 16 ++++++++++++---- providers/aws/services/memorydb/client.go | 16 ++++++++++++---- providers/aws/services/opensearch/client.go | 16 ++++++++++++---- providers/aws/services/redshift/client.go | 16 ++++++++++++---- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/providers/aws/services/elasticache/client.go b/providers/aws/services/elasticache/client.go index a5b20fe38..dc135c201 100644 --- a/providers/aws/services/elasticache/client.go +++ b/providers/aws/services/elasticache/client.go @@ -290,10 +290,7 @@ func (c *Client) paginateElastiCacheOfferings(ctx context.Context, rec common.Re if err != nil { return "", err } - tag := execID - if tag == "" { - tag = "no-exec" - } + tag := resolveTag(execID) t0 := time.Now() log.Printf("purchase[%s]: ElastiCache findOfferingID starting (nodeType=%s engine=%s duration=%s payment=%s)", tag, rec.ResourceType, details.Engine, duration, offeringType) @@ -359,6 +356,17 @@ func scanElastiCacheOfferingPage(offerings []types.ReservedCacheNodesOffering, r return "", nil } +// resolveTag returns execID when non-empty, or a sentinel "no-exec" string for +// log correlation when called outside of a purchase flow (e.g. ValidateOffering, +// GetOfferingDetails). Extracted from paginateElastiCacheOfferings to keep +// cyclomatic complexity within the pre-commit gocyclo limit (issue #1388). +func resolveTag(execID string) string { + if execID == "" { + return "no-exec" + } + return execID +} + // ValidateOffering checks if an offering exists without purchasing func (c *Client) ValidateOffering(ctx context.Context, rec common.Recommendation) error { _, err := c.findOfferingID(ctx, rec, "") diff --git a/providers/aws/services/memorydb/client.go b/providers/aws/services/memorydb/client.go index 51e9b3553..7f1dabd13 100644 --- a/providers/aws/services/memorydb/client.go +++ b/providers/aws/services/memorydb/client.go @@ -292,10 +292,7 @@ func (c *Client) findOfferingID(ctx context.Context, rec common.Recommendation, if err != nil { return "", err } - tag := execID - if tag == "" { - tag = "no-exec" - } + tag := resolveTag(execID) t0 := time.Now() log.Printf("purchase[%s]: MemoryDB findOfferingID starting (nodeType=%s term=%s payment=%s)", tag, rec.ResourceType, rec.Term, rec.PaymentOption) @@ -380,6 +377,17 @@ func isLastMemoryDBPage(nextToken *string) bool { return nextToken == nil || aws.ToString(nextToken) == "" } +// resolveTag returns execID when non-empty, or a sentinel "no-exec" string for +// log correlation when called outside of a purchase flow (e.g. ValidateOffering, +// GetOfferingDetails). Extracted from findOfferingID to keep cyclomatic complexity +// within the pre-commit gocyclo limit (issue #1388). +func resolveTag(execID string) string { + if execID == "" { + return "no-exec" + } + return execID +} + // getDurationStringForAPI converts the term string to a duration value accepted // by DescribeReservedNodesOfferings (seconds as a string or "1yr"/"3yr"). // The MemoryDB API accepts both numeric-seconds strings and year strings. diff --git a/providers/aws/services/opensearch/client.go b/providers/aws/services/opensearch/client.go index 73ec2b61a..e96c01b20 100644 --- a/providers/aws/services/opensearch/client.go +++ b/providers/aws/services/opensearch/client.go @@ -371,10 +371,7 @@ func (c *Client) findOfferingID(ctx context.Context, rec common.Recommendation, if err != nil { return "", err } - tag := execID - if tag == "" { - tag = "no-exec" - } + tag := resolveTag(execID) t0 := time.Now() log.Printf("purchase[%s]: OpenSearch findOfferingID starting (instanceType=%s term=%s payment=%s)", tag, rec.ResourceType, rec.Term, rec.PaymentOption) @@ -608,3 +605,14 @@ func getTermMonthsFromDuration(duration int32) int { } return 12 } + +// resolveTag returns execID when non-empty, or a sentinel "no-exec" string for +// log correlation when called outside of a purchase flow (e.g. ValidateOffering, +// GetOfferingDetails). Extracted from findOfferingID to keep cyclomatic complexity +// within the pre-commit gocyclo limit (issue #1388). +func resolveTag(execID string) string { + if execID == "" { + return "no-exec" + } + return execID +} diff --git a/providers/aws/services/redshift/client.go b/providers/aws/services/redshift/client.go index df14ca589..492e48bf6 100644 --- a/providers/aws/services/redshift/client.go +++ b/providers/aws/services/redshift/client.go @@ -416,10 +416,7 @@ func (c *Client) findOfferingID(ctx context.Context, rec common.Recommendation, if err != nil { return "", err } - tag := execID - if tag == "" { - tag = "no-exec" - } + tag := resolveTag(execID) t0 := time.Now() log.Printf("purchase[%s]: Redshift findOfferingID starting (nodeType=%s term=%s payment=%s)", tag, rec.ResourceType, rec.Term, rec.PaymentOption) @@ -691,3 +688,14 @@ func getTermMonthsFromDuration(duration int32) int { } return 12 } + +// resolveTag returns execID when non-empty, or a sentinel "no-exec" string for +// log correlation when called outside of a purchase flow (e.g. ValidateOffering, +// GetOfferingDetails). Extracted from findOfferingID to keep cyclomatic complexity +// within the pre-commit gocyclo limit (issue #1388). +func resolveTag(execID string) string { + if execID == "" { + return "no-exec" + } + return execID +}