Skip to content

Commit

Permalink
Changes to SqlServerOwner
Browse files Browse the repository at this point in the history
  - BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
    to ServerName and InstanceName respectivly (issue dsccommunity#308).
  • Loading branch information
johlju committed Dec 1, 2017
1 parent db79290 commit 7489e85
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 98 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
- Changes to SqlServerEndpoint
- BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).
- Changes to SqlServerOwner
- BREAKING CHANGE: Parameters SQLServer and SQLInstanceName has been renamed
to ServerName and InstanceName respectivly ([issue #308](https://github.com/PowerShell/xSQLServer/issues/)).

## 8.2.0.0

Expand Down
46 changes: 23 additions & 23 deletions DSCResources/MSFT_SqlDatabaseOwner/MSFT_SqlDatabaseOwner.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ Import-Module -Name (Join-Path -Path (Split-Path (Split-Path $PSScriptRoot -Pare
.PARAMETER Name
The name of the login that will become a owner of the desired sql database.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
#>
function Get-TargetResource
Expand All @@ -36,24 +36,24 @@ function Get-TargetResource
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLServer = $env:COMPUTERNAME,
$ServerName = $env:COMPUTERNAME,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLInstanceName = 'MSSQLSERVER'
$InstanceName = 'MSSQLSERVER'
)

Write-Verbose -Message "Getting owner of database $Database"
$sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

if ($sqlServerObject)
{
# Check database exists
if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$Database]) )
{
throw New-TerminatingError -ErrorType NoDatabase `
-FormatArgs @($Database, $SQLServer, $SQLInstanceName) `
-FormatArgs @($Database, $ServerName, $InstanceName) `
-ErrorCategory ObjectNotFound
}

Expand All @@ -65,16 +65,16 @@ function Get-TargetResource
catch
{
throw New-TerminatingError -ErrorType FailedToGetOwnerDatabase `
-FormatArgs @($Database, $SQLServer, $SQLInstanceName) `
-FormatArgs @($Database, $ServerName, $InstanceName) `
-ErrorCategory InvalidOperation
}
}

$returnValue = @{
Database = $Database
Name = $sqlDatabaseOwner
SQLServer = $SQLServer
SQLInstanceName = $SQLInstanceName
Database = $Database
Name = $sqlDatabaseOwner
ServerName = $ServerName
InstanceName = $InstanceName
}

$returnValue
Expand All @@ -90,10 +90,10 @@ function Get-TargetResource
.PARAMETER Name
The name of the login that will become a owner of the desired sql database.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
#>
function Set-TargetResource
Expand All @@ -114,29 +114,29 @@ function Set-TargetResource
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLServer = $env:COMPUTERNAME,
$ServerName = $env:COMPUTERNAME,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLInstanceName = 'MSSQLSERVER'
$InstanceName = 'MSSQLSERVER'
)

Write-Verbose -Message "Setting owner $Name of database $Database"
$sqlServerObject = Connect-SQL -SQLServer $SQLServer -SQLInstanceName $SQLInstanceName
$sqlServerObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

if ($sqlServerObject)
{
# Check database exists
if ( -not ($sqlDatabaseObject = $sqlServerObject.Databases[$Database]) )
{
throw New-TerminatingError -ErrorType NoDatabase -FormatArgs @($Database, $SQLServer, $SQLInstanceName) -ErrorCategory ObjectNotFound
throw New-TerminatingError -ErrorType NoDatabase -FormatArgs @($Database, $ServerName, $InstanceName) -ErrorCategory ObjectNotFound
}

# Check login exists
if ( -not ($sqlServerObject.Logins[$Name]) )
{
throw New-TerminatingError -ErrorType LoginNotFound -FormatArgs @($Name, $SQLServer, $SQLInstanceName) -ErrorCategory ObjectNotFound
throw New-TerminatingError -ErrorType LoginNotFound -FormatArgs @($Name, $ServerName, $InstanceName) -ErrorCategory ObjectNotFound
}

try
Expand All @@ -147,7 +147,7 @@ function Set-TargetResource
catch
{
throw New-TerminatingError -ErrorType FailedToSetOwnerDatabase `
-FormatArgs @($Name, $Database, $SQLServer, $SQLInstanceName) `
-FormatArgs @($Name, $Database, $ServerName, $InstanceName) `
-ErrorCategory InvalidOperation `
-InnerException $_.Exception
}
Expand All @@ -164,10 +164,10 @@ function Set-TargetResource
.PARAMETER Name
The name of the login that will become a owner of the desired sql database.
.PARAMETER SQLServer
.PARAMETER ServerName
The host name of the SQL Server to be configured.
.PARAMETER SQLInstanceName
.PARAMETER InstanceName
The name of the SQL instance to be configured.
#>
function Test-TargetResource
Expand All @@ -189,12 +189,12 @@ function Test-TargetResource
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLServer = $env:COMPUTERNAME,
$ServerName = $env:COMPUTERNAME,

[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$SQLInstanceName = 'MSSQLSERVER'
$InstanceName = 'MSSQLSERVER'
)

Write-Verbose -Message "Testing owner $Name of database $Database"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class MSFT_SqlDatabaseOwner : OMI_BaseResource
{
[Key, Description("The name of database to be configured.")] String Database;
[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 SQLServer;
[Write, Description("The name of the SQL instance to be configured.")] String SQLInstanceName;
[Write, Description("The host name of the SQL Server to be configured.")] String ServerName;
[Write, Description("The name of the SQL instance to be configured.")] String InstanceName;
};
2 changes: 1 addition & 1 deletion Examples/Resources/SqlDatabaseOwner/1-SetDatabaseOwner.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Configuration Example
{
Name = 'CONTOSO\SQLAdmin'
Database = 'AdventureWorks'
SQLServer = 'SQLServer'
ServerName = 'SQLServer'
InstanceName = 'DSC'
PsDscRunAsCredential = $SysAdminAccount
}
Expand Down
Loading

0 comments on commit 7489e85

Please sign in to comment.