Skip to content

refactor(Invoke-Logging): ignores pre-parsed script cache, rebuilds scriptblock on every call #30

@HeyItsGilbert

Description

@HeyItsGilbert

Summary

Import-GatekeeperConfig pre-parses logging scripts into $script:GatekeeperLogging. Invoke-Logging ignores this cache entirely and re-creates the scriptblock from raw config on every matching rule evaluation. Beyond the unnecessary overhead, calling [scriptblock]::Create() on a value that is already a scriptblock stringifies it first, losing any closure context.

File

Gatekeeper/Private/Invoke-Logging.ps1:17

Current Code

$sb = [scriptblock]::Create($logSettings.Script)   # ignores $script:GatekeeperLogging
& $sb -Rule $Rule

Fix

$sb = $script:GatekeeperLogging[$Effect]
if ($null -ne $sb) {
    & $sb -Rule $Rule
}

This also resolves the inconsistency where Test-FeatureFlag loads config in begin{} into an unused $config variable (that dead code can be removed, see Issue #24).

Notes

  • Found by Jordan B. and Sage Nakamura

Metadata

Metadata

Labels

ralphQueued for the ralph looprefactorCode quality, structure, or naming

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions