Skip to content

refactor: centralize and consolidate benchmark targets - #272

Open
jon-wang-ibm wants to merge 11 commits into
mainfrom
refactor/interface-any
Open

refactor: centralize and consolidate benchmark targets#272
jon-wang-ibm wants to merge 11 commits into
mainfrom
refactor/interface-any

Conversation

@jon-wang-ibm

@jon-wang-ibm jon-wang-ibm commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Centralizes and consolidates all benchmark targets: enforces a consistent method ordering, eliminates repeated cleanup and switch-statement boilerplate, modernizes Go idioms, and applies a uniform naming convention across all 50+ targets.

Changes

Method ordering

  • All targets follow: const → init() → attack struct → config structs → ParseConfig → Setup → Target → Cleanup → GetTargetInfo → Flags → private helpers
  • Attack struct field order: pathPrefix → header → body → roleName → action → config → logger → cleanup-only fields

Cleanup consolidation

  • logging.go: single cleanupMount(logger, client, pathPrefix) that detects auth vs secret mounts from the path prefix (/v1/auth//sys/auth/, otherwise → /sys/mounts/); affects 31 secret + 12 auth Cleanup bodies with one call

Setup consolidation

  • utils.go: resolveMountPath(base, random) replaces 48 identical RandomMounts blocks across all targets; 44 go-uuid imports removed
  • utils.go: writeStruct(client, path, in) folds structToMap + Logical().Write + both error checks into one call; 75 pairs replaced across 41 files
  • Transit and GCPKMS: buildResult(client, secretPath, action, keyName, configData) extracts the repeated json.Marshal → return &{Type}{pathPrefix, header, body, logger} tail from every action arm; each arm now contains only its unique seeding logic

Switch statement reduction

  • Target() switches: all multi-case switches restructured to build a default struct then patch only differing fields (identity, totp, sync_aws)
  • Target() helpers: kvv1/kvv2 read()/write(), totp create()/generate()/read(), sync_aws events()/write()/read() all inlined into Target(); totp mutable keyIndex removed (was not concurrency-safe); replaced with rand.Int63() suffix per tick
  • Setup() logger-name switches: typeKey field set in init() for transit, gcpkms, totp; Setup uses targetLogger.Named(t.typeKey) instead of a per-action switch
  • GCPKMS Setup: redundant two-arm switch calling identical createKey in both arms collapsed to unconditional call
  • GCP Target(): SecretType branch precomputed as targetURL in Setup; config dropped from attack struct

Modernization

  • interface{}any in command/base_flags.go (12 Get() methods) and config/config.go
  • for i := 0; i < len(...)for range / for i := range n in benchmark_targets.go and target_sync_aws.go
  • ioutil.ReadFileos.ReadFile; ioutil.Discardio.Discard; io/ioutil removed
  • strings import removed from 31 files where it was only used for the now-extracted cleanup pattern

Naming convention

  • All targets follow target_[type]_[method][Method][Type]: target_auth_**Auth, target_secret_**Secret, target_sync_awsAWSSync, target_sys_statusSysStatus
  • Top-level configs: *AuthConfig / *SecretConfig (removed Test and Secret infixes from ~40 names)
  • Sub-configs: <Engine><Subtype>Config applied uniformly; auth mount configs disambiguated to <Engine>AuthMountConfig where needed to avoid collision with the renamed top-level wrapper
  • Transit sub-configs: word order fixed (TransitConfigSignTransitSignConfig, etc.)
  • GCPKMS sub-configs: Test infix replaced with Secret (GCPKMSSecretMountConfig, GCPKMSSecretEncryptConfig, etc.)

Correctness

  • SecretIDNumUses typo fixed in approle
  • log.Fatalfreturn nil, fmt.Errorf in cert auth (3 calls); "log" import removed
  • errCount[]error + errors.Join in benchmark target cleanup
  • "POST"/"GET" string literals → named constants across all targets

TODOs as contracts

  • benchmark_targets.go: GetTargetInfo collapse into ConfigureTarget — deferred; requires touching all 50+ targets
  • benchmark_targets.go: single TestList registration per engine for transit/gcpkms/totp (identity pattern) — deferred; breaking HCL interface change (transit_signtransit with action in config block)

Validation

go build ./...
go vet ./...
go test -race ./benchmarktests/... ./config/...

updated each target to follow nil, fmt.Errorf() format, rather than the dangerous log.Fatalf. trimmed comment bloat and TODOs, and reordered identity structs to follow entity, alias, and group orderings
pathPrefix string    → location (always first, most referenced)
header     http.Header → auth material sent with every request
body       []byte    → request body (or cachedBody for AWS)
username   string    → only for URL-path targets (LDAP/RADIUS/Okta/userpass)
config     *Config   → only for AWS (needed at refresh time)
logger     hclog.Logger → last, least read in hot path
switch statements use a common default, reducing the amount of code copied
left a TODO to condense the testtypes, making it user facing. deferred to match target_identity.go
place the same 6 line into util to be used project wide
Convention is now fully uniform: target_auth_* → *Auth / *AuthConfig, target_secret_* → *Secret / *SecretConfig, target_sync_* → *Sync, target_sys_* → Sys*. Identity stays as-is — it's neither auth nor secret.
@jon-wang-ibm
jon-wang-ibm marked this pull request as ready for review August 12, 2026 23:44
@jon-wang-ibm
jon-wang-ibm requested a review from a team as a code owner August 12, 2026 23:44
@jon-wang-ibm jon-wang-ibm changed the title refactor: replace interface{} with any across secret targets and utils refactor: centralize and consolidate benchmark targets Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant