From 618398eedd4571a42e000a4ce4527b56244f7720 Mon Sep 17 00:00:00 2001 From: Giuseppe Campanelli Date: Thu, 18 Jun 2020 15:44:16 -0400 Subject: [PATCH] Save & restore the state of [Net.ServicePointManager]::SecurityProtocol (#240) [Net.ServicePointManager]::SecurityProtocol is a global configuration that was being modified during the execution of `Invoke-GHRestMethod`. With this change, the global state will be cached before the change and restored immediately afterwards. Fixes #230 --- GitHubCore.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/GitHubCore.ps1 b/GitHubCore.ps1 index 542ae5a8..09068429 100644 --- a/GitHubCore.ps1 +++ b/GitHubCore.ps1 @@ -201,6 +201,7 @@ function Invoke-GHRestMethod } $NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus + $originalSecurityProtocol = [Net.ServicePointManager]::SecurityProtocol try { @@ -560,6 +561,10 @@ function Invoke-GHRestMethod Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus throw $newLineOutput } + finally + { + [Net.ServicePointManager]::SecurityProtocol = $originalSecurityProtocol + } } function Invoke-GHRestMethodMultipleResult