Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqlServerDsc: Add Script Analyzer rule to help detect if resource do not load SMO #1684

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
6 changes: 5 additions & 1 deletion .vscode/analyzersettings.psd1
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
@{
CustomRulePath = '.\output\RequiredModules\DscResource.AnalyzerRules'
# There is a bug when using an array of paths here. No custom rules are used at all.
CustomRulePath = @(
'.\output\RequiredModules\DscResource.AnalyzerRules'
'.\tests\QA\AnalyzerRules\SqlServerDsc.AnalyzerRules.psm1'
)
IncludeDefaultRules = $true
IncludeRules = @(
# DSC Resource Kit style guideline rules.
Expand Down
29 changes: 22 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- SqlTraceFlag
- Fixed Assembly not loaded error
([issue #1680](https://github.com/dsccommunity/SqlServerDsc/issues/1680)).
### Added

- SqlServerDsc
- Added a new script analyzer rule to verify that `Import-SQLPSModule` or `Connect-SQL`
(that implicitly calls `Import-SQLPSModule`) is present in each `Get-`, `Test-`,
and `Set-TargetResource` function. If neither command is not needed then the
analyzer rule should be overridden ([issue #1683](https://github.com/dsccommunity/SqlServerDsc/issues/1683)).
- Added a new pipeline job that runs Script Analyzer on all PowerShell scripts
in the source folder. The rules are defined by the Script Analyzer settings
file `.vscode\analyzersettings.psd1` (which also the Visual Studio Code
PowerShell extension uses).
- Added unit tests and integration tests for SQL Server 2019
([issue #1310](https://github.com/dsccommunity/SqlServerDsc/issues/1310)).

### Changed

- SqlServerDsc
- Suppressed new custom Script Analyzer rule `SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO`
for `Get-`, `Test-`, and `Set-TargetResource` functions in the resources.
- SqlLogin
- Added functionality to throw exception if an update to the `LoginMustChangePassword`
value on an existing SQL Login is attempted. This functionality is not supported
Expand All @@ -28,10 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
of these properties that have to transition through an invalid combination (e.g.
where `PasswordExpirationEnabled` is `$true` but `PasswordPolicyEnforced` is
`$false`).

- SqlServerDsc
- Added unit tests and integration tests for SQL Server 2019
([issue #1310](https://github.com/dsccommunity/SqlServerDsc/issues/1310)).
- SqlSetup
- Minor refactor due to source code lint errors. The loop what evaluates
the configuration parameters `*FailoverCluster` was change to a `foreach()`.

### Fixed

Expand All @@ -40,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
configured when the repository moved to the new default branch `main`.
It no longer throws an error when using newer versions of GitVersion
([issue #1674](https://github.com/dsccommunity/SqlServerDsc/issues/1674)).
- Minor lint errors throughout the repository.
- SqlLogin
- Added integration tests to assert `LoginPasswordExpirationEnabled`,
`LoginPasswordPolicyEnforced` and `LoginMustChangePassword` properties/parameters
Expand All @@ -56,6 +69,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
argument is no longer wrongly added ([issue #1401](https://github.com/dsccommunity/SqlServerDsc/issues/1401)).
- SqlSetup
- Added/corrected `InstallSharedDir`, property output when using SQL Server 2019.
- SqlTraceFlag
- Fixed Assembly not loaded error ([issue #1680](https://github.com/dsccommunity/SqlServerDsc/issues/1680)).

## [15.0.1] - 2021-01-09

Expand Down
6 changes: 6 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ stages:
downloadType: 'single'
artifactName: 'output'
downloadPath: '$(Build.SourcesDirectory)'
- pwsh: |
# Workaround for issue https://github.com/dsccommunity/DscResource.Test/issues/100
./build.ps1 -Task noop
Invoke-Pester -Script .\tests\QA -EnableExit
name: qualitytest
displayName: 'Run SqlServerDsc QA Test'
- task: PowerShell@2
name: test
displayName: 'Run HQRM Test'
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/DSC_SqlAG/DSC_SqlAG.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
#>
function Get-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-SQLAlwaysOnAvailabilityGroupListener is called')]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down Expand Up @@ -422,6 +423,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ function Set-TargetResource
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
}

}
else
{
Expand Down Expand Up @@ -298,6 +297,7 @@ function Set-TargetResource

function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
3 changes: 3 additions & 0 deletions source/DSCResources/DSC_SqlAlias/DSC_SqlAlias.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
#>
function Get-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='Neither command is needed for this resource since the resource modifies registry')]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down Expand Up @@ -130,6 +131,7 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='Neither command is needed for this resource since the resource modifies registry')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -261,6 +263,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='Neither command is needed for this resource since the resource modifies registry')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/DSC_SqlDatabase/DSC_SqlDatabase.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ $script:localizedData = Get-LocalizedData -DefaultUICulture 'en-US'
#>
function Get-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-DatabaseObject is called')]
[CmdletBinding()]
[OutputType([System.Collections.Hashtable])]
param
Expand Down Expand Up @@ -237,6 +238,7 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql will be implicitly called in the call to Compare-TargetResourceState')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -518,6 +520,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql will be implicitly called in the call to Compare-TargetResourceState')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -310,7 +311,6 @@ function Set-TargetResource

$recreateDatabaseUser = $true
}

}
}

Expand Down Expand Up @@ -444,6 +444,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down Expand Up @@ -600,15 +601,14 @@ function ConvertTo-UserType
'NoLogin'
}

Default
default
{
$LoginType
}
}

}

Default
default
{
$errorMessage = $script:localizedData.UnknownAuthenticationType -f $AuthenticationType, $LoginType
New-InvalidOperationException -Message $errorMessage
Expand Down
3 changes: 2 additions & 1 deletion source/DSCResources/DSC_SqlEndpoint/DSC_SqlEndpoint.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down Expand Up @@ -570,7 +571,7 @@ function Test-TargetResource
}
}

if ($getTargetResourceResult.EndpointType -in @('DatabaseMirroring','ServiceBroker'))
if ($getTargetResourceResult.EndpointType -in @('DatabaseMirroring', 'ServiceBroker'))
{
if ($PSBoundParameters.ContainsKey('IsMessageForwardingEnabled'))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/DSC_SqlMaxDop/DSC_SqlMaxDop.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
1 change: 1 addition & 0 deletions source/DSCResources/DSC_SqlMemory/DSC_SqlMemory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Connect-Sql is called when Get-TargetResource is called')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
2 changes: 2 additions & 0 deletions source/DSCResources/DSC_SqlProtocol/DSC_SqlProtocol.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function Get-TargetResource
#>
function Set-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called when calling Compare-TargetResourceState')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -414,6 +415,7 @@ function Set-TargetResource
#>
function Test-TargetResource
{
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('SqlServerDsc.AnalyzerRules\Measure-CommandsNeededToLoadSMO', '', Justification='The command Import-SQLPSModule is implicitly called when calling Compare-TargetResourceState')]
[CmdletBinding()]
[OutputType([System.Boolean])]
param
Expand Down
Loading