Skip to content

Commit

Permalink
Merge pull request #4831 from sqlcollaborative/development
Browse files Browse the repository at this point in the history
0.9.720
  • Loading branch information
potatoqualitee authored Dec 16, 2018
2 parents eeb6a9d + 75f368d commit df03029
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 19 deletions.
Binary file modified allcommands.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion bin/dbatools-index.json.REMOVED.git-id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0460cb948613c5cac307ac21b7e20e946c81cc17
7509d6d06907f7baf4840d49bce50fe1ce945824
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.9.720] - 2018-12-16
### Fixed
* Enhanced outputs of Invoke-DbaDbDataMasking
* Save-DbaDiagnosticQuery to work with lightly malformed links

## [0.9.719] - 2018-12-15
### Added
* Piping to Get-DbaDbSpace
Expand Down
2 changes: 1 addition & 1 deletion dbatools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'dbatools.psm1'

# Version number of this module.
ModuleVersion = '0.9.719'
ModuleVersion = '0.9.720'

# ID used to uniquely identify this module
GUID = '9d139310-ce45-41ce-8e8b-d76335aa1789'
Expand Down
35 changes: 28 additions & 7 deletions functions/Invoke-DbaDbDataMasking.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ function Invoke-DbaDbDataMasking {
Useful for adhoc updates and testing, otherwise, the config file should be used.
.PARAMETER ExactLength
Mask string values to the same length. So 'Tate' will be replaced with 4 random characters.
.PARAMETER Force
Forcefully execute commands when needed
Expand Down Expand Up @@ -117,6 +120,7 @@ function Invoke-DbaDbDataMasking {
[string[]]$ExcludeColumn,
[string]$Query,
[int]$MaxValue,
[switch]$ExactLength,
[switch]$EnableException
)
begin {
Expand Down Expand Up @@ -147,12 +151,11 @@ function Invoke-DbaDbDataMasking {
return
}
}

if ($Table) {
$tables = $tables | Where-Object Name -in $Table
}


foreach ($tabletest in $tables.Tables) {
if ($Table -and $tabletest.Name -notin $Table) {
continue
}
foreach ($columntest in $tabletest.Columns) {
if ($columntest.ColumnType -in 'hierarchyid', 'geography', 'xml' -and $columntest.Name -notin $Column) {
Stop-Function -Message "$($columntest.ColumnType) is not supported, please remove the column $($columntest.Name) from the $($tabletest.Name) table" -Target $tables
Expand All @@ -174,7 +177,7 @@ function Invoke-DbaDbDataMasking {
foreach ($db in (Get-DbaDatabase -SqlInstance $server -Database $Database)) {
$stepcounter = 0
foreach ($tableobject in $tables.Tables) {
if ($tableobject.Name -in $ExcludeTable) {
if ($tableobject.Name -in $ExcludeTable -or ($Table -and $tableobject.Name -notin $Table)) {
Write-Message -Level Verbose -Message "Skipping $($tableobject.Name) because it is explicitly excluded"
continue
}
Expand All @@ -189,9 +192,10 @@ function Invoke-DbaDbDataMasking {

$data = $db.Query($query) | ConvertTo-DbaDataTable
} catch {
Stop-Function -Message "Something went wrong retrieving the data from table $($tableobject.Name)" -Target $Database
Stop-Function -Message "Failure retrieving the data from table $($tableobject.Name)" -Target $Database -ErrorRecord $_ -Continue
}

$elapsed = [System.Diagnostics.Stopwatch]::StartNew()
$tablecolumns = $tableobject.Columns

if ($Column) {
Expand Down Expand Up @@ -297,6 +301,13 @@ function Invoke-DbaDbDataMasking {
'uniqueidentifier' {
$faker.System.Random.Guid().Guid
}
'userdefineddatatype' {
if ($columnobject.MaxValue -eq 1) {
$faker.System.Random.Bool()
} else {
$null
}
}
default {
$null
}
Expand Down Expand Up @@ -335,6 +346,11 @@ function Invoke-DbaDbDataMasking {
if ($max -eq -1) {
$max = 1024
}

if ($columnobject.SubType -eq "String" -and (Test-Bound -ParameterName ExactLength)) {
$max = ($row.$($columnobject.Name)).Length
}

if ($columnobject.ColumnType -eq 'xml') {
$null
} else {
Expand All @@ -345,6 +361,9 @@ function Invoke-DbaDbDataMasking {
if ($max -eq -1) {
$max = 1024
}
if ((Test-Bound -ParameterName ExactLength)) {
$max = ($row.$($columnobject.Name)).ToString().Length
}
$faker.Random.String2($max, $charstring)
}
}
Expand Down Expand Up @@ -387,6 +406,8 @@ function Invoke-DbaDbDataMasking {
Schema = $tableobject.Schema
Table = $tableobject.Name
Columns = $tableobject.Columns.Name
Rows = $($data.Rows.Count)
Elapsed = [prettytimespan]$elapsed.Elapsed
Status = "Masked"
}
}
Expand Down
17 changes: 17 additions & 0 deletions functions/New-DbaDbMaskingConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,23 @@ function New-DbaDbMaskingConfig {
$subType = "Number"
$MaxValue = 255
}
"varbinary" {
$subType = "Byte"
$MaxValue = $columnLength
}
"varbinary" {
$subType = "Byte"
$MaxValue = $columnLength
}
"userdefineddatatype" {
if ($columnLength -eq 1) {
$subType = "Bool"
$MaxValue = $columnLength
} else {
$subType = "String"
$MaxValue = $columnLength
}
}
default {
$subType = "String"
$MaxValue = $columnLength
Expand Down
11 changes: 7 additions & 4 deletions functions/Save-DbaDiagnosticQueryScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function Save-DbaDiagnosticQueryScript {
$glenberryrss = "http://www.sqlskills.com/blogs/glenn/feed/"
$glenberrysql = @()

Write-Message -Level Output -Message "Downloading RSS Feed"
Write-Message -Level Verbose -Message "Downloading RSS Feed"
$rss = [xml](get-webdata -uri $glenberryrss)
$Feed = $rss.rss.Channel

Expand All @@ -90,12 +90,15 @@ function Save-DbaDiagnosticQueryScript {
break
}
}
Write-Message -Level Output -Message "Found $($glenberrysql.Count) documents to download"
Write-Message -Level Verbose -Message "Found $($glenberrysql.Count) documents to download"
foreach ($doc in $glenberrysql) {
try {
Write-Message -Level Output -Message "Downloading $($doc.URL)"
$link = $doc.URL.ToString().Replace('dl=0', 'dl=1')
Write-Message -Level Verbose -Message "Downloading $link)"
Write-ProgressHelper -Activity "Downloading Glenn Berry's most recent DMVs" -ExcludePercent -Message "Downloading $link" -StepNumber 1
$filename = "{0}\SQLServerDiagnosticQueries_{1}_{2}.sql" -f $Path, $doc.SQLVersion, "$($doc.FileYear)$($doc.FileMonth)"
Invoke-TlsWebRequest -Uri $doc.URL.ToString().Replace('dl\=0','dl\=1') -OutFile $filename -ErrorAction Stop
Invoke-TlsWebRequest -Uri $link -OutFile $filename -ErrorAction Stop
Get-ChildItem -Path $filename
} catch {
Stop-Function -Message "Requesting and writing file failed: $_" -Target $filename -ErrorRecord $_
return
Expand Down
8 changes: 4 additions & 4 deletions functions/Set-DbaSpn.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ function Set-DbaSpn {
https://dbatools.io/Set-DbaSpn
.EXAMPLE
PS C:\> Set-DbaSpn -SPN MSSQLSvc\SQLSERVERA.domain.something -ServiceAccount domain\account
PS C:\> Set-DbaSpn -SPN MSSQLSvc\SQLSERVERA.domain.something -ServiceAccount domain\account -EnableException
PS C:\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\account
PS C:\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\account -EnableException
Connects to Active Directory and adds a provided SPN to the given account.
Connects to Active Directory and adds a provided SPN to the given account, suppressing all error messages and throw exceptions that can be caught instead
.EXAMPLE
PS C:\> Set-DbaSpn -SPN MSSQLSvc\SQLSERVERA.domain.something -ServiceAccount domain\account -Credential ad\sqldba
PS C:\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\account -Credential ad\sqldba
Connects to Active Directory and adds a provided SPN to the given account. Uses alternative account to connect to AD.
.EXAMPLE
PS C:\> Set-DbaSpn -SPN MSSQLSvc\SQLSERVERA.domain.something -ServiceAccount domain\account -NoDelegation
PS C:\> Set-DbaSpn -SPN MSSQLSvc/SQLSERVERA.domain.something -ServiceAccount domain\account -NoDelegation
Connects to Active Directory and adds a provided SPN to the given account, without the delegation.
Expand Down
2 changes: 1 addition & 1 deletion tests/Invoke-DbaDbDataMasking.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
$defaultParamCount = 13
[object[]]$params = (Get-ChildItem function:\Invoke-DbaDbDataMasking).Parameters.Keys
$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'FilePath', 'Locale', 'CharacterString', 'Table', 'Column', 'ExcludeTable', 'ExcludeColumn', 'Query', 'MaxValue', 'EnableException'
$knownParameters = 'SqlInstance', 'SqlCredential', 'Database', 'FilePath', 'Locale', 'CharacterString', 'Table', 'Column', 'ExcludeTable', 'ExcludeColumn', 'Query', 'MaxValue', 'EnableException','ExactLength'
It "Should contain our specific parameters" {
( (Compare-Object -ReferenceObject $knownParameters -DifferenceObject $params -IncludeEqual | Where-Object SideIndicator -eq "==").Count ) | Should Be $knownParameters.Count
}
Expand Down
3 changes: 2 additions & 1 deletion tests/pester.groups.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ $TestsRunGroups = @{
'Test-DbaDbVirtualLogFile',
'Test-DbaAgentJobOwner',
'Resume-DbaAgDbDataMovement',
'Get-DbaDbMasterKey'
'Get-DbaDbMasterKey',
'Test-DbaJobOwner'
)
# do not run everywhere
"disabled" = @()
Expand Down

0 comments on commit df03029

Please sign in to comment.