Skip to content

Commit

Permalink
SqlServerDsc: clean up code in commands (#1936)
Browse files Browse the repository at this point in the history
- SqlServerDsc
  - Fix style changes in all private and public commands.
  • Loading branch information
johlju authored May 9, 2023
1 parent fccdb73 commit f9bde8a
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 63 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"Dbcc",
"creplace",
"dbatools",
"db_datareader",
"fastbuild"
],
"cSpell.ignorePaths": [
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Re-enable integration tests for dbatools.
- Bumped dbatools to v2.0.1 for the integration tests.

### fixed
### Fixed

- SqlServerDsc
- Fix style changes in all private and public commands.
- `Import-SqlDscPreferredModule`
- Now when parameter `Force` is passed the command correctly invoke
`Get-SqlDscPreferredModule` using the parameter `Refresh`.
Expand Down
4 changes: 2 additions & 2 deletions source/Private/Assert-SetupActionProperties.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#>
function Assert-SetupActionProperties
{
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification='The command uses plural noun to describe that it contain a collection of asserts.')]
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'The command uses plural noun to describe that it contain a collection of asserts.')]
[CmdletBinding()]
param
(
Expand Down Expand Up @@ -54,7 +54,7 @@ function Assert-SetupActionProperties

$assertRequiredCommandParameterParameters = @{
BoundParameterList = $Property
RequiredParameter = $assertParameters
RequiredParameter = $assertParameters
IfParameterPresent = $assertParameters
}

Expand Down
36 changes: 18 additions & 18 deletions source/Private/Invoke-SetupAction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,13 @@ function Invoke-SetupAction

[Parameter(ParameterSetName = 'UsingConfigurationFile', Mandatory = $true)]
[ValidateScript({
if (-not (Test-Path -Path $_))
{
throw $script:localizedData.Server_ConfigurationFileNotFound
}
if (-not (Test-Path -Path $_))
{
throw $script:localizedData.Server_ConfigurationFileNotFound
}

return $true
})]
return $true
})]
[System.String]
$ConfigurationFile,

Expand Down Expand Up @@ -565,13 +565,13 @@ function Invoke-SetupAction

[Parameter(Mandatory = $true)]
[ValidateScript({
if (-not (Test-Path -Path (Join-Path -Path $_ -ChildPath 'setup.exe')))
{
throw $script:localizedData.Server_MediaPathNotFound
}
if (-not (Test-Path -Path (Join-Path -Path $_ -ChildPath 'setup.exe')))
{
throw $script:localizedData.Server_MediaPathNotFound
}

return $true
})]
return $true
})]
[System.String]
$MediaPath,

Expand Down Expand Up @@ -1479,12 +1479,12 @@ function Invoke-SetupAction
See issue https://github.com/dsccommunity/SqlServerDsc/issues/1254.
#>
$boundParameterName.Where( { $_ -in $pathParameter } ).ForEach({
# Must not change paths that reference a root directory (they are handle differently later)
if ($PSBoundParameters.$_ -notmatch '^[a-zA-Z]:\\$')
{
$PSBoundParameters.$_ = $PSBoundParameters.$_.TrimEnd('\')
}
})
# Must not change paths that reference a root directory (they are handle differently later)
if ($PSBoundParameters.$_ -notmatch '^[a-zA-Z]:\\$')
{
$PSBoundParameters.$_ = $PSBoundParameters.$_.TrimEnd('\')
}
})

# Loop through all bound parameters and build arguments for the setup executable.
foreach ($parameterName in $boundParameterName)
Expand Down
6 changes: 3 additions & 3 deletions source/Public/Disable-SqlDscAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function Disable-SqlDscAudit
{
$getSqlDscAuditParameters = @{
ServerObject = $ServerObject
Name = $Name
Refresh = $Refresh
ErrorAction = 'Stop'
Name = $Name
Refresh = $Refresh
ErrorAction = 'Stop'
}

# If this command does not find the audit it will throw an exception.
Expand Down
6 changes: 3 additions & 3 deletions source/Public/Enable-SqlDscAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function Enable-SqlDscAudit
{
$getSqlDscAuditParameters = @{
ServerObject = $ServerObject
Name = $Name
Refresh = $Refresh
ErrorAction = 'Stop'
Name = $Name
Refresh = $Refresh
ErrorAction = 'Stop'
}

# If this command does not find the audit it will throw an exception.
Expand Down
6 changes: 3 additions & 3 deletions source/Public/Get-SqlDscAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ function Get-SqlDscAudit
$missingAuditMessage = $script:localizedData.Audit_Missing -f $Name

$writeErrorParameters = @{
Message = $missingAuditMessage
Category = 'InvalidOperation'
ErrorId = 'GSDA0001' # cspell: disable-line
Message = $missingAuditMessage
Category = 'InvalidOperation'
ErrorId = 'GSDA0001' # cspell: disable-line
TargetObject = $Name
}

Expand Down
2 changes: 1 addition & 1 deletion source/Public/Get-SqlDscPreferredModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function Get-SqlDscPreferredModule
{
$errorMessage = $script:localizedData.PreferredModule_ModuleNotFound

# cSpell: disable-next
# cSpell: disable-next
Write-Error -Message $errorMessage -Category 'ObjectNotFound' -ErrorId 'GSDPM0001' -TargetObject ($Name -join ', ')
}

Expand Down
4 changes: 2 additions & 2 deletions source/Public/Get-SqlDscServerPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function Get-SqlDscServerPermission
$getSqlDscServerPermissionResult = $null

$testSqlDscIsLoginParameters = @{
ServerObject = $ServerObject
Name = $Name
ServerObject = $ServerObject
Name = $Name
}

$isLogin = Test-SqlDscIsLogin @testSqlDscIsLoginParameters
Expand Down
6 changes: 3 additions & 3 deletions source/Public/Invoke-SqlDscQuery.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ function Invoke-SqlDscQuery
catch
{
$writeErrorParameters = @{
Message = $_.Exception.ToString()
Category = 'InvalidOperation'
ErrorId = 'ISDQ0001' # cSpell: disable-line
Message = $_.Exception.ToString()
Category = 'InvalidOperation'
ErrorId = 'ISDQ0001' # cSpell: disable-line
TargetObject = $DatabaseName
}

Expand Down
6 changes: 3 additions & 3 deletions source/Public/New-SqlDscAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ function New-SqlDscAudit

$getSqlDscAuditParameters = @{
ServerObject = $ServerObject
Name = $Name
Refresh = $Refresh
ErrorAction = 'SilentlyContinue'
Name = $Name
Refresh = $Refresh
ErrorAction = 'SilentlyContinue'
}

$auditObject = Get-SqlDscAudit @getSqlDscAuditParameters
Expand Down
6 changes: 3 additions & 3 deletions source/Public/Remove-SqlDscAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function Remove-SqlDscAudit
{
$getSqlDscAuditParameters = @{
ServerObject = $ServerObject
Name = $Name
Refresh = $Refresh
ErrorAction = 'Stop'
Name = $Name
Refresh = $Refresh
ErrorAction = 'Stop'
}

# If this command does not find the audit it will throw an exception.
Expand Down
30 changes: 15 additions & 15 deletions source/Public/Set-SqlDscAudit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ function Set-SqlDscAudit

[Parameter()]
[ValidateScript({
if ($_ -in 1..999 -or $_ -gt 2147483647)
{
throw ($script:localizedData.Audit_QueueDelayParameterValueInvalid -f $_)
}
if ($_ -in 1..999 -or $_ -gt 2147483647)
{
throw ($script:localizedData.Audit_QueueDelayParameterValueInvalid -f $_)
}

return $true
})]
return $true
})]
[System.UInt32]
$QueueDelay,

Expand Down Expand Up @@ -200,13 +200,13 @@ function Set-SqlDscAudit
[Parameter(ParameterSetName = 'AuditObjectWithSizeAndMaxFiles', Mandatory = $true)]
[Parameter(ParameterSetName = 'AuditObjectWithSizeAndMaxRolloverFiles', Mandatory = $true)]
[ValidateScript({
if ($_ -eq 1 -or $_ -gt 2147483647)
{
throw ($script:localizedData.Audit_MaximumFileSizeParameterValueInvalid -f $_)
}
if ($_ -eq 1 -or $_ -gt 2147483647)
{
throw ($script:localizedData.Audit_MaximumFileSizeParameterValueInvalid -f $_)
}

return $true
})]
return $true
})]
[System.UInt32]
$MaximumFileSize,

Expand Down Expand Up @@ -254,9 +254,9 @@ function Set-SqlDscAudit
{
$getSqlDscAuditParameters = @{
ServerObject = $ServerObject
Name = $Name
Refresh = $Refresh
ErrorAction = 'Stop'
Name = $Name
Refresh = $Refresh
ErrorAction = 'Stop'
}

# If this command does not find the audit it will throw an exception.
Expand Down
4 changes: 2 additions & 2 deletions source/Public/Set-SqlDscDatabasePermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function Set-SqlDscDatabasePermission
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
$missingPrincipalMessage,
'GSDDP0001',
'GSDDP0001', # cSpell: disable-line
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Name
)
Expand All @@ -208,7 +208,7 @@ function Set-SqlDscDatabasePermission
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
$missingDatabaseMessage,
'GSDDP0002',
'GSDDP0002', # cSpell: disable-line
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$DatabaseName
)
Expand Down
6 changes: 3 additions & 3 deletions source/Public/Set-SqlDscServerPermission.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ function Set-SqlDscServerPermission
}

$testSqlDscIsLoginParameters = @{
ServerObject = $ServerObject
Name = $Name
ServerObject = $ServerObject
Name = $Name
}

$isLogin = Test-SqlDscIsLogin @testSqlDscIsLoginParameters
Expand Down Expand Up @@ -172,7 +172,7 @@ function Set-SqlDscServerPermission
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
$missingPrincipalMessage,
'GSDDP0001',
'GSDDP0001', # cSpell: disable-line
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$Name
)
Expand Down
2 changes: 1 addition & 1 deletion source/Public/Test-SqlDscIsDatabasePrincipal.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function Test-SqlDscIsDatabasePrincipal
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
($script:localizedData.IsDatabasePrincipal_DatabaseMissing -f $DatabaseName),
'TSDISO0001',
'TSDISO0001', # cSpell: disable-line
[System.Management.Automation.ErrorCategory]::InvalidOperation,
$DatabaseName
)
Expand Down

0 comments on commit f9bde8a

Please sign in to comment.