Skip to content

Commit

Permalink
BREAKING CHANGE: SqlDatabaseOwner/Permission/Role: Update parameter D…
Browse files Browse the repository at this point in the history
…atabase to DatabaseName (#1507)

- BREAKING CHANGE: Database changed to DatabaseName for consistency with other modules.
  ([issue #1484](#1484)).
  - SqlDatabaseOwner
  - SqlDatabasePermission
  - SqlDatabaseRole
- README.md
  - Changed to point to CONTRIBUTING.md on master branch to avoid "404 Page not found" (issue #1508).
  • Loading branch information
Rob-S authored Apr 25, 2020
1 parent 2f60d0f commit 8ec8095
Show file tree
Hide file tree
Showing 21 changed files with 249 additions and 237 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md)

## [Unreleased]

### Changed

- BREAKING CHANGE: Database changed to DatabaseName for consistency with other modules.
([issue #1484](https://github.com/dsccommunity/SqlServerDsc/issues/1484)).
- SqlDatabaseOwner
- SqlDatabasePermission
- SqlDatabaseRole

- README.md
([issue #1508](https://github.com/dsccommunity/SqlServerDsc/issues/1508)).
- Changed to point to CONTRIBUTING.md on master branch to avoid "404 Page not found"

## [13.5.0] - 2020-04-12

### Added
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ full release to [PowerShell Gallery](https://www.powershellgallery.com/).
## Contributing

Please check out common DSC Community [contributing guidelines](https://dsccommunity.org/guidelines/contributing)
and the specific [Contributing to SqlServerDsc](https://github.com/dsccommunity/SqlServerDsc/blob/dev/CONTRIBUTING.md)
and the specific [Contributing to SqlServerDsc](https://github.com/dsccommunity/SqlServerDsc/blob/master/CONTRIBUTING.md)
guidelines.

## Installation
Expand Down Expand Up @@ -652,7 +652,7 @@ For more information about database owner, please read the article

#### Parameters

* **`[String]` Database** _(Key)_: The name of database to be configured.
* **`[String]` DatabaseName** _(Key)_: The name of database to be configured.
* **`[String]` Name** _(Required)_: The name of the login that will become a owner
of the desired sql database.
* **`[String]` ServerName** _(Write)_: The host name of the SQL Server to be configured.
Expand Down Expand Up @@ -687,7 +687,7 @@ will also get their permission revoked.
Default values is '$env:COMPUTERNAME'.
* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured.
Default value is 'MSSQLSERVER'.
* **`[String]` Database** _(Key)_: The name of the database.
* **`[String]` DatabaseName** _(Key)_: The name of the database.
* **`[String]` Name** _(Key)_: The name of the user that should be granted or denied
the permission.
* **`[String]` PermissionState** _(Key)_: The state of the permission.
Expand Down Expand Up @@ -753,7 +753,7 @@ manages members in both built-in and user created database roles.

* **`[String]` ServerName** _(Key)_: The host name of the SQL Server to be configured.
* **`[String]` InstanceName** _(Key)_: The name of the SQL instance to be configured.
* **`[String]` Database** _(Key)_: The name of the database in which the role should
* **`[String]` DatabaseName** _(Key)_: The name of the database in which the role should
be configured.
* **`[String]` Name** _(Key)_: The name of the database role to be added or removed.
* **`[String[]]` Members** _(Write)_: The members the database role should have.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabaseOwner'
.SYNOPSIS
This function gets the owner of the desired sql database.
.PARAMETER Database
.PARAMETER DatabaseName
The name of database to be configured.
.PARAMETER Name
Expand All @@ -31,7 +31,7 @@ function Get-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Database,
$DatabaseName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
Expand All @@ -50,7 +50,7 @@ function Get-TargetResource
)

Write-Verbose -Message (
$script:localizedData.GetCurrentDatabaseOwner -f $Database, $InstanceName
$script:localizedData.GetCurrentDatabaseOwner -f $DatabaseName, $InstanceName
)

try
Expand All @@ -59,27 +59,27 @@ function Get-TargetResource
if ($sqlServerObject)
{
# Check database exists
if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$Database]) )
if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$DatabaseName]) )
{
$errorMessage = $script:localizedData.DatabaseNotFound -f $Database
$errorMessage = $script:localizedData.DatabaseNotFound -f $DatabaseName
New-ObjectNotFoundException -Message $errorMessage
}

$sqlDatabaseOwner = $sqlDatabaseObject.Owner

Write-Verbose -Message (
$script:localizedData.CurrentDatabaseOwner -f $Database, $sqlDatabaseOwner
$script:localizedData.CurrentDatabaseOwner -f $DatabaseName, $sqlDatabaseOwner
)
}
}
catch
{
$errorMessage = $script:localizedData.FailedToGetOwnerDatabase -f $Database
$errorMessage = $script:localizedData.FailedToGetOwnerDatabase -f $DatabaseName
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}

$returnValue = @{
Database = $Database
DatabaseName = $DatabaseName
Name = $sqlDatabaseOwner
ServerName = $ServerName
InstanceName = $InstanceName
Expand All @@ -92,7 +92,7 @@ function Get-TargetResource
.SYNOPSIS
This function sets the owner of the desired sql database.
.PARAMETER Database
.PARAMETER DatabaseName
The name of database to be configured.
.PARAMETER Name
Expand All @@ -112,7 +112,7 @@ function Set-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Database,
$DatabaseName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
Expand All @@ -134,9 +134,9 @@ function Set-TargetResource
if ($sqlServerObject)
{
# Check database exists
if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$Database]) )
if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$DatabaseName]) )
{
$errorMessage = $script:localizedData.DatabaseNotFound -f $Database
$errorMessage = $script:localizedData.DatabaseNotFound -f $DatabaseName
New-ObjectNotFoundException -Message $errorMessage
}

Expand All @@ -148,7 +148,7 @@ function Set-TargetResource
}

Write-Verbose -Message (
$script:localizedData.SetDatabaseOwner -f $Database, $InstanceName
$script:localizedData.SetDatabaseOwner -f $DatabaseName, $InstanceName
)

try
Expand All @@ -161,7 +161,7 @@ function Set-TargetResource
}
catch
{
$errorMessage = $script:localizedData.FailedToSetOwnerDatabase -f $Database
$errorMessage = $script:localizedData.FailedToSetOwnerDatabase -f $DatabaseName
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
}
Expand All @@ -171,7 +171,7 @@ function Set-TargetResource
.SYNOPSIS
This function tests the owner of the desired sql database.
.PARAMETER Database
.PARAMETER DatabaseName
The name of database to be configured.
.PARAMETER Name
Expand All @@ -192,7 +192,7 @@ function Test-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Database,
$DatabaseName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
Expand All @@ -211,13 +211,13 @@ function Test-TargetResource
)

Write-Verbose -Message (
$script:localizedData.TestingConfiguration -f $Database, $InstanceName
$script:localizedData.TestingConfiguration -f $DatabaseName, $InstanceName
)

$currentValues = Get-TargetResource @PSBoundParameters
return Test-DscParameterState -CurrentValues $CurrentValues `
-DesiredValues $PSBoundParameters `
-ValuesToCheck @('Name', 'Database')
-ValuesToCheck @('Name', 'DatabaseName')
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[ClassVersion("1.0.0.0"), FriendlyName("SqlDatabaseOwner")]
class MSFT_SqlDatabaseOwner : OMI_BaseResource
{
[Key, Description("The name of database to be configured.")] String Database;
[Key, Description("The name of database to be configured.")] String DatabaseName;
[Required, Description("The name of the login that will become a owner of the desired sql database.")] String Name;
[Write, Description("The host name of the SQL Server to be configured.")] String ServerName;
[Key, Description("The name of the SQL instance to be configured.")] String InstanceName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $script:localizedData = Get-LocalizedData -ResourceName 'MSFT_SqlDatabasePermiss
.SYNOPSIS
Returns the current permissions for the user in the database
.PARAMETER Database
.PARAMETER DatabaseName
This is the SQL database
.PARAMETER Name
Expand All @@ -37,7 +37,7 @@ function Get-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Database,
$DatabaseName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -66,15 +66,15 @@ function Get-TargetResource
)

Write-Verbose -Message (
$script:localizedData.GetDatabasePermission -f $Name, $Database, $InstanceName
$script:localizedData.GetDatabasePermission -f $Name, $DatabaseName, $InstanceName
)

$sqlServerObject = Connect-SQL -ServerName $ServerName -InstanceName $InstanceName
if ($sqlServerObject)
{
$currentEnsure = 'Absent'

if ($sqlDatabaseObject = $sqlServerObject.Databases[$Database])
if ($sqlDatabaseObject = $sqlServerObject.Databases[$DatabaseName])
{
if ($sqlServerObject.Logins[$Name])
{
Expand Down Expand Up @@ -102,7 +102,7 @@ function Get-TargetResource
}
catch
{
$errorMessage = $script:localizedData.FailedToEnumDatabasePermissions -f $Name, $Database
$errorMessage = $script:localizedData.FailedToEnumDatabasePermissions -f $Name, $DatabaseName
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}

Expand All @@ -115,7 +115,7 @@ function Get-TargetResource
}
else
{
$errorMessage = $script:localizedData.DatabaseNotFound -f $Database
$errorMessage = $script:localizedData.DatabaseNotFound -f $DatabaseName
New-ObjectNotFoundException -Message $errorMessage
}

Expand All @@ -132,7 +132,7 @@ function Get-TargetResource

return @{
Ensure = $currentEnsure
Database = $Database
DatabaseName = $DatabaseName
Name = $Name
PermissionState = $PermissionState
Permissions = $getSqlDatabasePermissionResult
Expand All @@ -148,7 +148,7 @@ function Get-TargetResource
.PARAMETER Ensure
This is The Ensure if the permission should be granted (Present) or revoked (Absent)
.PARAMETER Database
.PARAMETER DatabaseName
This is the SQL database
.PARAMETER Name
Expand Down Expand Up @@ -179,7 +179,7 @@ function Set-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Database,
$DatabaseName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -211,10 +211,10 @@ function Set-TargetResource
if ($sqlServerObject)
{
Write-Verbose -Message (
$script:localizedData.ChangePermissionForUser -f $Name, $Database, $InstanceName
$script:localizedData.ChangePermissionForUser -f $Name, $DatabaseName, $InstanceName
)

if ($sqlDatabaseObject = $sqlServerObject.Databases[$Database])
if ($sqlDatabaseObject = $sqlServerObject.Databases[$DatabaseName])
{
if ($sqlServerObject.Logins[$Name])
{
Expand All @@ -224,7 +224,7 @@ function Set-TargetResource
{
Write-Verbose -Message (
'{0} {1}' -f
($script:localizedData.LoginIsNotUser -f $Name, $Database),
($script:localizedData.LoginIsNotUser -f $Name, $DatabaseName),
$script:localizedData.AddingLoginAsUser
)

Expand All @@ -234,7 +234,7 @@ function Set-TargetResource
}
catch
{
$errorMessage = $script:localizedData.FailedToAddUser -f $Name, $Database
$errorMessage = $script:localizedData.FailedToAddUser -f $Name, $DatabaseName
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
}
Expand All @@ -255,7 +255,7 @@ function Set-TargetResource
'Present'
{
Write-Verbose -Message (
$script:localizedData.AddPermission -f $PermissionState, ($Permissions -join ','), $Database
$script:localizedData.AddPermission -f $PermissionState, ($Permissions -join ','), $DatabaseName
)

switch ($PermissionState)
Expand All @@ -280,7 +280,7 @@ function Set-TargetResource
'Absent'
{
Write-Verbose -Message (
$script:localizedData.DropPermission -f $PermissionState, ($Permissions -join ','), $Database
$script:localizedData.DropPermission -f $PermissionState, ($Permissions -join ','), $DatabaseName
)

if ($PermissionState -eq 'GrantWithGrant')
Expand All @@ -296,7 +296,7 @@ function Set-TargetResource
}
catch
{
$errorMessage = $script:localizedData.FailedToSetPermissionDatabase -f $Name, $Database
$errorMessage = $script:localizedData.FailedToSetPermissionDatabase -f $Name, $DatabaseName
New-InvalidOperationException -Message $errorMessage -ErrorRecord $_
}
}
Expand All @@ -309,7 +309,7 @@ function Set-TargetResource
}
else
{
$errorMessage = $script:localizedData.DatabaseNotFound -f $Database
$errorMessage = $script:localizedData.DatabaseNotFound -f $DatabaseName
New-ObjectNotFoundException -Message $errorMessage
}
}
Expand All @@ -322,7 +322,7 @@ function Set-TargetResource
.PARAMETER Ensure
This is The Ensure if the permission should be granted (Present) or revoked (Absent)
.PARAMETER Database
.PARAMETER DatabaseName
This is the SQL database
.PARAMETER Name
Expand Down Expand Up @@ -354,7 +354,7 @@ function Test-TargetResource
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[System.String]
$Database,
$DatabaseName,

[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
Expand Down Expand Up @@ -383,13 +383,13 @@ function Test-TargetResource
)

Write-Verbose -Message (
$script:localizedData.TestingConfiguration -f $Name, $Database, $InstanceName
$script:localizedData.TestingConfiguration -f $Name, $DatabaseName, $InstanceName
)

$getTargetResourceParameters = @{
InstanceName = $PSBoundParameters.InstanceName
ServerName = $PSBoundParameters.ServerName
Database = $PSBoundParameters.Database
DatabaseName = $PSBoundParameters.DatabaseName
Name = $PSBoundParameters.Name
PermissionState = $PSBoundParameters.PermissionState
Permissions = $PSBoundParameters.Permissions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
class MSFT_SqlDatabasePermission : OMI_BaseResource
{
[Write, Description("If the values should be present or absent. Valid values are 'Present' or 'Absent'."), ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
[Key, Description("The name of the database.")] String Database;
[Key, Description("The name of the database.")] String DatabaseName;
[Key, Description("The name of the user that should be granted or denied the permission.")] String Name;
[Key, Description("The state of the permission. Valid values are 'Grant' or 'Deny'."), ValueMap{"Grant","Deny","GrantWithGrant"}, Values{"Grant","Deny","GrantWithGrant"}] String PermissionState;
[Required, Description("The set of permissions for the SQL database.")] String Permissions[];
Expand Down
Loading

0 comments on commit 8ec8095

Please sign in to comment.