Skip to content

Commit

Permalink
Merge pull request #36 from PlagueHO/dev
Browse files Browse the repository at this point in the history
Release 1.3.0.0
  • Loading branch information
PlagueHO authored Jul 20, 2019
2 parents 2720866 + 8a22397 commit 51fe7f3
Show file tree
Hide file tree
Showing 21 changed files with 2,251 additions and 1,129 deletions.
3 changes: 2 additions & 1 deletion .MetaTestOptIn.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"Common Tests - Custom Script Analyzer Rules",
"Common Tests - Validate Example Files To Be Published",
"Common Tests - Validate Markdown Links",
"Common Tests - Relative Path Length"
"Common Tests - Relative Path Length",
"Common Tests - Validate Localization"
]
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# Versions

## 1.3.0.0

- Opted into Common Tests 'Common Tests - Validate Localization' -
fixes [Issue #31](https://github.com/PlagueHO/FileContentDsc/issues/32).
- Combined all `FileContent.ResourceHelper` module functions into
`FileContent.Common` module - fixes [Issue #32](https://github.com/PlagueHO/FileContentDsc/issues/32).
- Renamed all localization strings so that they are detected by
'Common Tests - Validate Localization'.
- Correct style violations in unit tests:
- Adding `Get`, `Set` and `Test` tags to appropriate `describe` blocks.
- Removing uneccesary `#region` blocks.
- Conversion of double quotes to single quotes where possible.
- Replace variables with string litterals in `describe` block description.
- KeyValuePairFile:
- Improve unit tests to simplify and cover additional test cases.
- Fix error occuring when file is empty or does not exist - fixes [Issue #34](https://github.com/PlagueHO/FileContentDsc/issues/34).

## 1.2.0.0

- Added .VSCode settings for applying DSC PSSA rules - fixes [Issue #25](https://github.com/PlagueHO/FileContentDsc/issues/25).
Expand Down
71 changes: 29 additions & 42 deletions DSCResources/DSR_IniSettingsFile/DSR_IniSettingsFile.psm1
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
# Suppressed as per PSSA Rule Severity guidelines for unit/integration tests:
# https://github.com/PowerShell/DscResources/blob/master/PSSARuleSeverities.md
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')]
param ()

Set-StrictMode -Version 'Latest'

$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'

# Import the Storage Common Modules
# Import the Networking Common Modules
Import-Module -Name (Join-Path -Path $modulePath `
-ChildPath (Join-Path -Path 'FileContentDsc.Common' `
-ChildPath 'FileContentDsc.Common.psm1'))

# Import the Storage Resource Helper Module
Import-Module -Name (Join-Path -Path $modulePath `
-ChildPath (Join-Path -Path 'FileContentDsc.ResourceHelper' `
-ChildPath 'FileContentDsc.ResourceHelper.psm1'))

# Import Localization Strings
$localizedData = Get-LocalizedData `
-ResourceName 'DSR_IniSettingsFile' `
-ResourcePath (Split-Path -Parent $Script:MyInvocation.MyCommand.Path)
$script:localizedData = Get-LocalizedData -ResourceName 'DSR_IniSettingsFile'

<#
.SYNOPSIS
Expand All @@ -43,23 +31,23 @@ function Get-TargetResource
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Path,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Section,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Key
)

Assert-ParametersValid @PSBoundParameters

Write-Verbose -Message ($localizedData.GetIniSettingMessage -f `
Write-Verbose -Message ($script:localizedData.GetIniSettingMessage -f `
$Path, $Section, $Key)

$text = Get-IniSettingFileValue @PSBoundParameters
Expand Down Expand Up @@ -99,33 +87,31 @@ function Get-TargetResource
#>
function Set-TargetResource
{
# Should process is called in a helper functions but not directly in Set-TargetResource
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSShouldProcess', '')]
[CmdletBinding(SupportsShouldProcess = $true)]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Path,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Section,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Key,

[Parameter()]
[ValidateSet('Text', 'Secret')]
[String]
[System.String]
$Type = 'Text',

[Parameter()]
[String]
[System.String]
$Text,

[Parameter()]
Expand All @@ -143,15 +129,15 @@ function Set-TargetResource

if ($Type -eq 'Secret')
{
Write-Verbose -Message ($localizedData.SetIniSettingSecretMessage -f `
Write-Verbose -Message ($script:localizedData.SetIniSettingSecretMessage -f `
$Path, $Section, $Key)

$Text = $Secret.GetNetworkCredential().Password
$null = $PSBoundParameters.Remove('Secret')
}
else
{
Write-Verbose -Message ($localizedData.SetIniSettingTextMessage -f `
Write-Verbose -Message ($script:localizedData.SetIniSettingTextMessage -f `
$Path, $Section, $Key, $Text)
} # if

Expand Down Expand Up @@ -189,32 +175,32 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[OutputType([Boolean])]
[OutputType([System.Boolean])]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Path,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Section,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Key,

[Parameter()]
[ValidateSet('Text', 'Secret')]
[String]
[System.String]
$Type = 'Text',

[Parameter()]
[String]
[System.String]
$Text,

[Parameter()]
Expand Down Expand Up @@ -243,14 +229,14 @@ function Test-TargetResource

if ((Get-IniSettingFileValue @PSBoundParameters) -eq $Text)
{
Write-Verbose -Message ($localizedData.IniSettingMatchesMessage -f `
Write-Verbose -Message ($script:localizedData.IniSettingMatchesMessage -f `
$Path, $Section, $Key)

return $true
}
else
{
Write-Verbose -Message ($localizedData.IniSettingMismatchMessage -f `
Write-Verbose -Message ($script:localizedData.IniSettingMismatchMessage -f `
$Path, $Section, $Key)

return $false
Expand Down Expand Up @@ -289,26 +275,26 @@ function Assert-ParametersValid
(
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Path,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Section,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[String]
[System.String]
$Key,

[Parameter()]
[ValidateSet('Text', 'Secret')]
[String]
[System.String]
$Type = 'Text',

[Parameter()]
[String]
[System.String]
$Text,

[Parameter()]
Expand All @@ -319,10 +305,11 @@ function Assert-ParametersValid

# Does the file's parent path exist?
$parentPath = Split-Path -Path $Path -Parent

if (-not (Test-Path -Path $parentPath))
{
New-InvalidArgumentException `
-Message ($localizedData.FileParentNotFoundError -f $parentPath) `
-Message ($script:localizedData.FileParentNotFoundError -f $parentPath) `
-ArgumentName 'Path'
} # if
}
Expand Down
Loading

0 comments on commit 51fe7f3

Please sign in to comment.