Skip to content

Commit 10abef9

Browse files
intel352claude
andcommitted
fix(lint): eliminate G602 and guard ResolveSizing on abstract sizes only
Two related fixes to the ResolveSizing loop in applyWithProviderAndStore: 1. G602 (gosec slice index out-of-range false positive): replace indexing via specs[i] with a local pointer `spec := &specs[i]` so gosec can confirm the slice access is safe. 2. isAbstractSize guard (Copilot #2): add isAbstractSize helper that returns true only for xs/s/m/l/xl. ResolveSizing is now skipped for provider-specific slugs (e.g. "db-s-1vcpu-1gb") which are already concrete and must not be re-resolved. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent d19f4de commit 10abef9

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

cmd/wfctl/infra_apply.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,26 @@ func applyWithProviderAndStore(ctx context.Context, provider interfaces.IaCProvi
191191

192192
// Resolve abstract sizing tiers into concrete provider-specific values
193193
// (e.g. Size: "m" → instance_type: "s-1vcpu-2gb") for each spec that
194-
// declares a Size. The resolved values are merged into spec.Config so that
195-
// plan output and apply are always in sync.
194+
// declares an abstract Size tier. Provider-specific slugs (e.g.
195+
// "db-s-1vcpu-1gb") are passed through as-is to avoid double-resolution.
196+
// The resolved values are merged into spec.Config so that plan output and
197+
// apply are always in sync.
196198
for i := range specs {
197-
if specs[i].Size == "" {
199+
spec := &specs[i]
200+
if spec.Size == "" || !isAbstractSize(spec.Size) {
198201
continue
199202
}
200-
sizing, err := provider.ResolveSizing(specs[i].Type, specs[i].Size, specs[i].Hints)
203+
sizing, err := provider.ResolveSizing(spec.Type, spec.Size, spec.Hints)
201204
if err != nil {
202-
return fmt.Errorf("%s/%s: resolve sizing: %w", specs[i].Type, specs[i].Name, err)
205+
return fmt.Errorf("%s/%s: resolve sizing: %w", spec.Type, spec.Name, err)
203206
}
204207
if sizing != nil {
205-
if specs[i].Config == nil {
206-
specs[i].Config = map[string]any{}
208+
if spec.Config == nil {
209+
spec.Config = map[string]any{}
207210
}
208-
specs[i].Config["instance_type"] = sizing.InstanceType
211+
spec.Config["instance_type"] = sizing.InstanceType
209212
for k, v := range sizing.Specs {
210-
specs[i].Config[k] = v
213+
spec.Config[k] = v
211214
}
212215
}
213216
}
@@ -294,3 +297,15 @@ func applyWithProviderAndStore(ctx context.Context, provider interfaces.IaCProvi
294297
}
295298
return nil
296299
}
300+
301+
// isAbstractSize reports whether s is one of the canonical abstract size tiers
302+
// (xs/s/m/l/xl). Provider-specific slugs such as "db-s-1vcpu-1gb" return false
303+
// so that ResolveSizing is not called for already-concrete values.
304+
func isAbstractSize(s interfaces.Size) bool {
305+
switch s {
306+
case interfaces.SizeXS, interfaces.SizeS, interfaces.SizeM, interfaces.SizeL, interfaces.SizeXL:
307+
return true
308+
default:
309+
return false
310+
}
311+
}

0 commit comments

Comments
 (0)