Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.3.1] 2026-01-23

### Changed

- Refactored logging execution to use dedicated `Invoke-Logging` function for

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [alex] reported by reviewdog 🐶
Be careful with execution, it’s profane in some cases execution retext-profanities

improved maintainability and consistency across feature flag evaluation.
- Fixed parameter name in `Test-FeatureFlag` from `Properties` to `PropertySet`
for consistency with function implementation.

### Fixed

- Fixed variable name reference in `Test-FeatureFlag` from `$Feature` to
`$FeatureFlag` to correctly process feature flag rules.

## [0.3.0] 2026-01-23

### Added
Expand All @@ -17,7 +31,7 @@
### Changed

- `Test-Condition` function now accepts `ConditionGroup` objects instead of
hashtables for the Condition parameter, providing stronger type safety.

Check warning on line 34 in CHANGELOG.md

View workflow job for this annotation

GitHub Actions / Continuous Integration / Run Linters

Unknown word (hashtables) Suggestions: (hashables, hashtable, hashable, hatable, hashtags)
- `Test-Condition` function now accepts `PropertySet` objects instead of a
generic Properties hashtable for the Properties parameter.
- Internal condition evaluation logic updated to use null checks on
Expand Down
2 changes: 1 addition & 1 deletion Gatekeeper/Gatekeeper.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'Gatekeeper.psm1'

# Version number of this module.
ModuleVersion = '0.3.0'
ModuleVersion = '0.3.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
22 changes: 22 additions & 0 deletions Gatekeeper/Private/Invoke-Logging.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function Invoke-Logging {
param (
[Parameter(Mandatory)]
[Effect]
$Effect,
[Parameter(Mandatory)]
[Rule]
$Rule
)
begin {
$config = Import-GatekeeperConfig
}
process {
$logSettings = $config.Logging.$Effect

if ($logSettings.Enabled) {
$sb = [scriptblock]::Create($logSettings.Script)
& $sb -Rule $Rule
}
}

}
18 changes: 9 additions & 9 deletions Gatekeeper/Public/Test-FeatureFlag.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
.PARAMETER FeatureFlag
The name of the feature flag to test.

.PARAMETER Properties
A hashtable of properties that define the different values in the context.
.PARAMETER PropertySet
A PropertySet that defines the different values in the context.

.PARAMETER Context
The context to use to test against.
Expand All @@ -30,7 +30,7 @@
$FeatureFlag,
[PropertySet]
[PropertySetTransformAttribute()]
$Properties,
$PropertySet,
[Parameter(Mandatory)]
[hashtable]
$Context
Expand All @@ -44,32 +44,32 @@
process {
# Process each feature
Write-Verbose "Processing Feature $($FeatureFlag.Name) with ($($FeatureFlag.Rules.Count)) rules"
foreach ($rule in $Feature.Rules) {
foreach ($rule in $FeatureFlag.Rules) {
Write-Verbose "Processing Rule $($rule.Name)"
$testConditionSplat = @{
Context = $Context
Properties = $Properties
PropertySet = $PropertySet
Condition = $rule.Conditions
}
if (Test-Condition @testConditionSplat) {
Write-Verbose "✅ Rule [$($rule.Name)] matched. Effect: $($rule.Effect)"
# Check effect
switch ($rule.Effect) {
'Allow' {
. $script:GatekeeperLogging['Allow'] -Rule $rule
Invoke-Logging -Effect 'Allow' -Rule $rule
$finalResult = $true
break
}
'Deny' {
. $script:GatekeeperLogging['Deny'] -Rule $rule
Invoke-Logging -Effect 'Deny' -Rule $rule
$finalResult = $false
break
}
'Audit' {
. $script:GatekeeperLogging['Audit'] -Rule $rule
Invoke-Logging -Effect 'Audit' -Rule $rule
}
'Warn' {
. $script:GatekeeperLogging['Warning'] -Rule $rule
Invoke-Logging -Effect 'Warn' -Rule $rule
}
default {
throw 'Unknown effect'
Expand Down
6 changes: 3 additions & 3 deletions docs/en-US/Test-FeatureFlag.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
## SYNTAX

```
Test-FeatureFlag [-FeatureFlag] <FeatureFlag> [[-Properties] <PropertySet>] [-Context] <Hashtable>
Test-FeatureFlag [-FeatureFlag] <FeatureFlag> [[-PropertySet] <PropertySet>] [-Context] <Hashtable>
[-ProgressAction <ActionPreference>] [<CommonParameters>]
```

Expand Down Expand Up @@ -49,8 +49,8 @@
Accept wildcard characters: False
```

### -Properties
A hashtable of properties that define the different values in the context.
### -PropertySet
A PropertySet that defines the different values in the context.

```yaml
Type: PropertySet
Expand Down Expand Up @@ -85,7 +85,7 @@
```yaml
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga

Check warning on line 88 in docs/en-US/Test-FeatureFlag.md

View workflow job for this annotation

GitHub Actions / Continuous Integration / Run Linters

Unknown word (proga) Suggestions: (proa, prog, progs, Prog, prgo)

Required: False
Position: Named
Expand Down
22 changes: 16 additions & 6 deletions tests/Test-FeatureFlag.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
BeforeDiscovery {
if ($env:BHPSModuleManifest -eq $null -or $env:BHProjectPath -eq $null -or $env:BHProjectName -eq $null) {
. $PSscriptRoot\..\build.ps1 -Task Build
}
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$outputDir = Join-Path -Path $env:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
$outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1"

# Get module commands
# Remove all versions of the module from the session. Pester can't handle multiple versions.
Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore
Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop
}
Describe 'Test-FeatureFlag' {
BeforeAll {
$script:propertySet = Read-PropertySet -File "$PSScriptRoot\fixtures\Properties.json"
$script:context = @{
Percentage = 30
Environment = 'Production'
Environment = 'Staging'
IsCompliant = $true
}
# load feature flag
$json = Get-Content -Path "$PSScriptRoot\fixtures\Updawg.json" -Raw | ConvertFrom-JsonToHashtable
$script:featureFlag = Read-FeatureFlag -FilePath "$PSScriptRoot\fixtures\FeatureFlag.json"

Mock -CommandName Invoke-Logging -ModuleName $env:BHProjectName -Verifiable
}

It 'Allows when rule matches with Allow effect' {
$result = Test-FeatureFlag -FeatureFlag $script:featureFlag -PropertySet $script:propertySet -Context $script:context
$result | Should -BeTrue

Assert-MockCalled -CommandName Invoke-Logging -ModuleName $env:BHProjectName -ParameterFilter {
$Effect -eq 'Allow'
} -Times 1
}
}