refactor: centralize and consolidate benchmark targets - #272
Open
jon-wang-ibm wants to merge 11 commits into
Open
refactor: centralize and consolidate benchmark targets#272jon-wang-ibm wants to merge 11 commits into
jon-wang-ibm wants to merge 11 commits into
Conversation
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
marked this pull request as ready for review
August 12, 2026 23:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
const → init() → attack struct → config structs → ParseConfig → Setup → Target → Cleanup → GetTargetInfo → Flags → private helperspathPrefix → header → body → roleName → action → config → logger → cleanup-only fieldsCleanup consolidation
logging.go: singlecleanupMount(logger, client, pathPrefix)that detects auth vs secret mounts from the path prefix (/v1/auth/→/sys/auth/, otherwise →/sys/mounts/); affects 31 secret + 12 authCleanupbodies with one callSetup consolidation
utils.go:resolveMountPath(base, random)replaces 48 identicalRandomMountsblocks across all targets; 44go-uuidimports removedutils.go:writeStruct(client, path, in)foldsstructToMap + Logical().Write + both error checksinto one call; 75 pairs replaced across 41 filesbuildResult(client, secretPath, action, keyName, configData)extracts the repeatedjson.Marshal → return &{Type}{pathPrefix, header, body, logger}tail from every action arm; each arm now contains only its unique seeding logicSwitch 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/kvv2read()/write(),totpcreate()/generate()/read(),sync_awsevents()/write()/read()all inlined intoTarget();totpmutablekeyIndexremoved (was not concurrency-safe); replaced withrand.Int63()suffix per tickSetup()logger-name switches:typeKeyfield set ininit()for transit, gcpkms, totp;SetupusestargetLogger.Named(t.typeKey)instead of a per-action switchSetup: redundant two-arm switch calling identicalcreateKeyin both arms collapsed to unconditional callTarget():SecretTypebranch precomputed astargetURLinSetup;configdropped from attack structModernization
interface{}→anyincommand/base_flags.go(12Get()methods) andconfig/config.gofor i := 0; i < len(...)→for range/for i := range ninbenchmark_targets.goandtarget_sync_aws.goioutil.ReadFile→os.ReadFile;ioutil.Discard→io.Discard;io/ioutilremovedstringsimport removed from 31 files where it was only used for the now-extracted cleanup patternNaming convention
target_[type]_[method]→[Method][Type]:target_auth_*→*Auth,target_secret_*→*Secret,target_sync_aws→AWSSync,target_sys_status→SysStatus*AuthConfig/*SecretConfig(removedTestandSecretinfixes from ~40 names)<Engine><Subtype>Configapplied uniformly; auth mount configs disambiguated to<Engine>AuthMountConfigwhere needed to avoid collision with the renamed top-level wrapperTransitConfigSign→TransitSignConfig, etc.)Testinfix replaced withSecret(GCPKMSSecretMountConfig,GCPKMSSecretEncryptConfig, etc.)Correctness
SecretIDNumUsestypo fixed in approlelog.Fatalf→return nil, fmt.Errorfin cert auth (3 calls);"log"import removederrCount→[]error+errors.Joinin benchmark target cleanup"POST"/"GET"string literals → named constants across all targetsTODOs as contracts
benchmark_targets.go:GetTargetInfocollapse intoConfigureTarget— deferred; requires touching all 50+ targetsbenchmark_targets.go: singleTestListregistration per engine for transit/gcpkms/totp (identity pattern) — deferred; breaking HCL interface change (transit_sign→transitwithactionin config block)Validation
go build ./... go vet ./... go test -race ./benchmarktests/... ./config/...