Skip to content

Commit

Permalink
Set-DbatoolsInsecureConnection - Persist by default (#8877)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee authored Apr 27, 2023
1 parent 6392d00 commit e46e043
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gallery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Set encryption values
run: |
Import-Module dbatools
Set-DbatoolsInsecureConnection -Register
Set-DbatoolsInsecureConnection
Get-DbatoolsConfigValue -FullName sql.connection.encrypt | Write-Warning
- name: Setup docker images
Expand Down
21 changes: 14 additions & 7 deletions public/Set-DbatoolsInsecureConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ function Set-DbatoolsInsecureConnection {
You can read more here: https://dbatools.io/newdefaults
.PARAMETER Register
Registers the settings to persist across sessions so they'll be used even if you close and reopen PowerShell.
.PARAMETER SessionOnly
Does not persist across sessions so the default will return if you close and reopen PowerShell.
.PARAMETER Scope
The configuration scope it should be registered under. Defaults to UserDefault.
Configuration scopes are the default locations configurations are being stored at.
.PARAMETER Register
Deprecated.
.LINK
https://dbatools.io/Set-DbatoolsInsecureConnection
https://blog.netnerds.net/2023/03/new-defaults-for-sql-server-connections-encryption-trust-certificate/
Expand All @@ -30,24 +33,28 @@ function Set-DbatoolsInsecureConnection {
Sets the default connection settings to trust all server certificates and not require encrypted connections.
.EXAMPLE
PS C:\> Set-DbatoolsInsecureConnection -Register
PS C:\> Set-DbatoolsInsecureConnection -SessionOnly
Sets the default connection settings to trust all server certificates and not require encrypted connections.
Registers the settings to persist across sessions so they'll be used even if you close and reopen PowerShell.
Does not persist across sessions so the default will return if you close and reopen PowerShell.
#>
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "")]
[CmdletBinding()]
param (
[switch]$Register,
[Dataplat.Dbatools.Configuration.ConfigScope]$Scope = [Dataplat.Dbatools.Configuration.ConfigScope]::UserDefault
[switch]$SessionOnly,
[Dataplat.Dbatools.Configuration.ConfigScope]$Scope = [Dataplat.Dbatools.Configuration.ConfigScope]::UserDefault,
[switch]$Register
)
process {
if ($Register) {
Write-Message -Level Warning -Message "The Register parameter is deprecated and will be removed in a future release."
}
# Set these defaults for all future sessions on this machine
Set-DbatoolsConfig -FullName sql.connection.trustcert -Value $true -Passthru
Set-DbatoolsConfig -FullName sql.connection.encrypt -Value $false -Passthru

if ($Register) {
if (-not $SessionOnly) {
Register-DbatoolsConfig -FullName sql.connection.trustcert -Scope $Scope
Register-DbatoolsConfig -FullName sql.connection.encrypt -Scope $Scope
}
Expand Down
8 changes: 1 addition & 7 deletions tests/Set-DbatoolsInsecureConnection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Write-Host -Object "Running $PSCommandpath" -ForegroundColor Cyan
Describe "$CommandName Unit Tests" -Tag 'UnitTests' {
Context "Validate parameters" {
[object[]]$params = (Get-Command $CommandName).Parameters.Keys | Where-Object { $_ -notin ('whatif', 'confirm') }
[object[]]$knownParameters = 'Register', 'Scope'
[object[]]$knownParameters = 'Register', 'SessionOnly', 'Scope'
$knownParameters += [System.Management.Automation.PSCmdlet]::CommonParameters
It "Should only contain our specific parameters" {
(@(Compare-Object -ReferenceObject ($knownParameters | Where-Object { $_ }) -DifferenceObject $params).Count ) | Should Be 0
Expand All @@ -32,11 +32,5 @@ Describe "$commandname Integration Tests" -Tags "IntegrationTests" {
# sql.connection.encrypt is a string because it needs to be mandatory, optional, true or false
Get-DbatoolsConfigValue -FullName sql.connection.encrypt | Should -Be 'False'
}

It "registers the settings to persist across sessions so they'll be used even if you close and reopen PowerShell" {
$null = Set-DbatoolsInsecureConnection -Register
Get-DbatoolsConfigValue -FullName sql.connection.trustcert | Should -BeTrue
Get-DbatoolsConfigValue -FullName sql.connection.encrypt | Should -Be 'False'
}
}
}

0 comments on commit e46e043

Please sign in to comment.