Skip to content

Commit

Permalink
Add default baseline #126 (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite authored Sep 24, 2019
1 parent f123e87 commit 8bec63d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change log

## Unreleased

- Added default baseline to module. [#126](https://github.com/BernieWhite/PSRule.Rules.Azure/issues/126)

## v0.4.0-B190902 (pre-release)

- Added rule to verify connectivity of VNET peers. [#120](https://github.com/BernieWhite/PSRule.Rules.Azure/issues/120)
Expand Down
5 changes: 4 additions & 1 deletion pipeline.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function CopyModuleFiles {
process {
$sourcePath = Resolve-Path -Path $Path;

Get-ChildItem -Path $sourcePath -Recurse -File -Include *.ps1,*.psm1,*.psd1,*.ps1xml | Where-Object -FilterScript {
Get-ChildItem -Path $sourcePath -Recurse -File -Include *.ps1,*.psm1,*.psd1,*.ps1xml,*.yaml | Where-Object -FilterScript {
($_.FullName -notmatch '(\.(cs|csproj)|(\\|\/)(obj|bin))')
} | ForEach-Object -Process {
$filePath = $_.FullName.Replace($sourcePath, $destinationPath);
Expand Down Expand Up @@ -108,6 +108,9 @@ task VersionModule ModuleDependencies, {
}
};
Update-ModuleManifest -Path $manifestPath -RequiredModules $requiredModules;
$manifestContent = Get-Content -Path $manifestPath -Raw;
$manifestContent = $manifestContent -replace 'PSRule = ''System.Collections.Hashtable''', 'PSRule = @{ Baseline = ''Azure.SubscriptionDefault'' }';
$manifestContent | Set-Content -Path $manifestPath;
}

# Synopsis: Publish to PowerShell Gallery
Expand Down
2 changes: 1 addition & 1 deletion src/PSRule.Rules.Azure/PSRule.Rules.Azure.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ PrivateData = @{
ReleaseNotes = 'https://github.com/BernieWhite/PSRule.Rules.Azure/blob/master/CHANGELOG.md'
} # End of PSData hashtable
PSRule = @{
Baseline = 'DefaultBaseline'
Baseline = 'Azure.SubscriptionDefault'
}
} # End of PrivateData hashtable

Expand Down
3 changes: 2 additions & 1 deletion src/PSRule.Rules.Azure/rules/Baseline.Rule.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@

---
# Synopsis: Default baseline for Azure rules
kind: Baseline
metadata:
name: DefaultBaseline
name: Azure.SubscriptionDefault
spec:
binding:
targetType:
Expand Down
33 changes: 33 additions & 0 deletions tests/PSRule.Rules.Azure.Tests/Azure.Baseline.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#
# Unit tests for baselines
#

[CmdletBinding()]
param (

)

# Setup error handling
$ErrorActionPreference = 'Stop';
Set-StrictMode -Version latest;

if ($Env:SYSTEM_DEBUG -eq 'true') {
$VerbosePreference = 'Continue';
}

# Setup tests paths
$rootPath = $PWD;
Import-Module (Join-Path -Path $rootPath -ChildPath out/modules/PSRule.Rules.Azure) -Force;
$here = (Resolve-Path $PSScriptRoot).Path;

Describe 'Baselines' -Tag Baseline {
$dataPath = Join-Path -Path $here -ChildPath 'Resources.Resource.json';

Context 'Binding' {
$result = Invoke-PSRule -Module PSRule.Rules.Azure -Outcome All -InputPath $dataPath -WarningAction Ignore -ErrorAction Stop;

It 'TargetType' {
$result.TargetType | Should -Not -BeIn 'System.Management.Automation.PSCustomObject';
}
}
}

0 comments on commit 8bec63d

Please sign in to comment.