Skip to content

Commit e7dd59d

Browse files
committed
refactor: Change function to use Invoke-AzDoRestMethod
1 parent e0fe106 commit e7dd59d

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

AzureDevOpsPowerShell/Public/Api/ServiceEndpoints/Endpointproxy/Test-AzDoServiceConnection.ps1

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ function Test-AzDoServiceConnection {
5555
ServiceConnectionName = $ServiceConnectionName
5656
}
5757

58-
$Connections = Get-AzDoServiceConnection @getAzDoServiceConnectionSplat
59-
6058
$connectioninfo = Get-AzDoServiceConnection @getAzDoServiceConnectionSplat
6159

6260
$body = @{
@@ -67,22 +65,22 @@ function Test-AzDoServiceConnection {
6765
}
6866

6967
$params = @{
70-
uri = "$CollectionUri/$ProjectName/_apis/serviceendpoint/endpointproxy?endpointId=$($connectioninfo.ServiceConnectionId)&api-version=7.2-preview.1"
71-
Method = 'POST'
72-
Headers = $script:header
73-
body = $Body | ConvertTo-Json -Depth 99
74-
ContentType = 'application/json'
68+
uri = "$CollectionUri/$ProjectName/_apis/serviceendpoint/endpointproxy"
69+
version = "7.2-preview.1"
70+
queryParameters = "endpointId=$($connectioninfo.ServiceConnectionId)"
71+
method = 'POST'
72+
body = $body
7573
}
7674

7775
if ($PSCmdlet.ShouldProcess($ProjectName, "Test service connection on: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
78-
$result = Invoke-RestMethod @Params
79-
if ($response.statusCode -eq 'badRequest') {
80-
Write-Error "Connection $($connectioninfo.ServiceConnectionName) is not working: error $($response.errorMessage)"
76+
$result = Invoke-AzDoRestMethod @params
77+
if ($result.statusCode -eq 'badRequest') {
78+
Write-Error "Connection $($connectioninfo.ServiceConnectionName) is not working: error $($result.errorMessage)"
8179
} else {
8280
[PSCustomObject]@{
8381
Result = "Connection [$($connectioninfo.ServiceConnectionName)] is working as expected"
8482
}
85-
Write-Verbose ($response.result | ConvertFrom-Json -Depth 10 | ConvertTo-Json -Depth 10 -Compress)
83+
Write-Verbose ($result.result | ConvertFrom-Json -Depth 10 | ConvertTo-Json -Depth 10 -Compress)
8684
}
8785
}
8886
}

0 commit comments

Comments
 (0)