Fix for SQL Server Private Endpoints listing #62
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SQL servers with only one private endpoint are not being listed. This is due to the erratic behavior of the [String]::IsNullOrEmpty method being used with array of objects. When the object (privateEndpointConnections) has more than one element it returns $false, but when the object has only one element it returns $true. That way, ignoring unique private endpoints. I'm proposing to fix the object test and add a new loop for listing multiple private endpoints on the same SQL Server.
I understand that all modules need review. The use of the [string]::IsNullOrEmpty method can generate unwanted effects, as the method expects a String and not a collection or array of objects. When passing an array of objects, it is converted to a string. This test will only work in scenarios where there is no value or in scenarios with more than one value. For example, consider two arrays pvt1 and pvt2 containing private Endpoint Connections:
pvt1
pvt2
Checking the values with [String]::IsNullOrEmpty will return:
[String]::IsNullOrEmpty($pvt1) => $false
[String]::IsNullOrEmpty($pvt2) => $true
Both have data, but for one of them the function returned $true, ie null or empty.
This inappropriate use of the method can cause inaccuracy when reporting some resources or properties.