From e2451d8ef03dec0006fe1e8a57d61c2b987d7f85 Mon Sep 17 00:00:00 2001 From: Gaurav Agrawal Date: Wed, 5 Jul 2023 07:21:46 -0400 Subject: [PATCH] 1. Ignore the null values from the response 2. Fix the code to pass the Body param in proper way after migartion --- .../cmdlets/private/InvokeTssApiCmdlet.cs | 6 +++--- src/functions/metadata/New-TssMetadataField.ps1 | 6 +++++- src/functions/metadata/Update-TssMetadataField.ps1 | 6 +++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Thycotic.SecretServer/cmdlets/private/InvokeTssApiCmdlet.cs b/src/Thycotic.SecretServer/cmdlets/private/InvokeTssApiCmdlet.cs index d701c612..a1bf0c35 100644 --- a/src/Thycotic.SecretServer/cmdlets/private/InvokeTssApiCmdlet.cs +++ b/src/Thycotic.SecretServer/cmdlets/private/InvokeTssApiCmdlet.cs @@ -93,7 +93,7 @@ protected override void ProcessRecord() Uri requestUri = new Uri(Uri); options.BaseUrl = requestUri; options.MaxTimeout = Timeout; - + if (MyInvocation.BoundParameters.ContainsKey("Proxy")) { options.Proxy = new WebProxy(Proxy); @@ -119,14 +119,14 @@ protected override void ProcessRecord() } if (MyInvocation.BoundParameters.ContainsKey("Body")) { - apiRequest.AddParameter(ContentType, Body, ParameterType.RequestBody); + apiRequest.AddParameter(ContentType, ((PSObject)Body).BaseObject, ParameterType.RequestBody); } var apiClient = new RestClient(options); if (!String.IsNullOrEmpty(OutFile)) { // stream file content out RestResponse apiResponse = apiClient.Execute(apiRequest); - File.WriteAllBytes(OutFile, apiResponse.RawBytes); + File.WriteAllBytes(OutFile, apiResponse.RawBytes); } else { diff --git a/src/functions/metadata/New-TssMetadataField.ps1 b/src/functions/metadata/New-TssMetadataField.ps1 index f3be6657..41fe3161 100644 --- a/src/functions/metadata/New-TssMetadataField.ps1 +++ b/src/functions/metadata/New-TssMetadataField.ps1 @@ -157,7 +157,11 @@ function New-TssMetadataField { } if ($restResponse) { - [Thycotic.PowerShell.Metadata.Field]$restResponse + $restResponse | ForEach-Object { + $NonEmptyProperties = $_.restResponse.Properties | Where-Object {$_.Value} | Select-Object -ExpandProperty Name + $_ | Select-Object -Property $NonEmptyProperties + } + [Thycotic.PowerShell.Metadata.Field]$NonEmptyProperties } } else { Write-Warning "No valid session found" diff --git a/src/functions/metadata/Update-TssMetadataField.ps1 b/src/functions/metadata/Update-TssMetadataField.ps1 index 09b2467c..1caa9c15 100644 --- a/src/functions/metadata/Update-TssMetadataField.ps1 +++ b/src/functions/metadata/Update-TssMetadataField.ps1 @@ -133,7 +133,11 @@ function Update-TssMetadataField { } if ($restResponse) { - [Thycotic.PowerShell.Metadata.Field]$restResponse + $restResponse | ForEach-Object { + $NonEmptyProperties = $_.restResponse.Properties | Where-Object {$_.Value} | Select-Object -ExpandProperty Name + $_ | Select-Object -Property $NonEmptyProperties + } + [Thycotic.PowerShell.Metadata.Field]$NonEmptyProperties } } } else {